add a boot option to do strict boot

Seabios already added a new device type to halt booting.
Qemu can add "HALT" at the end of bootindex string, then
seabios will halt booting after trying to boot from all
selected devices.

This patch added a new boot option to configure if boot
from un-selected devices.

This option only effects when boot priority is changed by
bootindex options, the old style(-boot order=..) will still
try to boot from un-selected devices.

v2: add HALT entry in get_boot_devices_list()
v3: rebase to latest qemu upstream

Signed-off-by: Amos Kong <akong@redhat.com>
Message-id: 1363674207-31496-1-git-send-email-akong@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Amos Kong 2013-03-19 14:23:27 +08:00 committed by Anthony Liguori
parent 8510d91eba
commit c8a6ae8bb9
2 changed files with 30 additions and 3 deletions

View file

@ -161,14 +161,14 @@ ETEXI
DEF("boot", HAS_ARG, QEMU_OPTION_boot, DEF("boot", HAS_ARG, QEMU_OPTION_boot,
"-boot [order=drives][,once=drives][,menu=on|off]\n" "-boot [order=drives][,once=drives][,menu=on|off]\n"
" [,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time]\n" " [,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time][,strict=on|off]\n"
" 'drives': floppy (a), hard disk (c), CD-ROM (d), network (n)\n" " 'drives': floppy (a), hard disk (c), CD-ROM (d), network (n)\n"
" 'sp_name': the file's name that would be passed to bios as logo picture, if menu=on\n" " 'sp_name': the file's name that would be passed to bios as logo picture, if menu=on\n"
" 'sp_time': the period that splash picture last if menu=on, unit is ms\n" " 'sp_time': the period that splash picture last if menu=on, unit is ms\n"
" 'rb_timeout': the timeout before guest reboot when boot failed, unit is ms\n", " 'rb_timeout': the timeout before guest reboot when boot failed, unit is ms\n",
QEMU_ARCH_ALL) QEMU_ARCH_ALL)
STEXI STEXI
@item -boot [order=@var{drives}][,once=@var{drives}][,menu=on|off][,splash=@var{sp_name}][,splash-time=@var{sp_time}][,reboot-timeout=@var{rb_timeout}] @item -boot [order=@var{drives}][,once=@var{drives}][,menu=on|off][,splash=@var{sp_name}][,splash-time=@var{sp_time}][,reboot-timeout=@var{rb_timeout}][,strict=on|off]
@findex -boot @findex -boot
Specify boot order @var{drives} as a string of drive letters. Valid Specify boot order @var{drives} as a string of drive letters. Valid
drive letters depend on the target achitecture. The x86 PC uses: a, b drive letters depend on the target achitecture. The x86 PC uses: a, b
@ -192,6 +192,10 @@ when boot failed, then reboot. If @var{rb_timeout} is '-1', guest will not
reboot, qemu passes '-1' to bios by default. Currently Seabios for X86 reboot, qemu passes '-1' to bios by default. Currently Seabios for X86
system support it. system support it.
Do strict boot via @option{strict=on} as far as firmware/BIOS
supports it. This only effects when boot priority is changed by
bootindex options. The default is non-strict boot.
@example @example
# try to boot from network first, then from hard disk # try to boot from network first, then from hard disk
qemu-system-i386 -boot order=nc qemu-system-i386 -boot order=nc

25
vl.c
View file

@ -234,6 +234,7 @@ int ctrl_grab = 0;
unsigned int nb_prom_envs = 0; unsigned int nb_prom_envs = 0;
const char *prom_envs[MAX_PROM_ENVS]; const char *prom_envs[MAX_PROM_ENVS];
int boot_menu; int boot_menu;
bool boot_strict;
uint8_t *boot_splash_filedata; uint8_t *boot_splash_filedata;
size_t boot_splash_filedata_size; size_t boot_splash_filedata_size;
uint8_t qemu_extra_params_fw[2]; uint8_t qemu_extra_params_fw[2];
@ -458,6 +459,9 @@ static QemuOptsList qemu_boot_opts = {
}, { }, {
.name = "reboot-timeout", .name = "reboot-timeout",
.type = QEMU_OPT_STRING, .type = QEMU_OPT_STRING,
}, {
.name = "strict",
.type = QEMU_OPT_STRING,
}, },
{ /*End of list */ } { /*End of list */ }
}, },
@ -1267,6 +1271,12 @@ char *get_boot_devices_list(size_t *size)
*size = total; *size = total;
if (boot_strict && *size > 0) {
list[total-1] = '\n';
list = g_realloc(list, total + 4);
memcpy(&list[total], "HALT", 4);
*size = total + 4;
}
return list; return list;
} }
@ -3131,7 +3141,7 @@ int main(int argc, char **argv, char **envp)
static const char * const params[] = { static const char * const params[] = {
"order", "once", "menu", "order", "once", "menu",
"splash", "splash-time", "splash", "splash-time",
"reboot-timeout", NULL "reboot-timeout", "strict", NULL
}; };
char buf[sizeof(boot_devices)]; char buf[sizeof(boot_devices)];
char *standard_boot_devices; char *standard_boot_devices;
@ -3174,6 +3184,19 @@ int main(int argc, char **argv, char **envp)
exit(1); exit(1);
} }
} }
if (get_param_value(buf, sizeof(buf),
"strict", optarg)) {
if (!strcmp(buf, "on")) {
boot_strict = true;
} else if (!strcmp(buf, "off")) {
boot_strict = false;
} else {
fprintf(stderr,
"qemu: invalid option value '%s'\n",
buf);
exit(1);
}
}
if (!qemu_opts_parse(qemu_find_opts("boot-opts"), if (!qemu_opts_parse(qemu_find_opts("boot-opts"),
optarg, 0)) { optarg, 0)) {
exit(1); exit(1);