[HOWTO] Using GRUB as bootloader (second stage after U-Boot)

Test and fix the Kernel 4.14 features

Moderators: mdrjr, odroid

[HOWTO] Using GRUB as bootloader (second stage after U-Boot)

Unread postby OverSun » Tue May 02, 2017 10:21 pm

I don't know about most of users, but I play with kernel a lot and changing kernels on Odroid is real pain in the back when using u-boot. The thing is too simple, every time I want to test a kernel I need to type a ton of stuff to backup the current kernel, roll a testing kernel, boot, reboot, etc. Also "make install" from a kernel source tree is not really compatible with the u-boot, and u-boot options are not really accessible convenient way from the command line.
So here is a way to make U-Boot call GRUB as its first stage and not the real kernel. And from GRUB already you can do whatever you want standard Linux way. Plus all its configs are really vendor updates compatible, meaning ubuntu updates targeted to grub and kernel initramfs can apply normally.

1. You would need these packages installed into your ubuntu:
- u-boot-tools (or uboot-mkimage for older ubuntu versions)
- grub-uboot
- unfortunately, you would need grub2.02-beta3 at least, which is available as package only starting from ubuntu 17.04. Or from sources.

2. Most recent (mainline) u-boot version
- git checkout git://git.denx.de/u-boot.git
- make odroid-xu3_defconfig
- make nconfig
- enable "API -> U-Boot API" in the configuration menus
- add "#define CONFIG_SYS_MMC_MAX_DEVICE 2" into include/configs/odroid_xu3.h to make the API compile
- compile, get the u-boot-dtb.bin, flash it to your card

3. grub-install /boot
this will install all the GRUB files into the /boot directory

4. create a simple grub.cfg file with an entry to boot, for example (note that I have /boot directory, because I don't use separate partition for boot files, and also UUID definitely is going to be different for you):
Code: Select all
menuentry 'Kernel' {
   devicetree /boot/exynos5422-odroidxu4.dtb
   initrd /boot/initrd.img-4.9.25
   linux /boot/vmlinuz-4.9.25 console=tty1 console=ttySAC2,115200n8 root=UUID=98a483cb-87cc-4ca7-9aea-c2f8cbc491d0 rootwait ro fsck.repair=yes smsc95xx.macaddr=00:1e:06:61:7a:39 governor=ondemand hdmi_tx_amp_lvl=31 hdmi_tx_lvl_ch0=3 hdmi_tx_lvl_ch1=3 hdmi_tx_lvl_ch2=3 hdmi_tx_emp_lvl=6 hdmi_clk_amp_lvl=31 hdmi_tx_res=0 HPD=true vout=hdmi panic=3 s5p_mfc.mem=16M
}


5. to make U-Boot call GRUB as the loader you need this to be bootcmd of U-Boot (My /boot is not a separate partition and I don't use fat32 partition to store kernels, my system is on first partition of the card and all ext4):
Code: Select all
ext4load mmc 0:1 0x43300000 /boot/grub/arm-uboot/core.img
bootm 0x43300000

that will load standard GRUB menu with the menuentry you provided. Even if the menuentry would be wrong - it's much easier to work with kernels and parameters from the GRUB menu and editor

Tips and tricks.

To make grub-mkconfig work successfully you would need:
add your default kernel parameters to GRUB_CMDLINE_LINUX="", so all the stuff like "console=, blah-blah-blah..." is always added to every kernel line
in the file /etc/grub.d/10_linux two things are needed,
add "echo ' devicetree /boot/exynos5422-odroidxu4.dtb'" right before "if test -d /sys/firmware/efi && test -e "${linux}.efi.signed"; then", so devicetree entry is always added into every kernel menuentry
remove everything related to "recordfail". GRUB called from u-boot can access mmc read only and doesn't work with saving options.
After these changes grub-mkconfig can generate grub.cfg files absolutely standard way it does on normal ubuntu system

Reboot doesn't work. =(
For some reason first stage GRUB called from u-boot after a reboot cannot find mmc to call second stage. I'm not really sure whose fail this is - u-boot, GRUB or linux itself, but this major issue basically renders all that idea a good proof of concept thing that is not really ready to be used live.
Last edited by OverSun on Sat May 20, 2017 12:29 am, edited 1 time in total.
User avatar
OverSun
 
Posts: 1377
Joined: Mon Apr 29, 2013 5:12 pm
languages_spoken: english

Re: [HOWTO] Using GRUB as bootloader (second stage after U-B

Unread postby mad_ady » Wed May 03, 2017 2:39 am

Wow, when it works boot.ini will be a thing of the past...
User avatar
mad_ady
 
Posts: 4593
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [HOWTO] Using GRUB as bootloader (second stage after U-B

Unread postby rooted » Wed May 03, 2017 8:24 pm

This is the way it should work, I will get into this soon. Thanks OverSun :)

Is the eMMC driver built into the kernel? I don't think it's a module.

I would also try the direct location to your menu entry (/dev/mmbblk0p2), just an idea.
User avatar
rooted
 
Posts: 5602
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english
ODROIDs: C1, C1+, C2
XU3 Lite, XU4
N1
VU7+
HiFi Shield 2
Smart Power (original)

Re: [HOWTO] Using GRUB as bootloader (second stage after U-B

Unread postby phaseshifter » Wed May 03, 2017 8:42 pm

i am definitely a noob at this can you put the code down so a noob could follow..sorry coding is not my forte..i can follow some of your grub bootloader...some i dont ..i dont want to break the flash i have all ready
phaseshifter
 
Posts: 2934
Joined: Fri May 08, 2015 9:12 am
languages_spoken: english
ODROIDs: N-1..c1+ ..c-2..xu3 lite,xu4...u-3..
u-2...other odroid acc`s as well

Re: [HOWTO] Using GRUB as bootloader (second stage after U-B

Unread postby OverSun » Wed May 03, 2017 8:45 pm

Nah, that's a first stage GRUB failure.
Related to the thing that first stage doesn't see partitions.
So the scheme is this - GRUB has two stages, the first one is absolutely simple as a stick - it has only one ability - find a disk with the second stage and load it into extended memory. The first stage is that core.img u-boot loads.
What's happening is that after the reboot u-boot initialises mmc the way, this first stage can't find partitions on the card. I honestly think that this is some reset procedure not triggered right for the mmc storage driver of -XU4 in the new u-boot. I saw discussion or commits exactly about that "mmc right reset sequence", but where?..
So what's happening is that during normal boot u-boot loads from the mmcblk0boot0 partition, loads core.img from mmcblk0p1 and then core.img (which is almost GRUB already) finds (hd0,1) disk and all the files and modules for real grub on it, loads them and shows the menu.
After the reset u-boot loads, it loads core.img successfully, but then this core.img sees only (hd0) and no partitions on it, so it cannot find the GRUB second stage.

This could be either u-boot mmc driver reset sequence flaw (I suspect most) specific for -XU4, core.img (GRUB first stage flaw) generic for ARM's, or Linux weird flaw that does something to the card during reboot and doesn't release it successfully...
Also this happens not 100% of time, it's 50/50, sometimes it boots after reset, sometimes not.
Well, I'm not looking deeply into that right now, for me it's ok like this. It doesn't bother me to unplug/plug the board since I'm experimenting anyway. But the grub is waaaaay more easier as the system than u-boot to tinker with.
User avatar
OverSun
 
Posts: 1377
Joined: Mon Apr 29, 2013 5:12 pm
languages_spoken: english

Re: [HOWTO] Using GRUB as bootloader (second stage after U-B

Unread postby OverSun » Wed May 03, 2017 8:46 pm

phaseshifter wrote:i am definitely a noob at this can you put the code down so a noob could follow..sorry coding is not my forte..i can follow some of your grub bootloader...some i dont ..i dont want to break the flash i have all ready


I wouldn't advise you to try that if you don't know what you're doing. Just wait when it's stable and rolled out by vendor if they decide to go that way.
The process itself right now is pretty complicated to setup and has a flaw that doesn't make it useful 100%.
User avatar
OverSun
 
Posts: 1377
Joined: Mon Apr 29, 2013 5:12 pm
languages_spoken: english

Re: [HOWTO] Using GRUB as bootloader (second stage after U-B

Unread postby rooted » Thu May 04, 2017 8:12 am

Find out what happens from uboot when "reset" is issued, this triggers a full 'hard' boot in my testing.
User avatar
rooted
 
Posts: 5602
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english
ODROIDs: C1, C1+, C2
XU3 Lite, XU4
N1
VU7+
HiFi Shield 2
Smart Power (original)

Re: [HOWTO] Using GRUB as bootloader (second stage after U-B

Unread postby back2future » Sun Jul 23, 2017 10:04 pm

Kernel 3.10.x for xu4 supports cpu's in hyp mode.
( Compiling U-Boot and Grub works, but from my side, qemu related testing this setup is useless, with -cpu and -machine provided by qemu, so far.
One previous problem was having first partition sector 1 at block 2048 instead of higher number and is now for example at 4096. )
U-Boot 2017.07 is running and grub-2.02~beta3 is available on serial console 115200,8,1.
Can't recommend following u-boot config for boot.scr
setenv panel HDMI
setenv stdout serial,vga
setenv stderr serial,vga
, but may it's useful for someone else here.

OverSun wrote:For some reason first stage GRUB called from u-boot after a reboot cannot find mmc to call second stage.

Maybe there is a chance in editing .../grub/arm-uboot/load.cfg, line1: search.fs_uuid?



Next, Kernel 4.9.x.

Thanks for your advice.
naturally beYOnd spectrum
back2future
 
Posts: 96
Joined: Sun Jul 23, 2017 3:19 pm
languages_spoken: english

Re: [HOWTO] Using GRUB as bootloader (second stage after U-B

Unread postby tc424 » Wed Aug 29, 2018 2:11 am

OverSun wrote:[..] After the reset u-boot loads, it loads core.img successfully, but then this core.img sees only (hd0) and no partitions on it, so it cannot find the GRUB second stage.

This could be either u-boot mmc driver reset sequence flaw (I suspect most) specific for -XU4, core.img (GRUB first stage flaw) generic for ARM's, or Linux weird flaw that does something to the card during reboot and doesn't release it successfully...

Strangely, I've seen something similar with the USB connected on-board devices on the HC1 (NIC & SATA) - my root is on SATA connected SSD, and after anything but a clean reboot from a properly started normal ODROID kernel, there is a high likelihood of one or the other or both USB devices not coming up. After that a power cycle seems to be required, but I will try to the u-boot reset command next time.

I've sure I've seen recent mentions (commit log maybe?) of fixes to u-boot initialization code to address something like this, but can't remember where...

S.
tc424
 
Posts: 21
Joined: Sat Mar 03, 2018 10:26 pm
languages_spoken: english
ODROIDs: HC-1

Re: [HOWTO] Using GRUB as bootloader (second stage after U-B

Unread postby tjjh89017 » Mon Oct 08, 2018 4:27 am

I found this script for debian installer.
They use `grub-efi-arm` for boot after u-boot.
hardkernel u-boot (xu4-2017 branch) enable EFI loader by default.
Maybe this will be a way to boot kernel via EFI and follow the distro kernel to use.

https://github.com/tkiapril/debian-xu4/blob/master/mkimage.sh
tjjh89017
 
Posts: 1
Joined: Mon Oct 08, 2018 4:21 am
languages_spoken: Chinese
ODROIDs: XU4

Re: [HOWTO] Using GRUB as bootloader (second stage after U-B

Unread postby tc424 » Mon Oct 08, 2018 5:12 am

Thanks, that's interesting! Much as it's actually been quite nice not to have to deal with grub for once, I do probably need a more automated approach to kernel management.. so this is worth a look..
tc424
 
Posts: 21
Joined: Sat Mar 03, 2018 10:26 pm
languages_spoken: english
ODROIDs: HC-1


Return to Linux Kernel 4.14 Debugging Party

Who is online

Users browsing this forum: No registered users and 1 guest