qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [patch 4/4] Add Flash support to the Versatile PB platform


From: Thomas Petazzoni
Subject: [Qemu-devel] [patch 4/4] Add Flash support to the Versatile PB platform
Date: Thu, 02 Oct 2008 15:02:18 +0200
User-agent: quilt/0.46-1

This patch adds the emulation of the 64 MB Intel Flash present at
address 0x34000000 on the ARM Versatile PB platform, with a 256 KB
sector size. This flash emulation is enabled using the -pflash
option. If not enabled, Qemu falls back to the traditionnal way of
loading the kernel.

The RAM size is also hardcoded to 128 MB, and the memory size provided
by Qemu's -m option is the total memory size, so it must be at least
192 MB to run the Versatile PB with flash emulation. The same method
is used on other platforms, such as Gumstix.

Signed-off-by: Thomas Petazzoni <address@hidden>
---
 hw/versatilepb.c |   44 +++++++++++++++++++++++++++++++++++++-------
 1 file changed, 37 insertions(+), 7 deletions(-)

Index: qemu/hw/versatilepb.c
===================================================================
--- qemu.orig/hw/versatilepb.c
+++ qemu/hw/versatilepb.c
@@ -15,6 +15,7 @@
 #include "sysemu.h"
 #include "pci.h"
 #include "boards.h"
+#include "flash.h"
 
 /* Primary interrupt controller.  */
 
@@ -159,6 +160,12 @@
 
 static struct arm_boot_info versatile_binfo;
 
+#define VERSATILE_RAM_ADDR        0
+#define VERSATILE_RAM_SIZE        (128 * 1024 * 1024)
+#define VERSATILE_FLASH_ADDR      0x34000000
+#define VERSATILE_FLASH_SIZE      (64 * 1024 * 1024)
+#define VERSATILE_FLASH_SECT_SIZE (256 * 1024)
+
 static void versatile_init(ram_addr_t ram_size, int vga_ram_size,
                      const char *boot_device, DisplayState *ds,
                      const char *kernel_filename, const char *kernel_cmdline,
@@ -174,6 +181,7 @@
     int n;
     int done_smc = 0;
     int index;
+    int hasflash = 0;
 
     if (!cpu_model)
         cpu_model = "arm926";
@@ -184,7 +192,9 @@
     }
     /* ??? RAM should repeat to fill physical memory space.  */
     /* SDRAM at address zero.  */
-    cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);
+    cpu_register_physical_memory(VERSATILE_RAM_ADDR,
+                                VERSATILE_RAM_SIZE,
+                                qemu_ram_alloc(VERSATILE_RAM_SIZE) | 
IO_MEM_RAM);
 
     arm_sysctl_init(0x10000000, 0x41007004);
     pic = arm_pic_init_cpu(env);
@@ -249,6 +259,21 @@
     /* Add PL031 Real Time Clock. */
     pl031_init(0x101e8000,pic[10]);
 
+    index = drive_get_index(IF_PFLASH, 0, 0);
+    if (index != -1) {
+      if (!pflash_cfi01_register(VERSATILE_FLASH_ADDR,
+                                qemu_ram_alloc(VERSATILE_FLASH_SIZE),
+                                drives_table[index].bdrv,
+                                VERSATILE_FLASH_SECT_SIZE,
+                                VERSATILE_FLASH_SIZE / 
VERSATILE_FLASH_SECT_SIZE,
+                                4, 0, 0, 0, 0)) {
+       fprintf(stderr, "qemu: error registering flash memory.\n");
+       exit(1);
+      }
+
+      hasflash = 1;
+    }
+
     /* Memory map for Versatile/PB:  */
     /* 0x10000000 System registers.  */
     /* 0x10001000 PCI controller config registers.  */
@@ -285,12 +310,17 @@
     /*  0x101f3000 UART2.  */
     /* 0x101f4000 SSPI.  */
 
-    versatile_binfo.ram_size = ram_size;
-    versatile_binfo.kernel_filename = kernel_filename;
-    versatile_binfo.kernel_cmdline = kernel_cmdline;
-    versatile_binfo.initrd_filename = initrd_filename;
-    versatile_binfo.board_id = board_id;
-    arm_load_kernel(env, &versatile_binfo);
+    if (! hasflash) {
+      versatile_binfo.ram_size = VERSATILE_RAM_SIZE;
+      versatile_binfo.kernel_filename = kernel_filename;
+      versatile_binfo.kernel_cmdline = kernel_cmdline;
+      versatile_binfo.initrd_filename = initrd_filename;
+      versatile_binfo.board_id = board_id;
+      arm_load_kernel(env, &versatile_binfo);
+    }
+    else {
+      env->regs[15] = 0x34000000;
+    }
 }
 
 static void vpb_init(ram_addr_t ram_size, int vga_ram_size,

-- 
Thomas Petazzoni, Free Electrons
Kernel, drivers and embedded Linux development,
consulting, training and support.
http://free-electrons.com




reply via email to

[Prev in Thread] Current Thread [Next in Thread]