aboutsummaryrefslogtreecommitdiffstats
path: root/tools/firmware
diff options
context:
space:
mode:
authorKeir Fraser <keir@xen.org>2011-07-25 14:21:13 +0100
committerKeir Fraser <keir@xen.org>2011-07-25 14:21:13 +0100
commit487f749f0f076f82a13165a9522761b10defd93d (patch)
treef38eafbc437f5e86e951dbf0cc8b37d12143ae08 /tools/firmware
parentd31b9a4e409faa5c5e4bdd055c13b8c5c95c370c (diff)
downloadxen-487f749f0f076f82a13165a9522761b10defd93d.tar.gz
xen-487f749f0f076f82a13165a9522761b10defd93d.tar.bz2
xen-487f749f0f076f82a13165a9522761b10defd93d.zip
hvmloader: Allow default response to be specified to xenstore_read().
Signed-off-by: Keir Fraser <keir@xen.org>
Diffstat (limited to 'tools/firmware')
-rw-r--r--tools/firmware/hvmloader/hvmloader.c4
-rw-r--r--tools/firmware/hvmloader/smbios.c26
-rw-r--r--tools/firmware/hvmloader/util.h7
-rw-r--r--tools/firmware/hvmloader/xenbus.c21
4 files changed, 27 insertions, 31 deletions
diff --git a/tools/firmware/hvmloader/hvmloader.c b/tools/firmware/hvmloader/hvmloader.c
index 4613a736f4..5e7d128307 100644
--- a/tools/firmware/hvmloader/hvmloader.c
+++ b/tools/firmware/hvmloader/hvmloader.c
@@ -368,9 +368,7 @@ static const struct bios_config *detect_bios(void)
const struct bios_info *b;
const char *bios;
- bios = xenstore_read("hvmloader/bios");
- if ( !bios )
- bios = "rombios";
+ bios = xenstore_read("hvmloader/bios", "rombios");
for ( b = &bios_configs[0]; b->key != NULL; b++ )
if ( !strcmp(bios, b->key) )
diff --git a/tools/firmware/hvmloader/smbios.c b/tools/firmware/hvmloader/smbios.c
index 5674bf42c0..ea79e9e1b0 100644
--- a/tools/firmware/hvmloader/smbios.c
+++ b/tools/firmware/hvmloader/smbios.c
@@ -315,15 +315,11 @@ smbios_type_0_init(void *start, const char *xen_version,
p->embedded_controller_minor = 0xff;
start += sizeof(struct smbios_type_0);
- if ( ((s = xenstore_read("bios-strings/bios-vendor")) == NULL)
- || (*s == '\0') )
- s = "Xen";
+ s = xenstore_read("bios-strings/bios-vendor", "Xen");
strcpy((char *)start, s);
start += strlen(s) + 1;
- if ( ((s = xenstore_read("bios-strings/bios-version")) == NULL)
- || (*s == '\0') )
- s = xen_version;
+ s = xenstore_read("bios-strings/bios-version", xen_version);
strcpy((char *)start, s);
start += strlen(s) + 1;
@@ -362,28 +358,20 @@ smbios_type_1_init(void *start, const char *xen_version,
start += sizeof(struct smbios_type_1);
- if ( ((s = xenstore_read("bios-strings/system-manufacturer")) == NULL)
- || (*s == '\0') )
- s = "Xen";
+ s = xenstore_read("bios-strings/system-manufacturer", "Xen");
strcpy((char *)start, s);
start += strlen(s) + 1;
- if ( ((s = xenstore_read("bios-strings/system-product-name")) == NULL)
- || (*s == '\0') )
- s = "HVM domU";
+ s = xenstore_read("bios-strings/system-product-name", "HVM domU");
strcpy((char *)start, s);
start += strlen(s) + 1;
- if ( ((s = xenstore_read("bios-strings/system-version")) == NULL)
- || (*s == '\0') )
- s = xen_version;
+ s = xenstore_read("bios-strings/system-version", xen_version);
strcpy((char *)start, s);
start += strlen(s) + 1;
uuid_to_string(uuid_str, uuid);
- if ( ((s = xenstore_read("bios-strings/system-serial-number")) == NULL)
- || (*s == '\0') )
- s = uuid_str;
+ s = xenstore_read("bios-strings/system-serial-number", uuid_str);
strcpy((char *)start, s);
start += strlen(s) + 1;
@@ -494,7 +482,7 @@ smbios_type_11_init(void *start)
{
path[(sizeof path) - 3] = '0' + ((i < 10) ? i : i / 10);
path[(sizeof path) - 2] = (i < 10) ? '\0' : '0' + (i % 10);
- if ( ((s = xenstore_read(path)) == NULL) || (*s == '\0') )
+ if ( ((s = xenstore_read(path, NULL)) == NULL) || (*s == '\0') )
break;
strcpy((char *)start, s);
start += strlen(s) + 1;
diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h
index bc86043eec..464cf98f61 100644
--- a/tools/firmware/hvmloader/util.h
+++ b/tools/firmware/hvmloader/util.h
@@ -187,8 +187,11 @@ void xenbus_shutdown(void);
/* Read a xenstore key. Returns a nul-terminated string (even if the XS
* data wasn't nul-terminated) or NULL. The returned string is in a
- * static buffer, so only valid until the next xenstore/xenbus operation. */
-char *xenstore_read(char *path);
+ * static buffer, so only valid until the next xenstore/xenbus operation.
+ * If @default_resp is specified, it is returned in preference to a NULL or
+ * empty string received from xenstore.
+ */
+const char *xenstore_read(const char *path, const char *default_resp);
/* Setup PCI bus */
void pci_setup(void);
diff --git a/tools/firmware/hvmloader/xenbus.c b/tools/firmware/hvmloader/xenbus.c
index 90245f57b1..87f03a83f1 100644
--- a/tools/firmware/hvmloader/xenbus.c
+++ b/tools/firmware/hvmloader/xenbus.c
@@ -83,7 +83,7 @@ static void ring_wait(void)
}
/* Helper functions: copy data in and out of the ring */
-static void ring_write(char *data, uint32_t len)
+static void ring_write(const char *data, uint32_t len)
{
uint32_t part;
@@ -140,8 +140,8 @@ static void ring_read(char *data, uint32_t len)
* Returns 0 for success, or an errno for error.
* The answer is returned in a static buffer which is only
* valid until the next call of xenbus_send(). */
-static int xenbus_send(uint32_t type, uint32_t len, char *data,
- uint32_t *reply_len, char **reply_data)
+static int xenbus_send(uint32_t type, uint32_t len, const char *data,
+ uint32_t *reply_len, const char **reply_data)
{
struct xsd_sockmsg hdr;
evtchn_send_t send;
@@ -190,15 +190,22 @@ static int xenbus_send(uint32_t type, uint32_t len, char *data,
/* Read a xenstore key. Returns a nul-terminated string (even if the XS
* data wasn't nul-terminated) or NULL. The returned string is in a
- * static buffer, so only valid until the next xenstore/xenbus operation. */
-char *xenstore_read(char *path)
+ * static buffer, so only valid until the next xenstore/xenbus operation.
+ * If @default_resp is specified, it is returned in preference to a NULL or
+ * empty string received from xenstore.
+ */
+const char *xenstore_read(const char *path, const char *default_resp)
{
uint32_t len = 0;
- char *answer = NULL;
+ const char *answer = NULL;
/* Include the nul in the request */
if ( xenbus_send(XS_READ, strlen(path) + 1, path, &len, &answer) )
- return NULL;
+ answer = NULL;
+
+ if ( (default_resp != NULL) && ((answer == NULL) || (*answer == '\0')) )
+ answer = default_resp;
+
/* We know xenbus_send() nul-terminates its answer, so just pass it on. */
return answer;
}