[U-Boot] U-Boot as a multiboot GRUB2 payload

Dan Walkes danwalkes at trellis-logic.com
Sun Nov 26 19:45:34 UTC 2017


Hi,

I'm working on a project to integrate a mender [1], a framework for
embedded device update, on an Intel x86 platform using Legacy BIOS.
Mender makes use of u-boot environment configuration variables in
order to select which kernel/rootfs to use in a dual-boot A/B rootfs
scenario.

One of the thoughts I had about implementing this was to boot to grub
first, then use multiboot grub capability to load u-boot as a payload.
I noticed a patch [2] adding support for this through a multiboot
header, so I assume this has been done successfully before.

I thought I'd use qemu to prove this as a first step.

If I make qemu-x86_defconfig and then try to load with grub using this config:

---
set timeout=15
set default=0 # Set the default menu entry
set GRUB_GFXMODE=1024x768x32
set GRUB_GFXPAYLOAD_LINUX=keep

menuentry "u-boot" {
   multiboot /boot/u-boot
   boot
}
---

and a grub install to setup like below:
---
qemu-img create -f raw grub-uboot.img 50M
losetup /dev/loop0 grub-uboot.img
losetup /dev/loop1 grub-uboot.img -o 1048576
mke2fs /dev/loop1
mount /dev/loop1 /mnt
grub-install --root-directory=/mnt --no-floppy --modules="normal
part_msdos ext2 multiboot" /dev/loop0
---

Starting from qemu with:
---
qemu-system-i386 -s -curses -drive file=grub-uboot.img,format=raw
---

I get an error from grub:
---
  error: address is out of range.
  error: you need to load the kernel first.
---
Which I suspect is because grub doesn't like the  CONFIG_SYS_TEXT_BASE
default definition of 0xfff00000.

I've noticed that if I attempt to boot the coreboot payload from make
coreboot-x86_defconfig I get as far as failing to parse coreboot
tables in arch_cpu_init [3].  I looked through the config for coreboot
and noticed it uses a CONFIG_SYS_TEXT_BASE  at 0x1110000.  When I try
this with the qemu-x86_defconfig (plus a change to embed the dtb with
CONFIG_OF_EMBED and remove the reset vector with X86_RESET_VECTOR=n) I
see a crash during early initialization, right after configuration the
Cache As Ram addresses.  Looking at differences between configs I see
coreboot uses SYS_CAR_ADDR at 0x01920000 and  SYS_CAR_SIZE at 0x4000.

When I use the coreboot settings for SYS_CAR_ADDR and SYS_CAR_SIZE on
the qemu build I get a crash somewhere after dram_init, haven't found
where this is exactly yet.  My suspicion is that there are memory map
assumptions I don't understand in the qemu build and I need a
different load address/car address to avoid stomping on stack and text
during dram init and need to merge this with memory map restrictions
from grub2 which I also don't yet understand.

I'm wondering if someone on the mailing list could shed some light on
whether loading U-Boot as a multiboot grub2 payload from Legacy BIOS
could work and, if so, any pointers about how I could get a qemu demo
up and running.

Thanks very much for any suggestions you can provide.
Dan

[1] https://mender.io/
[2] https://lists.denx.de/pipermail/u-boot/2011-November/108932.html
[3] https://github.com/u-boot/u-boot/blob/master/arch/x86/cpu/coreboot/coreboot.c#L23


More information about the U-Boot mailing list