3 files changed, 61 insertions(+), 6 deletions(-) smbios.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ sysemu.h | 1 + vl.c | 8 ++++++++
# HG changeset patch # User Ryan Harper <[EMAIL PROTECTED]> # Date 1197402122 21600 # Node ID f1372e77455459b3e21ae908bb56cd43356159fd # Parent 115f40a4994be1d5b44ef193b3ccbe8e26410eef Add -uuid command line flag This patch allows users to specify a uuid. If no uuid is specified, then one is generated. Now supports -uuid both with and without libuuid Moved some includes into hw/hw.h and sysemh.h Reduced the number of CONFIG_UUID defines Signed-off-by: Ryan Harper <[EMAIL PROTECTED]> diff -r 115f40a4994b -r f1372e774554 smbios.c --- a/smbios.c Tue Dec 11 13:42:02 2007 -0600 +++ b/smbios.c Tue Dec 11 13:42:02 2007 -0600 @@ -32,11 +32,47 @@ #ifdef CONFIG_UUID #include <uuid/uuid.h> -#endif + +static int qemu_uuid_parse(const char *in, uint8_t *uu) +{ + if (uuid_parse(in, *((uuid_t *)uu)) < 0) + return -1; + + return 0; +} + +#define qemu_uuid_generate(x) (uuid_generate(*((uuid_t *)x))) + +#else +#define UUID2 "%02x%02x" +#define UUID4 "%02x%02x%02x%02x" +#define UUID6 "%02x%02x%02x%02x%02x%02x" +#define UUID_FMT UUID4"-"UUID2"-"UUID2"-"UUID2"-"UUID6 + +static int qemu_uuid_parse(const char *in, uint8_t *uu) +{ + unsigned int u[16]; + int rv, i; + + /* NB: sscanf requires %x format to store values in unsigned int */ + rv = sscanf(in, UUID_FMT, u, u+1, u+2, u+3, u+4, u+5, u+6, u+7, u+8, + u+9, u+10, u+11, u+12, u+13, u+14, u+15); + + if (rv != 16) + return -1; + + for (i=0; i<16; i++) + uu[i] = (uint8_t)u[i]; + + return 0; +} +#define qemu_uuid_generate(x) (memcpy(x, "QEMUQEMUQEMUQEMU", 16)) + +#endif /* CONFIG_UUID */ /* Write a two-character hex representation of 'byte' to digits[]. Pre-condition: sizeof(digits) >= 2 */ -void +static void byte_to_hex(char *digits, uint8_t byte) { uint8_t nybbel = byte >> 4; @@ -493,12 +529,22 @@ load_smbios_tables(uint8_t *entry, uint8 uint32_t major_version = 0; uint32_t minor_version = 9; #ifdef CONFIG_UUID - uuid_t uuid; - - uuid_generate(uuid); + uuid_t u; + uint8_t *uuid = (char *)&u; #else - uint8_t uuid[16] = "QEMUQEMUQEMUQEMU"; + uint8_t uuid[16]; #endif + + /* parse user-specified uuid if present */ + if (qemu_uuid != NULL) { + if (qemu_uuid_parse(qemu_uuid, uuid) < 0) { + fprintf(stderr, "SMBIOS: Could not parse user UUID" + " string, check format.\n"); + return -1; + } + } else { + qemu_uuid_generate(uuid); + } len = write_smbios_tables(entry, table, phys_table_start, smp_cpus, (ram_size >> 20), diff -r 115f40a4994b -r f1372e774554 sysemu.h --- a/sysemu.h Tue Dec 11 13:42:02 2007 -0600 +++ b/sysemu.h Tue Dec 11 13:42:02 2007 -0600 @@ -90,6 +90,7 @@ extern int autostart; extern int autostart; extern int old_param; extern const char *bootp_filename; +extern const char *qemu_uuid; #ifdef USE_KQEMU diff -r 115f40a4994b -r f1372e774554 vl.c --- a/vl.c Tue Dec 11 13:42:02 2007 -0600 +++ b/vl.c Tue Dec 11 13:42:02 2007 -0600 @@ -138,6 +138,7 @@ int inet_aton(const char *cp, struct in_ #else #define SMBD_COMMAND "/usr/sbin/smbd" #endif +const char *qemu_uuid; //#define DEBUG_UNUSED_IOPORT //#define DEBUG_IOPORT @@ -7545,6 +7546,8 @@ static void help(int exitcode) "-no-reboot exit instead of rebooting\n" "-loadvm file start right away with a saved state (loadvm in monitor)\n" "-vnc display start a VNC server on display\n" + "-uuid %%08x-%%04x-%%04x-%%04x-%%012x\n" + " specify machine UUID\n" #ifndef _WIN32 "-daemonize daemonize QEMU after initializing\n" #endif @@ -7647,6 +7650,7 @@ enum { QEMU_OPTION_vnc, QEMU_OPTION_no_acpi, QEMU_OPTION_no_reboot, + QEMU_OPTION_uuid, QEMU_OPTION_show_cursor, QEMU_OPTION_daemonize, QEMU_OPTION_option_rom, @@ -7742,6 +7746,7 @@ const QEMUOption qemu_options[] = { { "usbdevice", HAS_ARG, QEMU_OPTION_usbdevice }, { "smp", HAS_ARG, QEMU_OPTION_smp }, { "vnc", HAS_ARG, QEMU_OPTION_vnc }, + { "uuid", HAS_ARG, QEMU_OPTION_uuid }, /* temporary options */ { "usb", 0, QEMU_OPTION_usb }, @@ -8527,6 +8532,9 @@ int main(int argc, char **argv) case QEMU_OPTION_daemonize: daemonize = 1; break; + case QEMU_OPTION_uuid: + qemu_uuid = optarg; + break; case QEMU_OPTION_option_rom: if (nb_option_roms >= MAX_OPTION_ROMS) { fprintf(stderr, "Too many option ROMs\n");