summaryrefslogtreecommitdiff
path: root/usr/src/cmd/bhyve/bootrom.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/cmd/bhyve/bootrom.c')
-rw-r--r--usr/src/cmd/bhyve/bootrom.c52
1 files changed, 35 insertions, 17 deletions
diff --git a/usr/src/cmd/bhyve/bootrom.c b/usr/src/cmd/bhyve/bootrom.c
index cbb05c8c50..00f0a1a2a5 100644
--- a/usr/src/cmd/bhyve/bootrom.c
+++ b/usr/src/cmd/bhyve/bootrom.c
@@ -191,19 +191,33 @@ bootrom_alloc(struct vmctx *ctx, size_t len, int prot, int flags,
}
int
-bootrom_loadrom(struct vmctx *ctx, const char *romfile)
+bootrom_loadrom(struct vmctx *ctx, const nvlist_t *nvl)
{
struct stat sbuf;
ssize_t rlen;
off_t rom_size, var_size, total_size;
- char *ptr, *varfile;
+ char *ptr, *romfile;
int fd, varfd, i, rv;
+ const char *bootrom, *varfile;
rv = -1;
varfd = -1;
- varfile = strdup(romfile);
- romfile = strsep(&varfile, ",");
+ bootrom = get_config_value_node(nvl, "bootrom");
+ if (bootrom == NULL) {
+ return (-1);
+ }
+
+ /*
+ * get_config_value_node may use a thread local buffer to return
+ * variables. So, when we query the second variable, the first variable
+ * might get overwritten. For that reason, the bootrom should be
+ * duplicated.
+ */
+ romfile = strdup(bootrom);
+ if (romfile == NULL) {
+ return (-1);
+ }
fd = open(romfile, O_RDONLY);
if (fd < 0) {
@@ -212,6 +226,16 @@ bootrom_loadrom(struct vmctx *ctx, const char *romfile)
goto done;
}
+ if (fstat(fd, &sbuf) < 0) {
+ EPRINTLN("Could not fstat bootrom file \"%s\": %s", romfile,
+ strerror(errno));
+ goto done;
+ }
+
+ rom_size = sbuf.st_size;
+
+ varfile = get_config_value_node(nvl, "bootvars");
+ var_size = 0;
if (varfile != NULL) {
varfd = open(varfile, O_RDWR);
if (varfd < 0) {
@@ -219,23 +243,14 @@ bootrom_loadrom(struct vmctx *ctx, const char *romfile)
"\"%s\": %s\n", varfile, strerror(errno));
goto done;
}
- }
-
- if (fstat(fd, &sbuf) < 0) {
- EPRINTLN("Could not fstat bootrom file \"%s\": %s",
- romfile, strerror(errno));
- goto done;
- }
- rom_size = sbuf.st_size;
- if (varfd < 0) {
- var_size = 0;
- } else {
if (fstat(varfd, &sbuf) < 0) {
- fprintf(stderr, "Could not fstat bootrom variable file \"%s\": %s\n",
- varfile, strerror(errno));
+ fprintf(stderr,
+ "Could not fstat bootrom variable file \"%s\": %s\n",
+ varfile, strerror(errno));
goto done;
}
+
var_size = sbuf.st_size;
}
@@ -296,7 +311,10 @@ bootrom_loadrom(struct vmctx *ctx, const char *romfile)
rv = 0;
done:
+ if (varfd >= 0)
+ close(varfd);
if (fd >= 0)
close(fd);
+ free(romfile);
return (rv);
}