Commit 0ecdffbb60a2723779a37fa17b717d919d670336

Authored by aurel32
1 parent 4001a81e

Allow bootdevice change from the monitor

(Gildas Le Nadan)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4333 c046a42c-6fe2-441c-8c8c-71466251a162
... ... @@ -92,6 +92,12 @@ typedef void QEMUResetHandler(void *opaque);
92 92  
93 93 void qemu_register_reset(QEMUResetHandler *func, void *opaque);
94 94  
  95 +/* handler to set the boot_device for a specific type of QEMUMachine */
  96 +/* return 0 if success */
  97 +typedef int QEMUBootSetHandler(const char *boot_device);
  98 +extern QEMUBootSetHandler *qemu_boot_set_handler;
  99 +void qemu_register_boot_set(QEMUBootSetHandler *func);
  100 +
95 101 /* These should really be in isa.h, but are here to make pc.h happy. */
96 102 typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
97 103 typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
... ...
... ... @@ -189,6 +189,33 @@ static int boot_device2nibble(char boot_device)
189 189 return 0;
190 190 }
191 191  
  192 +/* copy/pasted from cmos_init, should be made a general function
  193 + and used there as well */
  194 +int pc_boot_set(const char *boot_device)
  195 +{
  196 +#define PC_MAX_BOOT_DEVICES 3
  197 + RTCState *s = rtc_state;
  198 + int nbds, bds[3] = { 0, };
  199 + int i;
  200 +
  201 + nbds = strlen(boot_device);
  202 + if (nbds > PC_MAX_BOOT_DEVICES) {
  203 + term_printf("Too many boot devices for PC\n");
  204 + return(1);
  205 + }
  206 + for (i = 0; i < nbds; i++) {
  207 + bds[i] = boot_device2nibble(boot_device[i]);
  208 + if (bds[i] == 0) {
  209 + term_printf("Invalid boot device for PC: '%c'\n",
  210 + boot_device[i]);
  211 + return(1);
  212 + }
  213 + }
  214 + rtc_set_memory(s, 0x3d, (bds[1] << 4) | bds[0]);
  215 + rtc_set_memory(s, 0x38, (bds[2] << 4));
  216 + return(0);
  217 +}
  218 +
192 219 /* hd_table must contain 4 block drivers */
193 220 static void cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
194 221 const char *boot_device, BlockDriverState **hd_table)
... ... @@ -713,6 +740,8 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
713 740 below_4g_mem_size = ram_size;
714 741 }
715 742  
  743 + qemu_register_boot_set(pc_boot_set);
  744 +
716 745 linux_boot = (kernel_filename != NULL);
717 746  
718 747 /* init CPUs */
... ...
monitor.c
... ... @@ -1019,6 +1019,21 @@ static void do_ioport_read(int count, int format, int size, int addr, int has_in
1019 1019 suffix, addr, size * 2, val);
1020 1020 }
1021 1021  
  1022 +static void do_boot_set(const char *bootdevice)
  1023 +{
  1024 + int res;
  1025 +
  1026 + if (qemu_boot_set_handler) {
  1027 + res = qemu_boot_set_handler(bootdevice);
  1028 + if (res == 0)
  1029 + term_printf("boot device list now set to %s\n", bootdevice);
  1030 + else
  1031 + term_printf("setting boot device list failed with error %i\n", res);
  1032 + } else {
  1033 + term_printf("no function defined to set boot device list for this architecture\n");
  1034 + }
  1035 +}
  1036 +
1022 1037 static void do_system_reset(void)
1023 1038 {
1024 1039 qemu_system_reset_request();
... ... @@ -1369,6 +1384,8 @@ static term_cmd_t term_cmds[] = {
1369 1384 "addr size file", "save to disk virtual memory dump starting at 'addr' of size 'size'", },
1370 1385 { "pmemsave", "lis", do_physical_memory_save,
1371 1386 "addr size file", "save to disk physical memory dump starting at 'addr' of size 'size'", },
  1387 + { "boot_set", "s", do_boot_set,
  1388 + "bootdevice", "define new values for the boot device list" },
1372 1389 #if defined(TARGET_I386)
1373 1390 { "nmi", "i", do_inject_nmi,
1374 1391 "cpu", "inject an NMI on the given CPU", },
... ...
qemu-doc.texi
... ... @@ -1259,6 +1259,14 @@ intercepts at low level, such as @code{ctrl-alt-f1} in X Window.
1259 1259  
1260 1260 Reset the system.
1261 1261  
  1262 +@item boot_set @var{bootdevicelist}
  1263 +
  1264 +Define new values for the boot device list. Those values will override
  1265 +the values specified on the command line through the @code{-boot} option.
  1266 +
  1267 +The values that can be specified here depend on the machine type, but are
  1268 +the same that can be specified in the @code{-boot} command line option.
  1269 +
1262 1270 @item usb_add @var{devname}
1263 1271  
1264 1272 Add the USB device @var{devname}. For details of available devices see
... ...
... ... @@ -6855,6 +6855,14 @@ void qemu_system_powerdown_request(void)
6855 6855 cpu_interrupt(cpu_single_env, CPU_INTERRUPT_EXIT);
6856 6856 }
6857 6857  
  6858 +/* boot_set handler */
  6859 +QEMUBootSetHandler *qemu_boot_set_handler = NULL;
  6860 +
  6861 +void qemu_register_boot_set(QEMUBootSetHandler *func)
  6862 +{
  6863 + qemu_boot_set_handler = func;
  6864 +}
  6865 +
6858 6866 void main_loop_wait(int timeout)
6859 6867 {
6860 6868 IOHandlerRecord *ioh;
... ...