1. Introduction
1.1 BootLoader
BootLoader is a piece of initialization code that runs when the system is powered on to boot a complete operating system and then hand over the controller to the operating system. This BootLoader program will first initialize peripherals such as DDR, then copy the Linux kernel from Flash (NAND, NOR FLASH, SD, MMC, etc.) to DDR, and finally start the Linux kernel.
In addition, some BootLoaders may contain some advanced features, such as verifying the operating system image, selecting the appropriate operating system to boot from multiple operating system images, or adding network functions, allowing the system to independently find a suitable image from the Internet and boot it, etc. Wait.
1.2 U-Boot
U-Boot (Universal Boot Loader) is a boot loader mainly used for embedded systems. Many different computer architectures are supported, including PPC, ARM, AVR32, MIPS, x86, 68k, Nios and MicroBlaze. This is also a set of free software released under the GNU General Public License. The main function of U-Boot is to start the operating system kernel. It is divided into two stages, namely boot + loader. The boot stage starts the system, initializes the hardware devices, establishes the memory space map, and brings the software and hardware of the system to a suitable state, the loader stage loads the operating system kernel file into the memory, and then jumps to the address where the kernel is located to run. Up to now, U-Boot can realize many functions, such as supporting LCD screen, network, USB and other advanced functions.
2. U-Boot engineering structure
directory/file | illustrate |
---|---|
api | Common API function related directory |
arch | Directory related to chip architecture |
board | Board Level Related Information Catalog |
cmd | uboot command related directory |
common | Common code directory |
configs | boot configuration file directory |
disk | Disk related content directory |
doc | Documentation |
drivers | Driver code related directory |
dtoverlay | |
dts | Device tree related directories |
env | uboot environment related |
examples | sample code directory |
fs | file system related directories |
include | Header file related directory |
lib | lib library file directory |
Licenses | License related directory |
net | Network related code directory |
post | Power-on self-test related directory |
scripts | Related Script Directory |
test | test code directory |
tools | uboot build tool related directory |
Kconfig | Graphical configuration interface related files |
Makefile | Makefile |
3. Install compilation tools and dependencies
sudo apt install make git gcc-arm-none-eabi gcc bison flex libssl-dev dpkg-dev lzop libncurses5-dev
4. Get U-Boot
[Not recommended, only listed]
- Official uboot download: https://github.com/u-boot/u-boot、https://ftp.denx.de/pub/u-boot/
- NXP provides uboot download: https://source.codeaurora.org/external/imx/uboot-imx
- STM32 provides uboot download: https://github.com/STMicroelectronics/u-boot
[Newbies are recommended to use the following development board manufacturers to provide uboot]
- Wildfire provides uboot download: https://gitee.com/Embedfire/ebf_linux_uboot
- Weidongshan provides uboot download: https://gitee.com/weidongshan/stm32mp15xc-uboot
5. Compile Wildfire to provide U-Boot
-
Get wildfire to provide U-Boot source code
git clone -b ebf_v2020_10_imx https://gitee.com/Embedfire/ebf_linux_uboot
-
Enter the project directory
cd ebf_linux_uboot
-
Clear project
Clear the last generated compilation environment to avoid previous environment interference from affecting the compilation results
sudo make distclean
-
Configuration project
Load the board-level configuration file. The specific board-level configuration file is in the configs directory under the uboot root directory.The imx6ull uboot provided by Wildfire is divided into the nand version and the emmc version. Take compiling the emmc version as an example
sudo make ARCH=arm CROSS_COMPILE=arm-none-eabi- mx6ull_fire_mmc_defconfig
- ARCH=arm: set the target to arm architecture
- CROSS_COMPILE: Specifies the cross compiler used
If you want to compile the nand version of uboot, you need to
mx6ull_fire_mmc_defconfig
change tomx6ull_fire_nand_defconfig
-
Compile the project
sudo make ARCH=arm CROSS_COMPILE=arm-none-eabi-
- ARCH=arm: set the target to arm architecture
- CROSS_COMPILE: Specifies the cross compiler used
-
Generated files
After the compilation is completed, some more files are added:
- uboot : Bare metal program, so it needs to be prefixed with headers (IVT, DCD, etc. data) to execute on IMX6ULL.
- u-boot-nodtb.bin : is the executable program after removing the symbol table information through objcopy on the basis of uboot
- u-boot.dtb : The device tree of uboot, compiled by arm-none-eabi-gcc and dtc
- u-boot.bin : It is a binary file formed by appending u-boot.dtb to u-boot-nodtb.bin.
- u-boot-dtb.imx :
就是我们最终要烧写到开发板中的 uboot 镜像文件
. It is an image composed of u-boot.bin with 3KB header information and tail information added (00,00 with 1298 bytes added at the end is actually useless).
-
Create a new compilation script file
Every time you compile uboot, you need to enter a long series of commands. For simplicity, we can create a new shell script file, write these commands into the shell script file, and then only need to execute the shell script each time to complete the compilation. Work.-
Create a new shell script file named imx6ull_uboot.sh:
vim imx6ull_uboot.sh
-
Then enter the following in it:
建议还是使用 arm-none-eabi- 编译器编译uboot,编译出来的镜像文件会小点,否则编译的uboot可能无法运行。
#!/bin/bash make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- mx6ull_fire_nand_defconfig make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
- Line 1: Required by the shell script, must be "#!/bin/bash" or "#!/bin/sh".
- Line 2: The make command is used to clean up the project, that is, clean up the project every time before compiling uboot. With three parameters, the first is ARCH, which is the specified architecture, which must be arm here; the second parameter CROSS_COMPILE is used to specify the compiler, just specify the compiler prefix, such as arm-linux-gnueabihf-gcc compilation The prefix of the device is "arm-linux-gnueabihf-"; the last parameter distclean is to clear the project.
- Line 3: The make command is also used to configure uboot. There are also three parameters, the difference is that the last parameter is mx6ull_fire_mmc_defconfig. As mentioned earlier, uboot is a kind of bootloader, which can be used to boot Linux, but uboot can also boot other systems besides Linux, and uboot also supports other architectures and peripherals, such as USB, network, SD card, etc. These are all configurable, and any functions can be enabled as needed. So before compiling uboot, be sure to configure uboot according to your own needs. mx6ull_fire_mmc_defconfig is the configuration file written by Wildfire for the EMMC core board of i.MX6ULL. This configuration file is in the configs directory of the uboot source code.
- Line 4: used to compile uboot, after configuring uboot through line 3, you can directly "make" to compile uboot
-
Increase executable permission
chmod 777 imx6ull_uboot.sh.sh
-
execute script file
./imx6ull_uboot.sh.sh
-
• Written by Leung on September 3, 2022
• Reference: 3. Uboot compilation
IMX6ULL - transplant uboot-imx_v2020.04_5.4.70_2.3.0
[Linux system transplant] U-Boot compilation, programming and use
[Linux system transplant] NXP official development board uboot compilation and programming