ia64/xen-unstable

changeset 11315:028862ea9c9d

[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@us.ibm.com>
author kaf24@localhost.localdomain
date Mon Aug 28 12:59:07 2006 +0100 (2006-08-28)
parents c61b8296b39a
children 3798ec84431d
files tools/firmware/hvmloader/smbios.c tools/firmware/hvmloader/util.c tools/firmware/hvmloader/util.h
line diff
     1.1 --- a/tools/firmware/hvmloader/smbios.c	Mon Aug 28 12:50:55 2006 +0100
     1.2 +++ b/tools/firmware/hvmloader/smbios.c	Mon Aug 28 12:59:07 2006 +0100
     1.3 @@ -116,8 +116,10 @@ smbios_table_size(uint32_t vcpus, const 
     1.4  
     1.5  	/* type 0: "Xen", xen_version, and release_date */
     1.6  	size += strlen("Xen") + strlen(xen_version) + 2;
     1.7 -	/* type 1: "Xen", xen_version, "HVM domU" */
     1.8 -	size += strlen("Xen") + strlen("HVM domU") + strlen(xen_version) + 3;
     1.9 +	/* type 1: "Xen", xen_version, "HVM domU", UUID as string for 
    1.10 +                   serial number */
    1.11 +	size += strlen("Xen") + strlen("HVM domU") + strlen(xen_version) +
    1.12 +			36 + 4;
    1.13  	/* type 3: "Xen" */
    1.14  	size += strlen("Xen") + 1;
    1.15  	/* type 4: socket designation ("CPU n"), processor_manufacturer */
    1.16 @@ -371,6 +373,7 @@ static void *
    1.17  smbios_type_1_init(void *start, const char *xen_version, 
    1.18  		   uint8_t uuid[16])
    1.19  {
    1.20 +	char uuid_str[37];
    1.21  	struct smbios_type_1 *p = (struct smbios_type_1 *)start;
    1.22  	p->header.type = 1;
    1.23  	p->header.length = sizeof(struct smbios_type_1);
    1.24 @@ -379,7 +382,7 @@ smbios_type_1_init(void *start, const ch
    1.25  	p->manufacturer_str = 1;
    1.26  	p->product_name_str = 2;
    1.27  	p->version_str = 3;
    1.28 -	p->serial_number_str = 0;
    1.29 +	p->serial_number_str = 4;
    1.30      
    1.31  	memcpy(p->uuid, uuid, 16);
    1.32  
    1.33 @@ -395,6 +398,9 @@ smbios_type_1_init(void *start, const ch
    1.34  	start += strlen("HVM domU") + 1;
    1.35  	strcpy((char *)start, xen_version);
    1.36  	start += strlen(xen_version) + 1;
    1.37 +	uuid_to_string(uuid_str, uuid);	
    1.38 +	strcpy((char *)start, uuid_str);
    1.39 +	start += strlen(uuid_str) + 1;
    1.40  	*((uint8_t *)start) = 0;
    1.41      
    1.42  	return start+1; 
     2.1 --- a/tools/firmware/hvmloader/util.c	Mon Aug 28 12:50:55 2006 +0100
     2.2 +++ b/tools/firmware/hvmloader/util.c	Mon Aug 28 12:59:07 2006 +0100
     2.3 @@ -174,3 +174,57 @@ cpuid(uint32_t idx, uint32_t *eax, uint3
     2.4  		: "0" (idx) );
     2.5  }
     2.6  
     2.7 +/* Write a two-character hex representation of 'byte' to digits[].
     2.8 +   Pre-condition: sizeof(digits) >= 2 */
     2.9 +void
    2.10 +byte_to_hex(char *digits, uint8_t byte)
    2.11 +{
    2.12 +	uint8_t nybbel = byte >> 4;
    2.13 +
    2.14 +	if (nybbel > 9)
    2.15 +		digits[0] = 'a' + nybbel-10;
    2.16 +	else
    2.17 +		digits[0] = '0' + nybbel;
    2.18 +
    2.19 +	nybbel = byte & 0x0f;
    2.20 +	if (nybbel > 9)
    2.21 +		digits[1] = 'a' + nybbel-10;
    2.22 +	else
    2.23 +		digits[1] = '0' + nybbel;
    2.24 +}
    2.25 +
    2.26 +/* Convert an array of 16 unsigned bytes to a DCE/OSF formatted UUID
    2.27 +   string.
    2.28 +
    2.29 +   Pre-condition: sizeof(dest) >= 37 */
    2.30 +void
    2.31 +uuid_to_string(char *dest, uint8_t *uuid)
    2.32 +{
    2.33 +	int i = 0;
    2.34 +	char *p = dest;
    2.35 +
    2.36 +	for (i = 0; i < 4; ++i) {
    2.37 +		byte_to_hex(p, uuid[i]);
    2.38 +		p += 2;
    2.39 +	}
    2.40 +	*p++ = '-';
    2.41 +	for (i = 4; i < 6; ++i) {
    2.42 +		byte_to_hex(p, uuid[i]);
    2.43 +		p += 2;
    2.44 +	}
    2.45 +	*p++ = '-';
    2.46 +	for (i = 6; i < 8; ++i) {
    2.47 +		byte_to_hex(p, uuid[i]);
    2.48 +		p += 2;
    2.49 +	}
    2.50 +	*p++ = '-';
    2.51 +	for (i = 8; i < 10; ++i) {
    2.52 +		byte_to_hex(p, uuid[i]);
    2.53 +		p += 2;
    2.54 +	}
    2.55 +	*p++ = '-';
    2.56 +	for (i = 10; i < 16; ++i) {
    2.57 +		byte_to_hex(p, uuid[i]);
    2.58 +		p += 2;
    2.59 +	}
    2.60 +}
     3.1 --- a/tools/firmware/hvmloader/util.h	Mon Aug 28 12:50:55 2006 +0100
     3.2 +++ b/tools/firmware/hvmloader/util.h	Mon Aug 28 12:59:07 2006 +0100
     3.3 @@ -25,6 +25,16 @@ void *memcpy(void *dest, const void *src
     3.4  void *memset(void *s, int c, unsigned n);
     3.5  char *itoa(char *a, unsigned int i);
     3.6  
     3.7 +/* convert a byte to two lowercase hex digits, with no terminating NUL 
     3.8 +   character.  digits[] must have at least two elements. */
     3.9 +void byte_to_hex(char *digits, uint8_t byte);
    3.10 +
    3.11 +/* Convert an array of 16 unsigned bytes to a DCE/OSF formatted UUID
    3.12 +   string.
    3.13 +
    3.14 +   Pre-condition: sizeof(dest) >= 37 */
    3.15 +void uuid_to_string(char *dest, uint8_t *uuid);
    3.16 +
    3.17  /* Debug output */
    3.18  void puts(const char *s);
    3.19