Odroid-C2 u-boot and GRUB with EFI

Post Reply
AdrianB
Posts: 18
Joined: Thu Aug 31, 2017 5:03 am
languages_spoken: english
ODROIDs: C2
XU4
Has thanked: 4 times
Been thanked: 2 times
Contact:

Odroid-C2 u-boot and GRUB with EFI

Post by AdrianB »

Hi all,

I'm trying to use GRUB as bootloader for my Odroid-C2 and also for my XU4.
I started to build this system from an original Armbian image.
My system is running u-boot 2021.04.
After I added the EFI partition with 512MB and installed grub-efi-arm64, I started to test if is working or not.
If I'm installing the GRUB using grub-install and --removable options it will add into the EFI partition efi/boot/bootaa64.efi. This is fine to boot the new system via GRUB with removable EFI.
The system is booting without issue and it says that is in EFI mode.

Code: Select all

Loading DTB for Odroid-C2 ...                                                                                                                   
Loading Linux 5.11.4-meson64 ...                                                                                                                
Loading initial ramdisk ...                                                                                                                     
EFI stub: Booting Linux Kernel...                                                                                                               
EFI stub: Using DTB from configuration table                                                                                                    
EFI stub: Exiting boot services and installing virtual address map...                                                                           
[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]                                                                          
[    0.000000] Linux version 5.11.4-meson64 (root@hirsute) (aarch64-linux-gnu-gcc (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (ar1
[    0.000000] Machine model: Hardkernel ODROID-C2                                                                                              
[    0.000000] efi: EFI v2.80 by Das U-Boot                                                                                                     
[    0.000000] efi: RTPROP=0x7af41040 SMBIOS=0x7af3d000 RNG=0x7ad8f040 MEMRESERVE=0x5894d040                                                    
[    0.000000] efi: seeding entropy pool                                                                                                        
[    0.000000] random: fast init done                                                                                                           
[    0.000000] Reserved memory: created CMA memory pool at 0x000000006ac00000, size 256 MiB                                                     
[    0.000000] OF: reserved mem: initialized node linux,cma, compatible id shared-dma-pool                                                      
[    0.000000] NUMA: No NUMA configuration found                                                                                                
[    0.000000] NUMA: Faking a node at [mem 0x0000000000000000-0x000000007fffffff]                                                               
[    0.000000] NUMA: NODE_DATA [mem 0x7fa31100-0x7fa32fff]                                                                                      
[    0.000000] Zone ranges:
 
And the efivar partition is mounted correctly:

Code: Select all

# ls /sys/firmware/efi/efivars/
AuditMode-8be4df61-93ca-11d2-aa0d-00e098032b8c               PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c
DeployedMode-8be4df61-93ca-11d2-aa0d-00e098032b8c            SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c
OsIndicationsSupported-8be4df61-93ca-11d2-aa0d-00e098032b8c  SetupMode-8be4df61-93ca-11d2-aa0d-00e098032b8c
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c            VendorKeys-8be4df61-93ca-11d2-aa0d-00e098032b8c
But when I'm trying to create a new Boot entry I'm getting this error:

Code: Select all

# efibootmgr -c -d /dev/mmcblk0p2 -l "\efi\debian\grubaa64.efi" -L "Debian GNU\Linux"
Could not prepare Boot variable: Read-only file system
Trying to mount the partition as RW and try to recreate it I got a kernel oops:

Code: Select all

# mount | grep efivars
efivarfs on /sys/firmware/efi/efivars type efivarfs (rw,nosuid,nodev,noexec,relatime)
root@odroidc2:/home/adrian# efibootmgr -c -d /dev/mmcblk0p2 -l "\efi\debian\grubaa64.efi" -L "Debian GNU\Linux"

Message from syslogd@odroidc2 at Jun 22 21:47:59 ...
 kernel:[10447.895898] Internal error: Oops: 86000004 [#1] PREEMPT SMP

Message from syslogd@odroidc2 at Jun 22 21:47:59 ...
 kernel:[10448.115019] Code: bad PC value
Segmentation fault
This is from Serial port output:

Code: Select all

[10447.862424] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000                             
[10447.865680] Mem abort info:                                                                                                                  
[10447.868407]   ESR = 0x86000004                                                                                                               
[10447.871410]   EC = 0x21: IABT (current EL), IL = 32 bits                                                                                     
[10447.876667]   SET = 0, FnV = 0                                                                                                               
[10447.879680]   EA = 0, S1PTW = 0                                                                                                              
[10447.882788] user pgtable: 4k pages, 48-bit VAs, pgdp=0000000003ffa000                                                                        
[10447.889167] [0000000000000000] pgd=0000000000000000, p4d=0000000000000000
[10447.895898] Internal error: Oops: 86000004 [#1] PREEMPT SMP
[10447.901376] Modules linked in: rfkill cpufreq_powersave cpufreq_conservative zram nls_iso8859_1 snd_soc_hdmi_codec dw_hdmi_i2s_audio meson_vb
[10447.963907] CPU: 2 PID: 2911 Comm: efibootmgr Tainted: G         C        5.11.4-meson64 #21.02.3
[10447.972702] Hardware name: Hardkernel Co., Ltd. ODROID-C2/ODROID-C2, BIOS 2021.04-armbian 06/16/2021
[10447.981759] pstate: 00000005 (nzcv daif -PAN -UAO -TCO BTYPE=--)
[10447.987708] pc : 0x0
[10447.989865] lr : efivar_entry_set_get_size+0xd4/0x1e0
[10447.994867] sp : ffff800012afbcd0
[10447.998145] x29: ffff800012afbcd0 x28: ffff000003645d00 
[10448.003406] x27: 0000000000000007 x26: ffff800012afbd7b 
[10448.008667] x25: 000000000000008c x24: ffff000003c06400 
[10448.013929] x23: ffff80001189b8c0 x22: 0000000000000000 
[10448.019190] x21: ffff800012afbd80 x20: ffff000003c06000 
[10448.024451] x19: ffff8000117ad7d0 x18: 0000000000000000 
[10448.029712] x17: 0000000000000000 x16: 0000000000000000 
[10448.034974] x15: 0000000000000000 x14: 0004ff7f00000069 
[10448.040235] x13: 00660065002e0034 x12: 0036006100610062 
[10448.045496] x11: 0000000000000009 x10: ffff000003615780 
[10448.050757] x9 : ffff800010f53748 x8 : ffff800010f53788 
[10448.056019] x7 : 0000000000000060 x6 : 0000000000000000 
[10448.061280] x5 : 0000000000000000 x4 : ffff000003645d00 
[10448.066541] x3 : 000000000000008c x2 : 0000000000000007 
[10448.071802] x1 : ffff000003c06400 x0 : ffff000003c06000 
[10448.077065] Call trace:
[10448.079482]  0x0
[10448.081290]  efivarfs_file_write+0x130/0x1c8 [efivarfs]
[10448.086465]  vfs_write+0xbc/0x390
[10448.089743]  ksys_write+0x68/0xf0
[10448.093020]  __arm64_sys_write+0x1c/0x28
[10448.096901]  el0_svc_common.constprop.3+0x98/0x188
[10448.101645]  do_el0_svc+0x24/0x90
[10448.104922]  el0_svc+0x14/0x20
[10448.107941]  el0_sync_handler+0x90/0xb8
[10448.111737]  el0_sync+0x158/0x180
[10448.115019] Code: bad PC value
[10448.118035] ---[ end trace 2771c863cf112966 ]---
Then I started to look deeper in u-boot code and I notice that it has the support to load and save persistent EFI variables to the disk. I couldn't find anything regarding this in u-boot manual or over internet. This is only what I've notice.

Code: Select all

# grep EFI_VARIABLE_FILE_STORE /usr/lib/u-boot/odroid-c2_defconfig 
CONFIG_EFI_VARIABLE_FILE_STORE=y
So seems that we have support for EFI variables to be stored. Looking in the Kconfig:

Code: Select all

choice
        prompt "Store for non-volatile UEFI variables"
        default EFI_VARIABLE_FILE_STORE
        help
          Select where non-volatile UEFI variables shall be stored.

config EFI_VARIABLE_FILE_STORE
        bool "Store non-volatile UEFI variables as file"
        depends on FAT_WRITE
        help
          Select this option if you want non-volatile UEFI variables to be
          stored as file /ubootefi.var on the EFI system partition.

Seems that the stored file for EFI variables is /ubootefi.var, on EFI partition.
Rebooting the system I notice this:

Code: Select all

U-Boot 2021.04-armbian (Jun 16 2021 - 08:10:59 +0000) odroid-c2                                                                                 

Model: Hardkernel ODROID-C2                                                                                                                     
SoC:   Amlogic Meson GXBB (S905) Revision 1f:c (0:1)                                                                                            
DRAM:  2 GiB                                                                                                                                    
MMC:   mmc@72000: 0, mmc@74000: 1                                                                                                               
In:    serial                                                                                                                                   
Out:   serial                                                                                                                                   
Err:   serial                                                                                                                                   
Net:   eth0: ethernet@c9410000                                                                                                                  
Hit any key to stop autoboot:  0                                                                                                                
switch to partitions #0, OK                                                                                                                     
mmc0 is current device                                                                                                                          
Scanning mmc 0:2...                                                                                                                             
libfdt fdt_check_header(): FDT_ERR_BADMAGIC                                                                                                     
Scanning disk mmc@72000.blk...                                                                                                                  
Card did not respond to voltage select! : -110                                                                                                  
Scanning disk mmc@74000.blk...                                                                                                                  
Disk mmc@74000.blk not ready                                                                                                                    
Found 3 disks                                                                                                                                   
** Unable to read file ubootefi.var **                                                                                                          
Failed to load EFI variables                                                                                                                    
BootOrder not defined                                                                                                                           
EFI boot manager: Cannot load any image                                                                                                         
Card did not respond to voltage select! : -110                                                                                                  
MMC Device 2 not found                                                                                                                          
Creating a file on EFI partition named ubootefi.var "fixed" this message:

Code: Select all

# touch /boot/efi/ubootefi.var
 ls -l /boot/efi/
total 4
drwxr-xr-x 4 root root 4096 Jun 22 14:28 EFI
-rwxr-xr-x 1 root root    0 Jun 22 22:03 ubootefi.var
Then u-boot:

Code: Select all

U-Boot 2021.04-armbian (Jun 16 2021 - 08:10:59 +0000) odroid-c2                                                                                 

Model: Hardkernel ODROID-C2                                                                                                                     
SoC:   Amlogic Meson GXBB (S905) Revision 1f:c (0:1)                                                                                            
DRAM:  2 GiB                                                                                                                                    
MMC:   mmc@72000: 0, mmc@74000: 1                                                                                                               
In:    serial                                                                                                                                   
Out:   serial                                                                                                                                   
Err:   serial                                                                                                                                   
Net:   eth0: ethernet@c9410000                                                                                                                  
Hit any key to stop autoboot:  0                                                                                                                
switch to partitions #0, OK                                                                                                                     
mmc0 is current device                                                                                                                          
Scanning mmc 0:2...                                                                                                                             
libfdt fdt_check_header(): FDT_ERR_BADMAGIC                                                                                                     
Scanning disk mmc@72000.blk...                                                                                                                  
Card did not respond to voltage select! : -110                                                                                                  
Scanning disk mmc@74000.blk...                                                                                                                  
Disk mmc@74000.blk not ready                                                                                                                    
Found 3 disks                                                                                                                                   
Failed to load EFI variables                                                                                                                    
BootOrder not defined                                                                                                                           
EFI boot manager: Cannot load any image                                                                                                         
Card did not respond to voltage select! : -110                                                                                                  
MMC Device 2 not found                                                                                                                          
no mmc device at slot 2                                                                                                                         
starting USB...                                                                                                                                 
Bus usb@c9100000: USB DWC2                                                                                                                      
Seems that u-boot is sees the new created file, but still is invalid. I can't find anything about how to "format" this file to be read by u-boot.
I tried again to create a Boot entry in EFI same result: oops in Kernel.

I don't know if is a bug in u-boot which is denying to write/read variables from this file or I'm missing something.
The problem with --removable is when a new GRUB version is coming in the OS upgrade I have to do it manually each time and of course chances to forget are very high and then you can't boot the system anymore.
Another aproch is to change boot.scr script to search the EFI boot loader for grubaa64.efi under "debian" folder in EFI partition, but first I want to ask you if you know a fix or a workaround for this issue with u-boot EFI and ubootefi.var file.
These users thanked the author AdrianB for the post (total 2):
igorpec (Mon Jun 28, 2021 4:50 am) • odroid (Tue Jun 29, 2021 11:11 am)

AdrianB
Posts: 18
Joined: Thu Aug 31, 2017 5:03 am
languages_spoken: english
ODROIDs: C2
XU4
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Odroid-C2 u-boot and GRUB with EFI

Post by AdrianB »

Hi all,

For those who are interested in how to boot EFI GRUB for Odroid, I found the answer after 4 days of digging.
First of all I had to rebuild U-BOOT adding some additional options (using git clone https://github.com/u-boot/u-boot):

Code: Select all

CONFIG_CMD_BOOTEFI=y
CONFIG_CMD_BOOTEFI_HELLO_COMPILE=y
# CONFIG_CMD_BOOTEFI_HELLO is not set
CONFIG_CMD_BOOTEFI_SELFTEST=y
CONFIG_CMD_NVEDIT_EFI=y
CONFIG_CMD_EFIDEBUG=y
CONFIG_EFI_PARTITION=y
CONFIG_EFI_PARTITION_ENTRIES_NUMBERS=128
CONFIG_EFI_PARTITION_ENTRIES_OFF=0
CONFIG_EFI_LOADER=y
CONFIG_CMD_BOOTEFI_BOOTMGR=y
CONFIG_EFI_VARIABLE_FILE_STORE=y
# CONFIG_EFI_VARIABLES_PRESEED is not set
CONFIG_EFI_VAR_BUF_SIZE=16384
# CONFIG_EFI_RUNTIME_UPDATE_CAPSULE is not set
# CONFIG_EFI_CAPSULE_ON_DISK is not set
CONFIG_EFI_DEVICE_PATH_TO_TEXT=y
CONFIG_EFI_DEVICE_PATH_UTIL=y
CONFIG_EFI_DT_FIXUP=y
CONFIG_EFI_LOADER_HII=y
CONFIG_EFI_UNICODE_COLLATION_PROTOCOL2=y
CONFIG_EFI_UNICODE_CAPITALIZATION=y
# CONFIG_EFI_LOADER_BOUNCE_BUFFER is not set
CONFIG_EFI_PLATFORM_LANG_CODES="en-US"
CONFIG_EFI_HAVE_RUNTIME_RESET=y
CONFIG_EFI_RNG_PROTOCOL=y
CONFIG_EFI_LOAD_FILE2_INITRD=y
CONFIG_EFI_SECURE_BOOT=y
CONFIG_EFI_SIGNATURE_SUPPORT=y
The most important configs where: CONFIG_CMD_EFIDEBUG, CONFIG_CMD_EFIDEBUG, CONFIG_EFI_VARIABLE_FILE_STORE.
After compiling the U-BOOT I've created the bootloader using the Odroid C2 instructions:

1. From U-BOOT odroidc2-v2015.01 you will need these files:

Code: Select all

fip/gxb/bl30.bin
fip/gxb/bl301.bin
fip/gxb/bl31.bin
2. From new U-BOOT you will need only this file: u-boot.bin

To build the new U-BOOT follow these steps:

1. Create a directory in "/opt/' named "devel" and change to here:

Code: Select all

# mkdir /opt/devel/
# cd /opt/devel/
2. Clone the U-BOOT for Odroid C2:

Code: Select all

# git clone https://github.com/hardkernel/u-boot -b odroidc2-v2015.01 odroidc2-v2015.01
3. Clone the latest U-BOOT:

Code: Select all

# git clone https://github.com/u-boot/u-boot
4. Build the U-BOOT config for Odroid-C2 or just copy my config file in .config in u-boot:

## Build your own U-BOOT config

Code: Select all

# cd u-boot
# make odroid-c2_defconfig
# make menuconfig # you must have ncurses devel installed!
Go to Library routings and check if you have Support running UEFI applications, UEFI Boot Manager and Store for non-volatile UEFI variables (Store non-volatile UEFI variables as file) checked. You should have FAT enable as FS and FAT write.
Also I have EFI_RNG_PROTOCOL support, EFI_FILE_LOAD2_PROTOCOL for Linux initial ramdisk and Enable EFI secure boot support checked.
Then go to Command line interface -> Environment commands and check env [set|print] -e - set/print UEFI variables.
The also under Command line interface -> Misc commands and check efidebug - display/configure UEFI environment.

These options should be enough to build the EFI vars.

Or download my config file:
Odroid-C2-U-BOOT-EFI.txt
(35.98 KiB) Downloaded 6 times
And rename it as ".config" in U-BOOT folder.

5. Compile the new U-BOOT using:

Code: Select all

# make -j8
6. In the end of the compiling you should see the U-BOOT binary:

Code: Select all

# ls -l u-boot*
-rwxr-xr-x 1 root root 6588696 Jun 26 13:25 u-boot
-rw-r--r-- 1 root root  721934 Jun 26 13:25 u-boot.bin
-rw-r--r-- 1 root root   11510 Jun 26 13:23 u-boot.cfg
-rw-r--r-- 1 root root    7155 Jun 26 13:23 u-boot.cfg.configs
-rw-r--r-- 1 root root   38286 Jun 26 13:25 u-boot.dtb
-rw-r--r-- 1 root root  721934 Jun 26 13:25 u-boot-dtb.bin
-rwxr-xr-x 1 root root  788048 Jun 26 13:25 u-boot.elf
-rw-r--r-- 1 root root      70 Jun 26 13:23 u-boot-elf.lds
-rw-r--r-- 1 root root  722552 Jun 26 13:25 u-boot-elf.o
-rw-r--r-- 1 root root    1348 Jun 26 13:23 u-boot.lds
-rw-r--r-- 1 root root  995683 Jun 26 13:25 u-boot.map
-rwxr-xr-x 1 root root  683648 Jun 26 13:25 u-boot-nodtb.bin
-rwxr-xr-x 1 root root 2051058 Jun 26 13:25 u-boot.srec
-rw-r--r-- 1 root root  279635 Jun 26 13:25 u-boot.sym
#
8. Go back in /opt/devel/ folder:

Code: Select all

cd ..
7. Build "fip_create" tool from U-BOOT Odroid-C2 sources:

Code: Select all

# cd odroidc2-v2015.01/tools/fip_create/
Edit "Makefile" and add "HOSTCC = gcc" before "RM := rm -rf" line.

Code: Select all

# make
  HOSTCC      fip_create.c
gcc -c -Wall -Werror -pedantic -std=c99 -O2 -I. fip_create.c -o fip_create.o
  HOSTLD      fip_create
gcc fip_create.o -o fip_create
# ls -l
total 68
-rwxr-xr-x 1 root root 19104 Jun 26 13:36 fip_create
-rw-r--r-- 1 root root 18451 Jun 26 13:35 fip_create.c
-rw-r--r-- 1 root root  2197 Jun 26 13:35 fip_create.h
-rw-r--r-- 1 root root 12008 Jun 26 13:36 fip_create.o
-rw-r--r-- 1 root root  2783 Jun 26 13:35 firmware_image_package.h
-rw-r--r-- 1 root root  2134 Jun 26 13:36 Makefile
-rw-r--r-- 1 root root  2068 Jun 26 13:35 uuid.h
Then copy the new file to /usr/local/bin:

Code: Select all

# cp -v fip_create /usr/local/bin/
'fip_create' -> '/usr/local/bin/fip_create'
#
Return to /opt/devel/ folder:

Code: Select all

cd ../../../
8. Build meson-tools:

Code: Select all

# git clone https://github.com/afaerber/meson-tools
# cd meson-tools
# make -j8
Copy the amlbootsig to /usr/local/bin:

Code: Select all

# cp -v amlbootsig /usr/local/bin
'amlbootsig' -> '/usr/local/bin/amlbootsig'
Return back to /opt/devel/

Code: Select all

# cd ..
9. Build the new Odroid-C2 U-BOOT. I'm using a sequence of commands and I've added in a script named GXBB-build-U-Boot:

Code: Select all

#!/bin/bash

DIR=/opt/devel/
DIROC2=${DIR}/odroidc2-v2015.01
DIRUBOOT=${DIR}/u-boot

fip_create --bl30  $DIROC2/fip/gxb/bl30.bin \
                   --bl301 $DIROC2/fip/gxb/bl301.bin \
                   --bl31  $DIROC2/fip/gxb/bl31.bin \
                   --bl33  $DIRUBOOT/u-boot.bin \
                   ./fip.bin
fip_create --dump fip.bin
cat $DIROC2/fip/gxb/bl2.package fip.bin > boot_new.bin

amlbootsig ./boot_new.bin ./u-boot.img

dd if=u-boot.img of=u-boot.gxbb bs=512 skip=96
As you can see DIR is the /opt/devel/ main dir, DIROC2 is the folder containing the Odroid-C2 U-BOOT where we can find BL30, BL301 and BL31 (Boot Loaders that are needed for Amlogic S905 SOC to boot. I found this stage extreamly hard to understand few ears ago in the beginning when I got this device).
DIRUBOOT contains the directory where we can find our new U-BOOT binary.
Then fip_create is creating the new boot loader using the boot loaders 30, 301, 31 and the new u-boot.bin. Second fip_create is just to show you that the packages is build OK.
The "cat" not sure what is combining there. the "BL2.packages" and the new "fip.bin" image in a new boot file called boot_new.bin.
amlbootsig will sign the new boot image and the output is dumped to u-boot.img.
The "dd" command is extracting the image starting from 512*96 byte. The new file is called u-boot.gxbb and finally our new boot loader!

10. I've used another script to write the new boot loader to SD card called GXBB-write-U-boot:

Code: Select all

#!/bin/bash

DIROC2=/opt/devel/odroidc2-v2015.01

DEV=/dev/disk/by-id/mmc-SL16G_0x3642dce0
BL1=$DIROC2/sd_fuse/bl1.bin.hardkernel

dd if=$BL1 of=$DEV conv=fsync bs=1 count=442
dd if=$BL1 of=$DEV conv=fsync bs=512 skip=1 seek=1
dd if=./u-boot.gxbb of=$DEV conv=fsync bs=512 seek=97
ATTENTION!!! Change you "DEV" to the correct SD card or MMC driver in you ODROID!!

We will still need BL1 from sources of U-BOOT Odroid-C2.
First "dd" is writing only 442 bytes into MBR from BL1 binary file.
Second "dd" is writing the rest of the BL1 binary file from the sector 1 of the SD.
Thrid "dd" will write the the the U-BOOT.

This is it for writing the new U-BOOT!

11. As I mention in my first post, I created a new EFI partition and I set the ESP flag on it, mount the partition into /boot/efi/ folder and I've installed GRUB EFI ARM64:

Code: Select all

# dpkg -l | grep grub
ii  grub-common                     2.02+dfsg1-20+deb10u4               arm64        GRand Unified Bootloader (common files)
ii  grub-efi-arm64                  2.02+dfsg1-20+deb10u4               arm64        GRand Unified Bootloader, version 2 (ARM64 UEFI version)
ii  grub-efi-arm64-bin              2.02+dfsg1-20+deb10u4               arm64        GRand Unified Bootloader, version 2 (ARM64 UEFI modules)
ii  grub-efi-arm64-signed           1+2.02+dfsg1+20+deb10u4             arm64        GRand Unified Bootloader, version 2 (arm64 UEFI signed by Debian)
ii  grub2-common                    2.02+dfsg1-20+deb10u4               arm64        GRand Unified Bootloader (common files for version 2)
Then I've installed the GRUB using:

Code: Select all

# grub-install --target=arm64-efi
# update-grub
In this moment we should have:

Code: Select all

# ls -l /boot/efi/EFI/
total 4
drwxr-xr-x 2 root root 4096 Jun 22 10:56 debian
# ls -l /boot/grub/
total 2372
drwxr-xr-x 2 root root   12288 Jun 22 10:56 arm64-efi
drwxr-xr-x 2 root root    4096 Jun 22 10:56 fonts
-r--r--r-- 1 root root    7205 Jun 26 12:34 grub.cfg
-rw-r--r-- 1 root root    1024 Jun 22 10:56 grubenv
drwxr-xr-x 2 root root    4096 Jun 25 13:44 locale
-rw-r--r-- 1 root root 2396122 Jun 22 10:50 unicode.pf2
12. Then is time to reboot the system!
13. On serial port we will receive this:

Code: Select all

GXBB:BL1:08dafd:0a8993;FEAT:EDFC318C;POC:3;RCY:0;EMMC:800;NAND:81;SD:0;READ:0;CHK:0;                                                                            
TE: 273476                                                                                                                                                      
no sdio debug board detected                                                                                                                                    

BL2 Built : 11:44:26, Nov 25 2015.                                                                                                                              
gxb gfb13a3b-c2 - jcao@wonton                                                                                                                                   

Board ID = 8                                                                                                                                                    
set vcck to 1100 mv                                                                                                                                             
set vddee to 1050 mv                                                                                                                                            
CPU clk: 1536MHz                                                                                                                                                
DDR channel setting: DDR0 Rank0+1 same                                                                                                                          
DDR0: 2048MB(auto) @ 912MHz(2T)-13                                                                                                                              
DataBus test pass!                                                                                                                                              
AddrBus test pass!                                                                                                                                              
Load fip header from SD, src: 0x0000c200, des: 0x01400000, size: 0x000000b0                                                                                     
Load bl30 from SD, src: 0x00010200, des: 0x01000000, size: 0x00009ef0                                                                                           
Sending bl30........................................OK.                                                                                                         
Run bl30...                                                                                                                                                     
Load bl301 from SD, src: 0x0001c200, des: 0x01000000, size: 0x000018c0                                                                                          
Wait bl30...Done                                                                                                                                                
Sending bl301.......OK.                                                                                                                                         
Run bl301...                                                                                                                                                    
00, size: 0x00011130rc: 0x00020200, des: 0x10100                                                                                                                


--- UART initialized after reboot ---                                                                                                                           
[Reset cause: unknown]                                                                                                                                          
[Image: unknown, amlogic_v1.1.3046-00db630-dirty 2016-08-31 09:24:14 tao.zeng@droid04]                                                                          
bl30: check_permit, count is 1                                                                                                                                  
bl30: check_permit: ok!                                                                                                                                         
chipid: Load bl33 from SD, src: 0x00034200, des: 0x01000000, size: 0x000b0470                                                                                   
ef be ad de d f0 ad ba ef be ad de not ES chip                                                                                                                  
[0.388828 Inits done]                                                                                                                                           
secure task start!                                                                                                                                              
high task start!                                                                                                                                                
low task start!                                                                                                                                                 
NOTICE:  BL3-1: v1.0(debug):4d2e34d                                                                                                                             
NOTICE:  BL3-1: Built : 17:08:35, Oct 29 2015                                                                                                                   
INFO:    BL3-1: Initializing runtime services                                                                                                                   
INFO:    BL3-1: Preparing for EL3 exit to normal world                                                                                                          
INFO:    BL3-1: Next image address = 0x1000000                                                                                                                  
INFO:    BL3-1: Next image spsr = 0x3c9                                                                                                                         


U-Boot 2021.07-rc4-00169-g4d8c21da41 (Jun 26 2021 - 13:23:53 +0000) odroid-c2                                                                                   

Model: Hardkernel ODROID-C2                                                                                                                                     
SoC:   Amlogic Meson GXBB (S905) Revision 1f:c (0:1)                                                                                                            
DRAM:  2 GiB                                                                                                                                                    
MMC:   mmc@72000: 0, mmc@74000: 1                                                                                                                               
Loading Environment from nowhere... OK                                                                                                                          
In:    serial                                                                                                                                                   
Out:   serial                                                                                                                                                   
Err:   serial                                                                                                                                                   
Net:   eth0: ethernet@c9410000                                                                                                                                  
Hit any key to stop autoboot:  0                                                                                                                                
switch to partitions #0, OK                                                                                                                                     
mmc0 is current device                                                                                                                                          
Scanning mmc 0:2...                                                                                                                                             
libfdt fdt_check_header(): FDT_ERR_BADMAGIC                                                                                                                     
Scanning disk mmc@72000.blk...                                                                                                                                  
Card did not respond to voltage select! : -110                                                                                                                  
Scanning disk mmc@74000.blk...                                                                                                                                  
Disk mmc@74000.blk not ready                                                                                                                                    
Found 3 disks                                                                                                                                                   
** Unable to read file ubootefi.var **                                                                                                                          
Failed to load EFI variables                                                                                                                                    
BootOrder not defined                                                                                                                                           
EFI boot manager: Cannot load any image                                                                                                                         
Card did not respond to voltage select! : -110                                                                                                                  
MMC Device 2 not found                                                                                                                                          
no mmc device at slot 2                                                                                                                                         
starting USB...                                                                                                                                                 
Bus usb@c9100000: USB DWC2                                                                                                                                      
scanning bus usb@c9100000 for devices... 2 USB Device(s) found                                                                                                  
       scanning usb for storage devices... 0 Storage Device(s) found                                                                                            

Device 0: unknown device                                                                                                                                        
Speed: 1000, full duplex                                                                                                                                        
BOOTP broadcast 1                                                                                                                                               
BOOTP broadcast 2                                                                                                                                               
DHCP client bound to address 192.168.105.196 (420 ms)                                                                                                           
*** Warning: no boot file name; using 'C0A869C4.img'                                                                                                            
Using ethernet@c9410000 device                                                                                                                                  
TFTP from server 192.168.105.1; our IP address is 192.168.105.196                                                                                               
Filename 'C0A869C4.img'.                                                                                                                                        
Load address: 0x1000000                                                                                                                                         
Loading: T T T T T T T T T T                                                                                                                                    
Retry count exceeded; starting again                                                                                                                            
missing environment variable: pxeuuid                                                                                                                           
missing environment variable: bootfile                                                                                                                          
Retrieving file: pxelinux.cfg/01-00-1e-06-34-04-1a                                                                                                              
Speed: 1000, full duplex                                                                                                                                        
Using ethernet@c9410000 device                                                                                                                                  
TFTP from server 192.168.105.1; our IP address is 192.168.105.196                                                                                               
Filename 'pxelinux.cfg/01-00-1e-06-34-04-1a'.                                                                                                                   
Load address: 0x1080000                                                                                                                                         
Loading: T T T T T T T T T T                                                                                                                                    
Retry count exceeded; starting again                                                                                                                            
missing environment variable: bootfile                                                                                                                          
Retrieving file: pxelinux.cfg/C0A869C4                                                                                                                          
Speed: 1000, full duplex                                                                                                                                        
Using ethernet@c9410000 device                                                                                                                                  
TFTP from server 192.168.105.1; our IP address is 192.168.105.196                                                                                               
Filename 'pxelinux.cfg/C0A869C4'.                                                                                                                               
Load address: 0x1080000                                                                                                                                         
Loading: T T T T
Because we have a EFI partiotion and we don't have \EFI\BOOT\BOOTAA64.EFI, U-BOOT will try to boot from network. Press CTRL+C few times until you will be dropped in U-BOOT cli:

You should see this:

Code: Select all

Abort
Config file not found
=> <INTERRUPT>
=> <INTERRUPT>
=> 
14. Let test the EFI commands:

Code: Select all

=> efidebug 
efidebug - Configure UEFI environment

Usage:
efidebug   - UEFI Shell-like interface to configure UEFI environment

efidebug boot add -b <bootid> <label> <interface> <devnum>[:<part>] <file path> -i <interface> <devnum>[:<part>] <initrd file path> -s '<optional data>'
  - set UEFI BootXXXX variable
    <load options> will be passed to UEFI application
efidebug boot rm <bootid#1> [<bootid#2> [<bootid#3> [...]]]
  - delete UEFI BootXXXX variables
efidebug boot dump
  - dump all UEFI BootXXXX variables
efidebug boot next <bootid>
  - set UEFI BootNext variable
efidebug boot order [<bootid#1> [<bootid#2> [<bootid#3> [...]]]]
  - set/show UEFI boot order
Perfect! Now is time to build our new Boot0000 EFI variable and, for my supprise, it will be automatically stored on EFI partition under ubootefi.var file!

15. Create a new EFI Boot0000 Entry:

Code: Select all

=> efidebug boot add -b 0000 "Debian GNU/Linux" mmc 0:2 "\EFI\DEBIAN\GRUBAA64.EFI" -i mmc 0:2 "" -s ''
=>
You should not get any output, but if we check the with "efidebug boot dump":

Code: Select all

=> efidebug boot dump
Boot0000:
attributes: A-- (0x00000001)
  label: Debian GNU/Linux
  file_path: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(0)/SD(0)/HD(2,MBR,0x90160000,0x1cac800,0xb3800)/\EFI\DEBIAN\GRUBAA64.EFI
  initrd_path: /VenMedia(5568e427-68fc-4f3d-ac74-ca555231cc68)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(0)/SD(0)/HD(2,MBR,0x90160000,0x1cac800,0xb3800)/
  data:
 
Nice! We have a new EFI entry! Now, the last step, is to add BootOrder variable and mention here to boot the entry in Boot0000:

Code: Select all

=> efidebug boot order 0000
[code]

Same here, no output, but "efidebug boot order" will show us:

[code]
=> efidebug boot order
 1: Boot0000: Debian GNU/Linux
[code]

That's it! You also can check using "printenv -e" command and you will get:
[code]
Boot0000:
    8be4df61-93ca-11d2-aa0d-00e098032b8c EFI_GLOBAL_VARIABLE_GUID
    NV|BS|RT, DataSize = 0x112
BootOrder:
    8be4df61-93ca-11d2-aa0d-00e098032b8c EFI_GLOBAL_VARIABLE_GUID
    NV|BS|RT, DataSize = 0x2
Just reset your Odroid C2 and you will get the GRUB menu!
After booting the system you can check the /boot/efi director and you will see the ubootefi.var file!

Code: Select all

# ls -l /boot/efi/
total 8
drwxr-xr-x 3 root root 4096 Jun 26 13:57 EFI
-rwxr-xr-x 1 root root  472 Jan  1  1980 ubootefi.var
Hope this tutorial can help us to use U-BOOT EFI + GRUB EFI in the future. For me this approach is more like a "PC" booting.

One think: EFI vars can't be changed under Linux. I don't know what are the limitations, but even with this tutorial I couldn't use efibootmgr to change anything.

User avatar
mad_ady
Posts: 9540
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, C4, N1, N2, H2, Go, Go Advance
Location: Bucharest, Romania
Has thanked: 604 times
Been thanked: 693 times
Contact:

Re: Odroid-C2 u-boot and GRUB with EFI

Post by mad_ady »

Thank you for taking the time to document everything!
These users thanked the author mad_ady for the post:
AdrianB (Tue Jun 29, 2021 5:14 am)

User avatar
rooted
Posts: 8630
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 743 times
Been thanked: 359 times
Contact:

Re: Odroid-C2 u-boot and GRUB with EFI

Post by rooted »

What a journey and amazing documentation, thank you for taking us along for the ride.
These users thanked the author rooted for the post:
AdrianB (Tue Jun 29, 2021 5:14 am)

AdrianB
Posts: 18
Joined: Thu Aug 31, 2017 5:03 am
languages_spoken: english
ODROIDs: C2
XU4
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Odroid-C2 u-boot and GRUB with EFI

Post by AdrianB »

Thanks.

Unfortunately I did it without too much documentation.
I will try to do the same for a XU4. But I don't have it with me.

Also I will write an article on my blog, maybe a little better detailed. I want to try to create a Debian package for this type of U-boot.

moon.linux
Posts: 1203
Joined: Thu Oct 02, 2014 11:42 pm
languages_spoken: english
ODROIDs: U3, XU3. XU4, C1+...
Has thanked: 1 time
Been thanked: 13 times
Contact:

Re: Odroid-C2 u-boot and GRUB with EFI

Post by moon.linux »

Hi AdrianB

Thanks for this information will give this a try.

Post Reply

Return to “General Topics”

Who is online

Users browsing this forum: No registered users and 1 guest