[HVM] [SMBIOS] Duplicate UUID into serial number in SMBIOS tables.
Windows zeroes out the UUID in the SMBIOS tables, but the identifier
is often needed by systems management code. Duplicating the UUID
as the virtual system's serial number should help.
Signed-off-by: Andrew D. Ball <aball@xxxxxxxxxx>
diff -r 6a8204e4619d -r f3a3ee53050e tools/firmware/hvmloader/smbios.c
--- a/tools/firmware/hvmloader/smbios.c Mon Aug 21 13:36:05 2006 +0100
+++ b/tools/firmware/hvmloader/smbios.c Tue Aug 22 14:34:50 2006 -0400
@@ -116,8 +116,10 @@ smbios_table_size(uint32_t vcpus, const
/* type 0: "Xen", xen_version, and release_date */
size += strlen("Xen") + strlen(xen_version) + 2;
- /* type 1: "Xen", xen_version, "HVM domU" */
- size += strlen("Xen") + strlen("HVM domU") + strlen(xen_version) + 3;
+ /* type 1: "Xen", xen_version, "HVM domU", UUID as string for
+ serial number */
+ size += strlen("Xen") + strlen("HVM domU") + strlen(xen_version) +
+ 36 + 4;
/* type 3: "Xen" */
size += strlen("Xen") + 1;
/* type 4: socket designation ("CPU n"), processor_manufacturer */
@@ -371,6 +373,7 @@ smbios_type_1_init(void *start, const ch
smbios_type_1_init(void *start, const char *xen_version,
uint8_t uuid[16])
{
+ char uuid_str[37];
struct smbios_type_1 *p = (struct smbios_type_1 *)start;
p->header.type = 1;
p->header.length = sizeof(struct smbios_type_1);
@@ -379,7 +382,7 @@ smbios_type_1_init(void *start, const ch
p->manufacturer_str = 1;
p->product_name_str = 2;
p->version_str = 3;
- p->serial_number_str = 0;
+ p->serial_number_str = 4;
memcpy(p->uuid, uuid, 16);
@@ -395,6 +398,9 @@ smbios_type_1_init(void *start, const ch
start += strlen("HVM domU") + 1;
strcpy((char *)start, xen_version);
start += strlen(xen_version) + 1;
+ uuid_to_string(uuid_str, uuid);
+ strcpy((char *)start, uuid_str);
+ start += strlen(uuid_str) + 1;
*((uint8_t *)start) = 0;
return start+1;
diff -r 6a8204e4619d -r f3a3ee53050e tools/firmware/hvmloader/util.c
--- a/tools/firmware/hvmloader/util.c Mon Aug 21 13:36:05 2006 +0100
+++ b/tools/firmware/hvmloader/util.c Tue Aug 22 14:34:50 2006 -0400
@@ -174,3 +174,57 @@ cpuid(uint32_t idx, uint32_t *eax, uint3
: "0" (idx) );
}
+/* Write a two-character hex representation of 'byte' to digits[].
+ Pre-condition: sizeof(digits) >= 2 */
+void
+byte_to_hex(char *digits, uint8_t byte)
+{
+ uint8_t nybbel = byte >> 4;
+
+ if (nybbel > 9)
+ digits[0] = 'a' + nybbel-10;
+ else
+ digits[0] = '0' + nybbel;
+
+ nybbel = byte & 0x0f;
+ if (nybbel > 9)
+ digits[1] = 'a' + nybbel-10;
+ else
+ digits[1] = '0' + nybbel;
+}
+
+/* Convert an array of 16 unsigned bytes to a DCE/OSF formatted UUID
+ string.
+
+ Pre-condition: sizeof(dest) >= 37 */
+void
+uuid_to_string(char *dest, uint8_t *uuid)
+{
+ int i = 0;
+ char *p = dest;
+
+ for (i = 0; i < 4; ++i) {
+ byte_to_hex(p, uuid[i]);
+ p += 2;
+ }
+ *p++ = '-';
+ for (i = 4; i < 6; ++i) {
+ byte_to_hex(p, uuid[i]);
+ p += 2;
+ }
+ *p++ = '-';
+ for (i = 6; i < 8; ++i) {
+ byte_to_hex(p, uuid[i]);
+ p += 2;
+ }
+ *p++ = '-';
+ for (i = 8; i < 10; ++i) {
+ byte_to_hex(p, uuid[i]);
+ p += 2;
+ }
+ *p++ = '-';
+ for (i = 10; i < 16; ++i) {
+ byte_to_hex(p, uuid[i]);
+ p += 2;
+ }
+}
diff -r 6a8204e4619d -r f3a3ee53050e tools/firmware/hvmloader/util.h
--- a/tools/firmware/hvmloader/util.h Mon Aug 21 13:36:05 2006 +0100
+++ b/tools/firmware/hvmloader/util.h Tue Aug 22 14:34:50 2006 -0400
@@ -25,6 +25,16 @@ void *memset(void *s, int c, unsigned n)
void *memset(void *s, int c, unsigned n);
char *itoa(char *a, unsigned int i);
+/* convert a byte to two lowercase hex digits, with no terminating NUL
+ character. digits[] must have at least two elements. */
+void byte_to_hex(char *digits, uint8_t byte);
+
+/* Convert an array of 16 unsigned bytes to a DCE/OSF formatted UUID
+ string.
+
+ Pre-condition: sizeof(dest) >= 37 */
+void uuid_to_string(char *dest, uint8_t *uuid);
+
/* Debug output */
void puts(const char *s);
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|