Use cross-compilation on Linux hosts to port U-boot to Raspberry Pi

Source: Internet
Author: User
Tags raspbian jessie

0 environment

Linux hosts os:ubuntu14.04 64-bit, running on WMware workstation 10 virtual machines

Raspberry Pi Version: Raspberry Pi 2 Type B.

Raspberry Pi Os:debian Jessie Raspbian Jessie

1 Raspberry Pi Start-up process

The boot process of the Raspberry Pi is roughly the same, and is divided into 3 stages: the GPU bootloader on the ROM starts the GPU,GPU boot cpu,cpu directly to boot the kernel or boot the kernel through u-boot.

Since Raspberry Pi is not open source for GPU-related things, porting u-boot to Raspberry Pi is not really a bootloader, but given the wide range of u-boot applications, there is still a need to learn

Raspberry Pi Boot process:

How the RASPBERRY PI BOOTS up

Raspberry Pi 3 Boot process overview

RPi Software

2 porting U-boot to the Debian Jessie system

Initially wanted to directly transplant U-boot to Raspbian, tried many times failed. Google U-boot start Raspberry Pi is mostly based on Debian Jessie, so try divert first.

Porting U-boot to Raspberry Pi reference routines

(1) The most comprehensive RPI u-boot routines RPi U-boot

(2) RPi2-based routines booting a Raspberry Pi2, with U-boot and HYP enabled

(3) RPi2-based routines for providing ready -made files Raspberry Pi 2–debian Jessie and U-boot

(4) mainline U-boot-based routines How to compile mainline u-boot for Raspberry Pi?

microSD card Burn-write Image: Debian Jessie

Ubuntu host on U-boot use mainline version, official website source Amazon

The file location on the Ubuntu host is as follows

Home directory (/root) The u-boot-2016.09 folder is extracted after the U-boot

Home directory (/root) under Script_u-boot folder is your own write environment configuration, script

u-boot-2016.09 folder as follows, you can read the Readme first

Script_u-boot folder such as, from left to right is an SCR configuration file, Environment profile, generate U-boot.bin file, generate SCR file

The Env_gnueabihf_mkimage file code is as follows

#添加树莓派的交叉编译工具链路径 (host is 64-bit)
Export PATH= $PATH:/root/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/ bin# Specifies that the compilation target schema is arm and the compiler is the cross compiler in the path path
Export Arch=arm cross_compile=arm-linux-gnueabihf-

Raspberry Pi Cross compiler toolchain address Https://github.com/raspberrypi/tools

Raspberry Pi Cross-compiling can refer to the Linux host on the implementation of Raspberry Pi cross-compiling and file transfer, remote login

Before subsequent operation, source this file to make the configuration take effect, close the terminal or re-login Ubuntu need again source

Using echo to view variables, note the tab auto-completion path

The Make_ubootbin file code is as follows

#从脚本文件夹切换到u-/root/u-boot-2016.09#配置适用于树莓派2的u-boot make rpi_2_ defconfig# compiling  make all
/root/script_u-boot

The switch path is because execution of this script is in the Script_u-boot folder, while the make command executes makefile is in the u-boot-2016.09 folder, and the last tangent back to the path facilitates subsequent source

Here make Rpi_2_defconfig is for Raspberry Pi 2 Board, other version of the Raspberry Pi make config reference the previous porting u-boot to the Raspberry Pi reference routine (1) (4)

Execution Make_ubootbin No error

A u-boot.bin is generated under the u-boot-2016.09 folder

Plug the Debian Jessie SD card into the computer via the card reader, and note that the Ubuntu system of the virtual machine is selected and Ubuntu will automatically read (mount) the SD card

Rootfs (root file system) partition:

Firmware (boot partition under Debian Jessie):

For files such as boot partition config.txt bootcode.bin cmdline.txt start.elf kernel7.img, refer to the previous Raspberry pi boot process

You can now copy the U-boot.bin to the firmware of the SD card (for the Debian Jessie System)

Then add the Config.txt in the

Kernel=u-boot.bin

Specifies that booting the kernel with U-boot.bin kernel7,config.txt is the kernel configuration file, similar to the BIOS configuration of the computer

How to configure the kernel:

One approach is to manually enter commands in the U-boot phase, while the mainline version of U-boot does not support USB input, and the Stephen Warren version in the routine (1) is not available (the problem remains to be investigated)

The other is to write the command entered in the U-boot to a script file, the script is generated by the Mkimage command. SCR image, and then put to the boot partition, U-boot will automatically read the script to start the kernel, which is easier and easier to modify, but is not conducive to debugging error messages

In the first way, you can unplug the SD card, configure the kernel boot on the Raspberry Pi, and note that the output information can only be viewed through the HDMI external display or the serial port during the U-boot phase. For serial ports refer to RPi Serial Connection

The second method is to generate the BOOT.SCR image on the Ubuntu host, write a configuration file: Create a new configure_scr_file under the Script_u-boot folder, the content is as follows

0x00000c42
" earlyprintk console=tty0 console=ttyama0 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait noinitrd "
#保存环境配置saveenv
0:1 ${kernel_addr_r} kernel7.img
#启动内核bootz ${kernel_addr_r}

The syntax of the above command is u-boot software provisions, the details of the command can refer to the RPi u-boot official documentation U-bootdoc

Then create a new script MAKE_UBOOTSCR to generate the SCR image, MAKE_UBOOTSCR content as follows

0x00000000 0x00000000 " RPi2 Boot Script " -D/PATH/TO/SCRIPT/BOOT/FIRMWARE/BOOT.SCR

/path/to/script is the path of the Configure_scr_file, replaced as follows

0x00000000 0x00000000 " RPi2 Boot Script " -D/ROOT/SCRIPT_U-BOOT/CONFIGURE_SCR_FILE/BOOT/FIRMWARE/BOOT.SCR

Source error, prompt not installed Mkimage

Command not found usually not installed software, or did not add the path, Mkimage should be included in the U-boot software, due to previous experience with the Raspberry Pi cross-compiling tool chain, found in the u-boot-2016.09 folder Tools folder Mkimage Program

More common is to find it with the Find command

 Find Find path-name file name

It appears that there is no add mkimage path to the environment variable, just add the path in Env_gnueabihf_mkimage and then source

Env_gnueabihf_mkimage modified as follows

Export path= $PATH:/root/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin:/root /u-boot-2016.09/toolsexport ARCH=arm cross_compile=arm-linux-gnueabihf-

Hint path does not exist

At this point you need to understand the specific meaning of this mkimage command, refer to mkimage-generate image for U-boot

/BOOT/FIRMWARE/BOOT.SCR is the path to generate the Boot.scr file, if the path on the Raspberry Pi operation is the boot partition, but I am operating on the Ubuntu host, the SD card is attached to the Ubuntu host path has been changed

View block devices can be used with commands

Lsblk

SDB is the SD card, SDB1 is the firmware boot partition, SDB2 is the Rootfs file system partition

In fact, when inserting the SD card, Ubuntu automatically mount the SD card to the/media path of the host, so the front can copy and paste the U-boot.bin directly.

However, if you want to mount the first partition of the SD card to another path, such as the/mnt folder of the host, you should

Mount /dev/sdb1/mnt

Note the actual path of the device and the difference between the mount after the path,/dev/xxx is the actual device path

Check the SD card path on the Debian Jessie Raspberry Pi below

This is because the Debian Jessie does not have the automatic mount function

The BOOT.SCR can be generated directly into the firmware (first inserted in Ubuntu SD card)

0x00000000 0x00000000 " RPi2 Boot Script " -D/ROOT/SCRIPT_U-BOOT/CONFIGURE_SCR_FILE/MEDIA/BOOT/FIRMWARE/BOOT.SCR

It is recommended that the build be copied to the SD card in other directories (such as the u-boot-2016.09 folder) and eventually to the following,-n is the generated file name

Mkimage-a arm-o linux-t script-c none-a 0x00000000-e 0x00000000-n boot.scr-d/root/script_u-boot/configure_scr_fil E/root/u-boot-2016.09/boot.scr

Successfully generated BOOT.SCR

After the U-boot.bin BOOT.SCR is copied to the SD card firmware, confirm that Config.txt added Kernel=u-boot.bin can unplug the SD card to start the Raspberry Pi 2.

The startup process is as follows

Enter the login screen

Login name (login): root

Password (password):d Ebian

Login successful, u-boot migration completed on Debian Jessie

Cross-compiling on the host generates Boot.bin, or you can specify the compiler directly in the make statement without adding the environment variable Arch,cross_compile

Make_ubootbin can be changed to the following

cd/root/u-boot-2016.09 make Arch=arm cross_compile=arm-linux-gnueabihf-
Make Arch=arm cross_compile=arm-linux-gnueabihf--/root/script_u-boot
-j4 is based on a four-core processor four thread compilation, depending on the host CPU WIN7 view the number of CPU cores

3 porting U-boot to Raspbian Jessie system

With the previous attempt, the next one will follow.

If you directly copy the U-boot.bin BOOT.SCR you just generated to Raspbian, add Kernel=u-boot.bin in Config.txt

After start-up stay in starting kernel ...

The message shows that the KERNEL7 has been read through BOOT.SCR, stating that the problem is the part after the boot kernel

Comparing the partitions of Debian Jessie and Raspbian Jessie, the file system is the same, that is, the boot partition is different

Boot partition for Debian Jessie

Raspbian Jessie's boot partition

Found Raspbian more than a kernel.img, a few. dtb files, overlay inside is also. dtb file

Refer to the RPi u-boot after feeling the need to load DTB (Device Tree binary)

Modify the contents of the BOOT.SCR configuration file (Configure_scr_file) as follows

 setenv machid 0x00000c42   #添加变量fdtfile的值为bcm2709 -rpi-2 --rpi-2 - B.dtbsetenv Bootargs   EARLYPRINTK Console=tty0 console=ttyama0 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait noinitrd   " saveenvfatload MMC  0 :  ${ Kernel_addr_r} kernel7.img# Load Fdtfile value fatload mmc  0 : 1   ${fdt_addr_r} ${fdtfile}bootz ${kernel_addr_r} -${fdt_addr_r} 

Add BCM2709-RPI-2-B.DTB here because using Raspberry Pi 2, if other versions are modified as appropriate

Then source generates BOOT.SCR

SOURCE Make_ubootbin

Copy the new BOOT.SCR to the boot partition, U-boot.bin is exactly the same as before, Config.txt add Kernel=u-boot.bin

Unplug SD card on host, start Raspberry Pi

Automatic Login to the desktop

at this point u-boot on Raspbian Jessie to complete the transplant  

Use cross-compilation on Linux hosts to port U-boot to Raspberry Pi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.