Skip to contentSkip to conversation

hw/mips/boston: Initrd support

PATCH In review Jiaxun Yang 3 participants 6 messages Aug 13, 2022 – Aug 18, 2022

lore
Share & tools
lore
#0 lore raw

cover hw/mips/boston: Initrd support

Hi all,

Just a small addition to make boston board easier to use :-)

Thanks
- Jiaxun

Jiaxun Yang (2):
mips/boston: Support initrd for ELF kernel
hw/mips/boston: Pack fdt in fdt filter

 hw/mips/boston.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
Signature · 1 line
2.32.1 (Apple Git-133)
#1 lore raw

PATCH 1/2 hw/mips/boston: Support initrd for ELF kernel

When loading ELF kernel we can just load out initrd after DTB and append initrd information to DeviceTree's chosen node.

---
 hw/mips/boston.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
hw/mips/boston.c +39 -0
index d2ab9da1a0..5145179951 100644
@@ -73,6 +73,8 @@ struct BostonState {
 
     hwaddr kernel_entry;
     hwaddr fdt_base;
+    hwaddr initrd_base;
+    hwaddr initrd_end;
 };
 
 enum {
@@ -383,6 +385,14 @@ static const void *boston_fdt_filter(void *opaque, const void *fdt_orig,
         return NULL;
     }
 
+    if (s->initrd_base) {
+        qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start",
+                             s->initrd_base);
+
+        qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end",
+                             s->initrd_end);
+    }
+
     ram_low_sz = MIN(256 * MiB, machine->ram_size);
     ram_high_sz = machine->ram_size - ram_low_sz;
     qemu_fdt_setprop_sized_cells(fdt, "/memory@0", "reg",
@@ -804,6 +814,35 @@ static void boston_mach_init(MachineState *machine)
                 dtb_file_data = create_fdt(s, boston_memmap, &dt_size);
             }
 
+            if (machine->initrd_filename) {
+                /* We want to leave low 128 MiB memory for kernelrelocation */
+                hwaddr initrd_paddr = MAX(128 * MiB,
+                                         QEMU_ALIGN_UP(dtb_paddr + dt_size,
+                                         64 * KiB));
+                int maxsz = boston_memmap[BOSTON_LOWDDR].size - initrd_paddr;
+
+                if (maxsz <= 0) {
+                        error_report("no space left for ramdisk '%s'",
+                                     machine->initrd_filename);
+                        exit(1);
+                }
+
+                int size = load_ramdisk(machine->initrd_filename,
+                                        initrd_paddr, maxsz);
+                if (size < 0) {
+                    size = load_image_targphys(machine->initrd_filename,
+                                               initrd_paddr, maxsz);
+                    if (size < 0) {
+                        error_report("could not load ramdisk '%s'",
+                                     machine->initrd_filename);
+                        exit(1);
+                    }
+                }
+
+                s->initrd_base = initrd_paddr;
+                s->initrd_end = s->initrd_base + size;
+            }
+
             dtb_load_data = boston_fdt_filter(s, dtb_file_data,
                                               NULL, &dtb_vaddr);
 
Signature · 1 line
2.32.1 (Apple Git-133)
#2 lore raw

PATCH 2/2 hw/mips/boston: Pack fdt in fdt filter

In reply to Jiaxun Yang

FDT can be awfully fat after series of modifications in fdt filter. Just pack it up before add to ram.

---
 hw/mips/boston.c | 1 +
 1 file changed, 1 insertion(+)
hw/mips/boston.c +1 -0
index 5145179951..a40f193f78 100644
@@ -400,6 +400,7 @@ static const void *boston_fdt_filter(void *opaque, const void *fdt_orig,
                         1, boston_memmap[BOSTON_HIGHDDR].base + ram_low_sz,
                         1, ram_high_sz);
 
+    fdt_pack(fdt);
     fdt = g_realloc(fdt, fdt_totalsize(fdt));
     qemu_fdt_dumpdtb(fdt, fdt_sz);
 
Signature · 1 line
2.32.1 (Apple Git-133)
#3 lore raw

Re: [PATCH 2/2] hw/mips/boston: Pack fdt in fdt filter

Quoted 13 lines · Jiaxun Yang

FDT can be awfully fat after series of modifications in fdt filter. Just pack it up before add to ram.

---
  hw/mips/boston.c | 1 +
  1 file changed, 1 insertion(+)
hw/mips/boston.c +0 -0
index 5145179951..a40f193f78 100644

hw/mips/boston.c static const void *boston_fdt_filter(void *opaque, const void *fdt_orig, · line 406

Quoted 7 lines
hw/mips/boston.c +1 -0
@@ -400,6 +400,7 @@ static const void *boston_fdt_filter(void *opaque, const void *fdt_orig,
                          1, boston_memmap[BOSTON_HIGHDDR].base + ram_low_sz,
                          1, ram_high_sz);
 
+    fdt_pack(fdt);
      fdt = g_realloc(fdt, fdt_totalsize(fdt));
      qemu_fdt_dumpdtb(fdt, fdt_sz);
 

Why not pack by default in qemu_fdt_dumpdtb()?

#4 lore raw

Re: [PATCH 2/2] hw/mips/boston: Pack fdt in fdt filter

Quoted 16 lines

2022年8月16日 01:44,Philippe Mathieu-Daudé <[email protected]> 写道:

Quoted 11 lines · Jiaxun Yang

FDT can be awfully fat after series of modifications in fdt filter. Just pack it up before add to ram.

---
 hw/mips/boston.c | 1 +
 1 file changed, 1 insertion(+)
hw/mips/boston.c +0 -0
index 5145179951..a40f193f78 100644
@@ -400,6 +400,7 @@ static const void *boston_fdt_filter(void *opaque, const void *fdt_orig,
Quoted 8 lines

hw/mips/boston.c static const void *boston_fdt_filter(void *opaque, const void *fdt_orig, · line 406

Quoted 6 lines
hw/mips/boston.c +0 -0
                         1, boston_memmap[BOSTON_HIGHDDR].base + ram_low_sz,
                         1, ram_high_sz);
 +    fdt_pack(fdt);
     fdt = g_realloc(fdt, fdt_totalsize(fdt));
     qemu_fdt_dumpdtb(fdt, fdt_sz);
 

Why not pack by default in qemu_fdt_dumpdtb()?

qemu_fdt_dumpdtb() is explicitly a function for debugging purpose. Donno if it’s wise to hijack it.

Thanks.
---
Jiaxun Yang

#5 lore raw

Re: [PATCH 2/2] hw/mips/boston: Pack fdt in fdt filter

Quoted 25 lines · Jiaxun Yang
Quoted 16 lines

2022年8月16日 01:44,Philippe Mathieu-Daudé <[email protected]> 写道:

Quoted 11 lines · Jiaxun Yang

FDT can be awfully fat after series of modifications in fdt filter. Just pack it up before add to ram.

---
 hw/mips/boston.c | 1 +
 1 file changed, 1 insertion(+)
hw/mips/boston.c +0 -0
index 5145179951..a40f193f78 100644
@@ -400,6 +400,7 @@ static const void *boston_fdt_filter(void *opaque, const void *fdt_orig,
Quoted 8 lines

hw/mips/boston.c static const void *boston_fdt_filter(void *opaque, const void *fdt_orig, · line 406

Quoted 6 lines
hw/mips/boston.c +0 -0
                         1, boston_memmap[BOSTON_HIGHDDR].base + ram_low_sz,
                         1, ram_high_sz);
 +    fdt_pack(fdt);
     fdt = g_realloc(fdt, fdt_totalsize(fdt));
     qemu_fdt_dumpdtb(fdt, fdt_sz);
 

Why not pack by default in qemu_fdt_dumpdtb()?

Quoted 2 lines

qemu_fdt_dumpdtb() is explicitly a function for debugging purpose. Donno if it’s wise to hijack it.

Agreed. Having this modify the dtb sounds like a very bad idea.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson