diff mbox series

[RFC,5/6] hw/arm: add mask boot ROM logic

Message ID 20220110175104.2908956-6-alex.bennee@linaro.org
State New
Headers show
Series Basic skeleton of RP2040 Raspbery Pi Pico | expand

Commit Message

Alex Bennée Jan. 10, 2022, 5:51 p.m. UTC
The mask ROM contains the initial boot code to start the RP2040. It
also contains some common sub-routines as well as the flash
programming code for drag and drop programming. As a result we need to
ensure the full version is available to any user supplied programs we
might want to run.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 hw/arm/rp2040.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/hw/arm/rp2040.c b/hw/arm/rp2040.c
index c6cc9b7165..9a5bc20159 100644
--- a/hw/arm/rp2040.c
+++ b/hw/arm/rp2040.c
@@ -8,10 +8,12 @@ 
 
 #include "qemu/osdep.h"
 #include "qemu/units.h"
+#include "qemu/datadir.h"
 #include "qapi/error.h"
 #include "hw/arm/armv7m.h"
 #include "hw/arm/rp2040.h"
 #include "hw/misc/unimp.h"
+#include "hw/loader.h"
 #include "hw/sysbus.h"
 #include "hw/qdev-properties.h"
 
@@ -33,6 +35,8 @@  typedef struct RP2040Class {
 #define RP2040_SRAM4_BASE 0x20040000
 #define RP2040_SRAM5_BASE 0x20041000
 
+#define RP2040_MASK_ROM   "pipico.rom"
+
 static void rp2040_init(Object *obj)
 {
     RP2040State *s = RP2040(obj);
@@ -61,6 +65,8 @@  static void rp2040_realize(DeviceState *dev, Error **errp)
     RP2040State *s = RP2040(dev);
     Object *obj = OBJECT(dev);
     int n;
+    g_autofree char *mask_rom = qemu_find_file(QEMU_FILE_TYPE_BIOS,
+                                               RP2040_MASK_ROM);
 
     if (!s->memory) {
         error_setg(errp, "%s: memory property was not set", __func__);
@@ -68,9 +74,20 @@  static void rp2040_realize(DeviceState *dev, Error **errp)
     }
 
     /* initialize internal 16 KB internal ROM */
-    memory_region_init_rom(&s->rom, obj, "rp2040.rom0", 16 * KiB, errp);
+    memory_region_init_rom(&s->rom, obj, "rp2040.rom", 16 * KiB, errp);
     memory_region_add_subregion(s->memory, 0, &s->rom);
 
+    if (!mask_rom) {
+        error_setg(errp, "%s: unable to find mask_rom %s",
+                   __func__, RP2040_MASK_ROM);
+        return;
+    }
+    n = load_image_targphys(mask_rom, 0x0, 16 * KiB);
+    if (n <= 0) {
+        error_setg(errp, "%s: failed to load mask rom image: %s",
+                   __func__, RP2040_MASK_ROM);
+    }
+
     /* SRAM (Main 256k bank + two 4k banks)*/
     memory_region_init_ram(&s->sram03, obj, "rp2040.sram03", 256 * KiB, errp);
     memory_region_add_subregion(s->memory, RP2040_SRAM_BASE, &s->sram03);