Grub on BPI-R2: kernel starting problem

Hi everyone.

Just wondering if anyone has tried to run OS using GRUB, and if it was successfull?

For now i’ve installed grub (u-boot 2020-01-bpi-r2 from Frank’s repo), i’m able to run it, but i can’t load linux kernel ftom grub.

u-boot env for grub run:

...
boot19=load mmc 0:1 ${loadaddr} /grub/arm-uboot/core.img; bootm ${loadaddr}
...
bootmenu_4=5. Run GRUB.=run boot19 
...

Grub Menu:

GNU GRUB  version 2.05_alpha20200110                                                                                                                                                                                          
                                                                                                                                                                                                                                                   
+----------------------------------------------------------------------------+                                                                                                                                                                     
|*Gentoo GNU/Linux                                                           |                                                                                                                                                                     
| Advanced options for Gentoo GNU/Linux                                      |                                                                                                                                                                     
|                                                                            |                                                                                                                                                                     
|                                                                            |                                                                                                                                                                     
|                                                                            |                                                                                                                                                                     
|                                                                            |                                                                                                                                                                     
|                                                                            |                                                                                                                                                                     
|                                                                            |                                                                                                                                                                     
|                                                                            |                                                                                                                                                                     
|                                                                            |                                                                                                                                                                     
|                                                                            |                                                                                                                                                                     
|                                                                            |                                                                                                                                                                     
+----------------------------------------------------------------------------+                                                                                                                                                                     
                                                                                                                                                                                                                                                   
     Use the ^ and v keys to select which entry is highlighted.                                                                                                                                                                                    
     Press enter to boot the selected OS, `e' to edit the commands                                                                                                                                                                                 
     before booting or `c' for a command-line.

cgub.cfg:

menuentry 'Gentoo GNU/Linux' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-4d920cff-b900-40c2-90c8-ffc716a6656f' {
        load_video
        insmod gzio
        insmod part_msdos
        insmod fat
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root  4449-36D1
        else
          search --no-floppy --fs-uuid --set=root 4449-36D1
        fi
        echo    'Loading Linux 5.5.0-rc1-arm+ ...'
        devicetree /bpi-r2.dts
        linux   /vmlinuz-5.5.0-rc1-arm+ root=UUID=4d920cff-b900-40c2-90c8-ffc716a6656f ro root=/dev/sdb1 rootfstype=ext4 rootwait console=earlyprintk console=tty1 fbcon=map:0 console=ttyS0,115200 
        echo    'Loading initial ramdisk ...'
        initrd  /initramfs-5.5.0-rc1-arm+.img
}

root=UUID=4d920cff-b900-40c2-90c8-ffc716a6656f ro root=/dev/sdb1 - are the same drive

/etc/default/grub:

GRUB_DISTRIBUTOR="Gentoo"

GRUB_TERMINAL="console serial"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"

GRUB_DEFAULT=0

GRUB_TIMEOUT=5

GRUB_CMDLINE_LINUX="root=/dev/sdb1 rootfstype=ext4 rootwait console=earlyprintk console=tty1 fbcon=map:0 console=ttyS0,115200"

Kernel is my 5.5-merged-lima branch based on Frank’s 5.5-merged. It runs w/o any problebs when built by build.sh script for u-boot.

After attempt to boot it prints Loading Linux 5.5.0-rc1-arm+ ... halts for 3-5 secs and resets.

P.S. Looks like uboot has some type of watchdog and restart board after some period of inactivity, if it’s really u-boot, where can i edit timeouts?

uboot has watchdog timeout, but it is ~20 sec of inactivity and shows message before do the reset…

have not tried using grub because one bootloader is enough for me :wink: what do you want to archive with it?

More familiar environment for me, no u-boot image ‘magic’,no uboot env - easy to update kernel, easy to use initramfs(useful for mdadm, zfs, dmraid, etc), new experience :wink:

Where can I disable it or edit timeout? Not very convinient when r2 reboots during reading manuals :slight_smile:.

I didn’t catched the message.

maybe by disabling the watchdog-driver…imho timeout cannot be increased

if not maybe you can start timer again if it is timed-out

1 Like

It is hardware timer. You should put grup to update watchdog timer regular interval. I don’t know how but I guess that broblem is solved in grub somehow.

1 Like

Fixed!

The problem was in wrong grub loading address.

Works great with:

load mmc 0:1 0x88000000 /grub/arm-uboot/core.img; bootm 0x88000000

Kernel loads, and works great:

Loading Devicetree ...                                                                                                                                                                                                                                  
Loading Linux 5.5.0-rc1-arm+ ...                                                                                                                                                                                                                    
Loading initial ramdisk ...                                                                                                                                                                                                                         
Done, starting ...                                                                                                                                                                                                                                      
[    0.000000] Booting Linux on physical CPU 0x0                                                                                                                                                                                                    
[    0.000000] Linux version 5.5.0-rc1-arm+ (root@bpi-r2-gentoo) (gcc version 9.2.0 (Gentoo 9.2.0-r2 p3)) #1 SMP Wed Jan 29 23:02:39 PST 2020                                                                                                       
[    0.000000] CPU: ARMv7 Processor [410fc073] revision 3 (ARMv7), cr=10c5387d                                                                                                                                                                      
[    0.000000] CPU: div instructions available: patching division code                                                                                                                                                                              
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache                                                                                                                                                             
[    0.000000] OF: fdt: Machine model: Bananapi BPI-R2                                                                                                                                                                                              
[    0.000000] Memory policy: Data cache writealloc                                                                                                                                                                                                 
[    0.000000] [WMT-CONSYS-HW][W]reserve_memory_consys_fn: name: consys-reserve-memory, base: 0xffe00000, size: 0x100000                                                                                                                            
[    0.000000] OF: reserved mem: initialized node consys-reserve-memory, compatible id mediatek,consys-reserve-memory                                                                                                                               
[    0.000000] cma: Reserved 64 MiB at 0xfb800000

Menuenty for my boot:

    menuentry 'Gentoo GNU/Linux, with Linux 5.5.0-rc1-arm+' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.5.0-rc1-arm+-advanced-4d920cff-b900-40c2-90c8-ffc716a6656f' {
            load_video
            insmod gzio
            insmod part_msdos
            insmod fat
            if [ x$feature_platform_search_hint = xy ]; then
              search --no-floppy --fs-uuid --set=root  4449-36D1
            else
              search --no-floppy --fs-uuid --set=root 4449-36D1
            fi
            echo  'Loading Devicetree ...'
            devicetree /bpi-r2.dtb
            echo    'Loading Linux 5.5.0-rc1-arm+ ...'
            linux   /vmlinuz-5.5.0-rc1-arm+ root=UUID=4d920cff-b900-40c2-90c8-ffc716a6656f ro root=/dev/sdb1 rootfstype=ext4 rootwait console=earlyprintk console=tty1 fbcon=map:0 console=ttyS0,115200 
            echo    'Loading initial ramdisk ...'
            initrd  /initramfs-5.5.0-rc1-arm+.img
            echo  'Done, starting ...'
    }

P.S. grub is installed to /boot using:

bpi-r2-gentoo ~ # grub-install /boot
Installing for arm-uboot platform.
grub-install: warning: no hints available for your platform. Expect reduced performance.
grub-install: warning: WARNING: no platform-specific install was performed.
Installation finished. No error reported.

P.P.S. My personal benefits using GRUB is to update, install and/or use multiple kernels without modifying u-boot env. :sunglasses:

Small HOWTO:

  • build u-boot (i use Frank’s 2020-01-bpi-r2)

Grub requires u-boot with enabled U-Boot API (enabled from menuconfig)

and

diff --git a/include/configs/mt7623.h b/include/configs/mt7623.h
index e5182aeea8..50c3fc66b0 100644
--- a/include/configs/mt7623.h
+++ b/include/configs/mt7623.h
@@ -15,6 +15,10 @@
 #define CONFIG_SETUP_MEMORY_TAGS
 #define CONFIG_INITRD_TAG
 #define CONFIG_CMDLINE_TAG
+#define CONFIG_SYS_MMC_MAX_DEVICE      2
+#define CONFIG_SYS_SCSI_MAX_DEVICE     2
+#define CONFIG_CMD_EXT2
+#define CONFIG_CMD_ECHO
   
 #define CONFIG_SYS_MAXARGS             8
 #define CONFIG_SYS_BOOTM_LEN           SZ_64M

(define CONFIG_SYS_MMC_MAX_DEVICE 2 is likely not needed)

  • Install grub

First install grub-uboot package (in gentoo: emerge -av grub with GRUB_PLATFORMS="uboot" defined )

2nd - install grub to /boot: grub-install /boot

  • Modify /etc/default/grub (to enable serial console and add kernel boot barameters):

/etc/default/grub:

GRUB_TERMINAL="console serial"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
...
GRUB_CMDLINE_LINUX="root=/dev/sdb1 rootfstype=ext4 rootwait console=earlyprintk console=tty1 fbcon=map:0 console=ttyS0,115200"
  • Create and modify grub config (/boot/grub/grub.cfg)

create:

grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.5.0-rc1-arm+
Found initrd image: /boot/initramfs-5.5.0-rc1-arm+.img
Found linux image: /boot/kernel-5.5.0-bananapi
Found linux image: /boot/kernel-5.4.0-bananapi
done

in my case it detects kernels and initramfs files placed in /boot

modify /boot/grub/grub.cfg: in my case i had to add devicetree /bpi-r2.dtb to each menuentry, and some verbose messages, but as i know there is a way to automate it by editing grub templates.

And the last…

  • modify uboot env to boot grub

I’ve changed 1 of boot entry envs to:

boot19=load mmc 0:1 0x88000000 /grub/arm-uboot/core.img; bootm 0x88000000
...
bootmenu_4=5. Run GRUB.=run boot19
2 Likes