Skip to contentSkip to conversation

change boot device in monitor

Qemu-devel Anand Kumria 2 participants 3 messages Oct 10, 2004

lore
Share & tools
lore
#0 lore raw

Hi,

Attached is a patch which allows you to change the boot device in the monitor. The change won't take affect until the next 'system_reset' but I've found it useful as I can specify a floppy, hard disk and cdrom and switch between booting them without exiting.

This is against current CVS - I've only tested this on x86 but I've put in what I think are the right hooks for PPC and Sparc. When looking at this, I was thinking that a struct vm_state might be useful.

As I'm now going to be working on a way to modify the memory amount within the monitor. The struct_vm would basically be the what is used for savevm/loadvm. Thoughts?

Regards,
Anand

hw/pc.c +23 -15
diff -x qemu.pod -X dont-diff -urN upstream/hw/pc.c my-chg-boot/hw/pc.c
@@ -101,6 +101,26 @@
     return val;
 }
 
+
+void boot_device_set(int boot_device)
+{
+  RTCState *s = rtc_state;
+
+  switch(boot_device) {
+  case 'a':
+  case 'b':
+    rtc_set_memory(s, 0x3d, 0x01); /* floppy boot */
+    break;
+  default:
+  case 'c':
+    rtc_set_memory(s, 0x3d, 0x02); /* hard drive boot */
+    break;
+  case 'd':
+    rtc_set_memory(s, 0x3d, 0x03); /* CD-ROM boot */
+    break;
+  }
+}
+
 static void cmos_init_hd(int type_ofs, int info_ofs, BlockDriverState *hd) 
 {
     RTCState *s = rtc_state;
@@ -163,21 +183,9 @@
         val = 65535;
     rtc_set_memory(s, 0x34, val);
     rtc_set_memory(s, 0x35, val >> 8);
-    
-    switch(boot_device) {
-    case 'a':
-    case 'b':
-        rtc_set_memory(s, 0x3d, 0x01); /* floppy boot */
-        break;
-    default:
-    case 'c':
-        rtc_set_memory(s, 0x3d, 0x02); /* hard drive boot */
-        break;
-    case 'd':
-        rtc_set_memory(s, 0x3d, 0x03); /* CD-ROM boot */
-        break;
-    }
-
+ 
+    boot_device_set(boot_device);
+   
     /* floppy type */
 
     fd0 = fdctrl_get_drive_type(floppy_controller, 0);
hw/ppc.c +6 -1
diff -x qemu.pod -X dont-diff -urN upstream/hw/ppc.c my-chg-boot/hw/ppc.c
@@ -398,6 +398,11 @@
     return crc;
 }
 
+static void boot_device_set(m48t59_t *nvram, int boot_device)
+{
+    NVRAM_set_byte(nvram,   0x34, boot_device);
+}
+
 #define CMDLINE_ADDR 0x017ff000
 
 int PPC_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size,
@@ -417,7 +422,7 @@
     NVRAM_set_word(nvram,   0x14, NVRAM_size);
     NVRAM_set_string(nvram, 0x20, arch, 16);
     NVRAM_set_lword(nvram,  0x30, RAM_size);
-    NVRAM_set_byte(nvram,   0x34, boot_device);
+    boot_device_set(nvram, boot_device);
     NVRAM_set_lword(nvram,  0x38, kernel_image);
     NVRAM_set_lword(nvram,  0x3C, kernel_size);
     if (cmdline) {
monitor.c +24 -0
diff -x qemu.pod -X dont-diff -urN upstream/monitor.c my-chg-boot/monitor.c
@@ -173,6 +173,28 @@
     }
 }
 
+static void do_boot(const char *boot_from)
+{
+  switch(boot_from[0]) {
+  case 'a':
+  case 'b':
+  case 'c':
+  case 'd':
+#ifdef TARGET_PPC    
+    term_printf("not implemented for PPC\n");
+#elif TARGET_SPARC
+    term_printf("not implemented for Sparc\n");
+#else
+    boot_device_set(boot_from[0]);
+#endif
+    break;
+  default:
+    term_printf("boot device must be one of: a, b, c or d\n");
+    break;
+  }
+
+}
+
 static void do_info(const char *item)
 {
     term_cmd_t *cmd;
@@ -821,6 +843,8 @@
 static term_cmd_t term_cmds[] = {
     { "help|?", "s?", do_help, 
       "[cmd]", "show the help" },
+    { "boot", "s", do_boot,
+      "device", "change the boot device (takes affect next system_reset)" },
     { "commit", "", do_commit, 
       "", "commit changes to the disk images (if -snapshot is used)" },
     { "info", "s?", do_info,
vl.h +9 -0
diff -x qemu.pod -X dont-diff -urN upstream/vl.h my-chg-boot/vl.h
@@ -638,7 +638,16 @@
 int pit_get_gate(PITState *pit, int channel);
 int pit_get_out(PITState *pit, int channel, int64_t current_time);
 
+/* pc.c and ppc.c */
+#ifdef TARGET_PPC
+#include "hw/m48t59.h"
+void boot_device_set(m48t59_t *nvram, int boot_device);
+#else /* TARGET_PC */
+void boot_device_set(int boot_device);
+#endif 
+
 /* pc.c */
+
 void pc_init(int ram_size, int vga_ram_size, int boot_device,
              DisplayState *ds, const char **fd_filename, int snapshot,
              const char *kernel_filename, const char *kernel_cmdline,
#1 lore raw

Hi,

Quoted 4 lines · Anand Kumria

Attached is a patch which allows you to change the boot device in the monitor. The change won't take affect until the next 'system_reset' but I've found it useful as I can specify a floppy, hard disk and cdrom and switch between booting them without exiting.

I like this feature! (Also your "info version").

Quoted 3 lines

As I'm now going to be working on a way to modify the memory amount within the monitor. The struct_vm would basically be the what is used for savevm/loadvm. Thoughts?

Well, I prefer to specify the memory on the command line. Of course, if you loadvm with a different size, this does not work AFAIK, but IMHO it does not make sense to support virtual hot-plugging of memory ;-)

Ciao,
Dscho

#2 lore raw
Quoted 10 lines · Johannes Schindelin

Hi,

Quoted 4 lines · Anand Kumria

Attached is a patch which allows you to change the boot device in the monitor. The change won't take affect until the next 'system_reset' but I've found it useful as I can specify a floppy, hard disk and cdrom and switch between booting them without exiting.

I like this feature! (Also your "info version").

Thanks - I hope Fabrice does also.

Quoted 7 lines
Quoted 3 lines

As I'm now going to be working on a way to modify the memory amount within the monitor. The struct_vm would basically be the what is used for savevm/loadvm. Thoughts?

Well, I prefer to specify the memory on the command line. Of course, if you loadvm with a different size, this does not work AFAIK, but IMHO it does not make sense to support virtual hot-plugging of memory ;-)

The reason I want to be able to do this is to support testing installer disks and operating systems with varying amounts of memory. Since qemu can be forked and have the monitor available to another process as stdin/stdout it means I can setup regressions test for memory points.

Cheers,
Anand