Please enable javascript, or click here to visit my ecommerce web site powered by Shopify.
Jump to: navigation, search

Difference between revisions of "Zero/dev/u-boot"

< Zero‎ | dev
(Run U-boot)
m (Changed compiler flag to match installed libraries. Added warning as fastboot flashing does not work for current image (as long as nobody figures out the 'magic number' to U-Boot))
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{zero_header}}
 
{{zero_header}}
 +
 
{{Languages|zero/dev/u-boot}}
 
{{Languages|zero/dev/u-boot}}
 +
 
     [[zero | Radxa Zero]] > [[zero/dev | Development]] > [[zero/dev/u-boot | U-Boot]]
 
     [[zero | Radxa Zero]] > [[zero/dev | Development]] > [[zero/dev/u-boot | U-Boot]]
  
=== Build U-Boot and run it on Radxa Zero ===
+
=== Build U-Boot and flash it on Radxa Zero ===
 +
 
 +
This guide describes how to build U-Boot and flash it on Radxa Zero. U-Boot image can be flashed on eMMC or microSD, and it can be sideload from USB as well.
  
This guide describes how to build U-Boot  and run it on Radxa Zero. U-Boot images could be installed into eMMC or Micro SD Card or USB boot.
+
<font color="#FF0000">WARNING!</font> Flash bootloader incorrectly could result in unbootable system and loss of data. Do not replace bundled bootloader unless you understand the risk.
  
 
==== Requirement ====
 
==== Requirement ====
Line 11: Line 15:
 
* Radxa Zero
 
* Radxa Zero
 
* USB A to C cable
 
* USB A to C cable
* A PC/laptop running Linux(Ubuntu 18.04 or higher)
+
* A computer running Ubuntu 18.04 or higher
  
 
==== Build U-Boot ====
 
==== Build U-Boot ====
Line 17: Line 21:
 
===== Step 1: Get the source code =====
 
===== Step 1: Get the source code =====
  
You need Git to get multiple git repositories to build the image.
+
We use git to fetch source code from internet. If you do not have git installed, try following commands:
  
Install Git if you don't have it.
+
    sudo apt update
 +
    sudo apt install git
  
    sudo apt-get update && sudo apt-get install -y git
+
Once you have git installed, you can download the source code:
 
+
Clone the source code
+
  
 
     git clone -b radxa-zero-v2021.07 https://github.com/radxa/u-boot.git
 
     git clone -b radxa-zero-v2021.07 https://github.com/radxa/u-boot.git
  
FIP(Firmware in Package) is a bunch of scripts and prebuilt binaries(first stage loader etc) for Radxa Zero u-boot.
+
FIP(Firmware in Package) is a collection of scripts and pre-built binaries (such as first stage loader and so on) for Radxa Zero U-Boot. Get them with following command:
  
 
     git clone https://github.com/radxa/fip.git
 
     git clone https://github.com/radxa/fip.git
  
===== Step 2: Install necessary tools =====
+
===== Step 2: Set up build environment =====
  
  sudo apt-get install -y gcc-aarch64-linux-gnu device-tree-compiler libncurses5 libncurses5-dev
+
Execute following commands to install build dependencies and the tool chain necessary for building.
  sudo apt-get install -y bc python dosfstools flex build-essential libssl-dev mtools
+
 
+
Get the toolchain
+
  
 +
  sudo apt install bc nano mc build-essential autoconf libtool cmake pkg-config git python python-dev swig libpcre3-dev libnode-dev gawk wget diffstat bison flex device-tree-compiler libncurses5 libncurses5-dev gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binfmt-support qemu-user-static dosfstools libssl-dev mtools
 
   wget https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz
 
   wget https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz
 
   sudo tar xvf gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz -C /opt
 
   sudo tar xvf gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz -C /opt
Line 43: Line 44:
 
===== Step 3: Build U-boot =====
 
===== Step 3: Build U-boot =====
  
   export CROSS_COMPILE=/opt/gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf/bin/aarch64-none-elf-
+
   export CROSS_COMPILE=/opt/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin/aarch64-none-elf-
 
   export ARCH=arm
 
   export ARCH=arm
 
   cd u-boot
 
   cd u-boot
Line 49: Line 50:
 
   make
 
   make
  
You will have u-boot.bin built.
+
You will find <code>u-boot.bin</code> under <code>u-boot</code> folder if everything runs without error.
  
 
===== Step 4: Pack U-boot =====
 
===== Step 4: Pack U-boot =====
Line 63: Line 64:
 
==== Run U-boot ====
 
==== Run U-boot ====
  
* Download and run in RAM from USB
+
* Sideloading from USB
 +
 
 +
When your U-Boot is broken you can sideload a working image to recover an unbootable system. This can also be used to verify the newly generated image is working before flashing it permanently on storage media.
  
 
Install the maskrom usb download tool with pip
 
Install the maskrom usb download tool with pip
  
 
   sudo apt install pip3
 
   sudo apt install pip3
   sudo pip3 install git+https://github.com/superna9999/pyamlboot
+
   sudo pip3 install pyamlboot
 +
 
 +
Press and hold the [https://wiki.radxa.com/mw/images/e/e2/Radxa_zero_ports.jpg USB boot button] on the back of Radxa Zero, and connect Zero to your PC.
  
Press and hold the [https://wiki.radxa.com/mw/images/e/e2/Radxa_zero_ports.jpg USB boot button] on the back of Radxa Zero, plug the Zero to PC
+
You should see following device connected to your system:
  
 
   $ lsusb
 
   $ lsusb
 
   Bus 002 Device 030: ID 1b8e:c003 Amlogic, Inc. GX-CHIP
 
   Bus 002 Device 030: ID 1b8e:c003 Amlogic, Inc. GX-CHIP
  
Download and run u-boot.bin
+
Sideloadng u-boot.bin:
  
 
   boot-g12.py /path/to/'''fip/radxa-zero/u-boot.bin'''
 
   boot-g12.py /path/to/'''fip/radxa-zero/u-boot.bin'''
  
On serial console, you will see the just built u-boot is booting.
+
If you have serial console attached to Radxa Zero, you will see the boot message from U-Boot.
  
* Write the u-boot to Micro SD card and run
+
* Flash U-Boot to microSD
  
 
   bin=/path/to/'''fip/radxa-zero/u-boot.bin.sd.bin'''
 
   bin=/path/to/'''fip/radxa-zero/u-boot.bin.sd.bin'''
Line 87: Line 92:
 
   sudo dd if=$bin of=/dev/sdx conv=fsync,notrunc bs=512 skip=1 seek=1
 
   sudo dd if=$bin of=/dev/sdx conv=fsync,notrunc bs=512 skip=1 seek=1
  
Plug the micro SD card to Zero and boot. If your Zero has eMMC, you can erase it first to make sure it boots from micro SD card.
+
If your Zero has built-in eMMC, we recommend [[Zero/install/eMMC_erase | erase it]] so the microSD's U-Boot will be used.
  
* Write the u-boot to eMMC
+
* Flash U-Boot to eMMC (ONLY FOR BRANCH 2021.01, DOES NOT WORK WITH ABOVE BUILD)
  
We use '''fastboot''' to flash u-boot to eMMC. Unplug the micro SD card of Zero and press&hold the [https://wiki.radxa.com/mw/images/e/e2/Radxa_zero_ports.jpg usb boot button], plug the power cable to PC.
+
We use '''fastboot''' to flash U-Boot to eMMC. Unplug microSD card from Zero and press & hold the [https://wiki.radxa.com/mw/images/e/e2/Radxa_zero_ports.jpg usb boot button], then connect Zero to your PC.
  
 
   sudo apt install fastboot
 
   sudo apt install fastboot
Line 99: Line 104:
 
   sudo fastboot reboot
 
   sudo fastboot reboot
  
unplug and plug USB C cable and new u-boot will boot from eMMC.
+
Some forum user also discover a method to [https://forum.radxa.com/t/install-os-direct-to-emmc-with-ubuntu/7435 flash U-Boot with dd] in USB mass storage mode:
 +
 
 +
curl -L https://dl.radxa.com/zero/images/loader/u-boot.bin | sudo dd of=/dev/sdX bs=512 seek=1 && sync

Latest revision as of 13:18, 18 October 2022

    Radxa Zero >  Development >  U-Boot

Build U-Boot and flash it on Radxa Zero

This guide describes how to build U-Boot and flash it on Radxa Zero. U-Boot image can be flashed on eMMC or microSD, and it can be sideload from USB as well.

WARNING! Flash bootloader incorrectly could result in unbootable system and loss of data. Do not replace bundled bootloader unless you understand the risk.

Requirement

  • Radxa Zero
  • USB A to C cable
  • A computer running Ubuntu 18.04 or higher

Build U-Boot

Step 1: Get the source code

We use git to fetch source code from internet. If you do not have git installed, try following commands:

   sudo apt update
   sudo apt install git

Once you have git installed, you can download the source code:

   git clone -b radxa-zero-v2021.07 https://github.com/radxa/u-boot.git

FIP(Firmware in Package) is a collection of scripts and pre-built binaries (such as first stage loader and so on) for Radxa Zero U-Boot. Get them with following command:

   git clone https://github.com/radxa/fip.git
Step 2: Set up build environment

Execute following commands to install build dependencies and the tool chain necessary for building.

 sudo apt install bc nano mc build-essential autoconf libtool cmake pkg-config git python python-dev swig libpcre3-dev libnode-dev gawk wget diffstat bison flex device-tree-compiler libncurses5 libncurses5-dev gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binfmt-support qemu-user-static dosfstools libssl-dev mtools
 wget https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz
 sudo tar xvf gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz -C /opt
Step 3: Build U-boot
 export CROSS_COMPILE=/opt/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin/aarch64-none-elf-
 export ARCH=arm
 cd u-boot
 make radxa-zero_defconfig 
 make

You will find u-boot.bin under u-boot folder if everything runs without error.

Step 4: Pack U-boot
 cp u-boot.bin ../fip/radxa-zero/bl33.bin
 cd ../fip/radxa-zero
 make

This will generate

   u-boot.bin u-boot.bin.sd.bin u-boot.bin.usb.bl2 u-boot.bin.usb.tpl

Run U-boot

  • Sideloading from USB

When your U-Boot is broken you can sideload a working image to recover an unbootable system. This can also be used to verify the newly generated image is working before flashing it permanently on storage media.

Install the maskrom usb download tool with pip

 sudo apt install pip3
 sudo pip3 install pyamlboot

Press and hold the USB boot button on the back of Radxa Zero, and connect Zero to your PC.

You should see following device connected to your system:

 $ lsusb
 Bus 002 Device 030: ID 1b8e:c003 Amlogic, Inc. GX-CHIP

Sideloadng u-boot.bin:

 boot-g12.py /path/to/fip/radxa-zero/u-boot.bin

If you have serial console attached to Radxa Zero, you will see the boot message from U-Boot.

  • Flash U-Boot to microSD
 bin=/path/to/fip/radxa-zero/u-boot.bin.sd.bin
 sudo dd if=$bin of=/dev/sdx conv=fsync,notrunc bs=1 count=444
 sudo dd if=$bin of=/dev/sdx conv=fsync,notrunc bs=512 skip=1 seek=1

If your Zero has built-in eMMC, we recommend erase it so the microSD's U-Boot will be used.

  • Flash U-Boot to eMMC (ONLY FOR BRANCH 2021.01, DOES NOT WORK WITH ABOVE BUILD)

We use fastboot to flash U-Boot to eMMC. Unplug microSD card from Zero and press & hold the usb boot button, then connect Zero to your PC.

 sudo apt install fastboot
 wget https://dl.radxa.com/zero/images/loader/rz-fastboot-loader.bin
 boot-g12.py rz-fastboot-loader.bin
 sudo fastboot flash 0x200 /path/to/fip/radxa-zero/u-boot.bin
 sudo fastboot reboot

Some forum user also discover a method to flash U-Boot with dd in USB mass storage mode:

curl -L https://dl.radxa.com/zero/images/loader/u-boot.bin | sudo dd of=/dev/sdX bs=512 seek=1 && sync