RK3399 ported u-boot


0.Preface

  I recently bought a SW799 board at the seafood market, which looks like a disassembly board for a smart terminal. The main control is rk3399, dual-core 1.8GHz A72 + quad-core 1.4GHz A53, 4G RAM + 16G eMMC configuration. The performance looks pretty good. The previous i.mx6q-sdb was released, so I just wanted to change to a domestic controller to play with. The main reason why I chose this board is that someone has decompiled the device tree file and has the conditions for transplantation. Even if it is bricked, there is still a way to remedy it. And I found some related transplant cases, let’s try them out first.

1. Transplant

Note:
  The transplantation steps mainly refer to @大ULTerman's little monster blogger's post. You can also read the chip principle part about rk3399 step by step. The writing is very level and has reference value. The author only simplifies some steps here for reference only.
  In addition, the content of this article is temporarily based on the boss's case and is transplanted based on the configuration of the official evb evaluation board. Familiarize yourself with the development process first and then adapt it to SW799 later. Therefore, if you want to directly transplant the same board, you may need to first Explore on your own.

1. Cross tool chain installation

  Download the cross-compilation tool chain provided by the GNU Arm Embedded Toolchain official website . You need to choose according to the chip architecture. Here is:
Insert image description here
After downloading, extract it to the /usr/local/arm directory, modify the /etc/profile file, and add the tool chain to Environment variables:

sudo vim /etc/profile
export PATH=$PATH:/usr/local/arm/arm-gnu-xxxx/bin
#保存后重新加载环境变量
source /etc/profile

Check whether the installation is successful:

aarch64-none-linux-gnu-gcc -v

2. Get bl31.elf

  rk3399 is an Armv8-A architecture and also requires arm-trusted-firmware verification. Therefore, you need to compile TF-A first to obtain bl31.elf for later merging with u-boot.
  Download the arm-trusted-fireware source code, enter the directory and use the following command to compile:

make CROSS_COMPILE=aarch64-none-linux-gnu- PLAT=rk3399

Error: The arm-none-eabi-gcc tool chain is missing
Insert image description here

sudo apt-get install gcc-arm-none-eabi

Then recompile and copy the build/rk3399/release/bl31/bl31.elf file for later use.

3. Porting u-boot

u-boot software package download website: https://ftp.denx.de/pub/u-boot/

1) Download:

wget https://ftp.denx.de/pub/u-boot/u-boot-2023.07.tar.bz2
tar -jxf u-boot-2023.07.tar.bz2

2) Configuration:

make evb-rk3399_defconfig V=1
make menuconfig

Modify the serial port baud rate:

ctrl + Enter to enter modifications

Device Drivers  ---> 
      Serial --->     
           (115200) Default baudrate 

Modify emmc:

Turn off the CONFIG_MMC_HS400_SUPPORT and CONFIG_MMC_SDHCI_SDMA configurations. These two options are related to the reading and writing methods of emmc. Turning them on now will cause the problem of being unable to read emmc. You will try to adapt after transplanting the relevant drivers.

Device Drivers  ---> 
      MMC Host controller Support  --->
            [ ] MMC debugging
            [ ] enable HS400 support  
            [ ] Support IO voltage configuration
            [ ] Support SDHCI SDMA  

Configure FIT:

Download Rockchip's official u-boot and copy the script that generates the fit file from the official source code:

git clone https://github.com/rockchip-linux/u-boot.git
cp rockchip-linux/u-boot/arch/arm/mach-rockchip/make_fit_atf.py u-boot-2023.07/arch/arm/mach-rockchip/

Then add the script path in menuconfig:

Boot options  --->    
     Boot images  --->
         [*] Use a script to generate the .its script                                                 
        (arch/arm/mach-rockchip/make_fit_atf.py) .its file generator script for U-Boot FIT image

Configure boot delay: (optional)

Boot options  --->    
     Autoboot options --->
         (5) delay in seconds before automatically booting

After the setting is completed, save this configuration as my-rk3399_defconfig, and subsequent transplants will be modified based on this configuration.

3) Compile:

make ARCH=arm CROSS_COMPILE=aarch64-none-linux-gnu-

Error: atf-bl31 file is missing.
Insert image description here
Copy the bl31.elf saved in the previous step to the root directory of u-boot, rename it and recompile:

cp <path>/bl31.elf u-boot-2023.07/
cp bl31.elf atf-bl31

If an error is reported Failed to read ELF file: Python: No module named 'elftools', just use pip3 install pyelftoolsinstallation.

4) Generate idbloader.img file:

  TPL/SPL is compiled based on uboot source code. TPL is responsible for DDR initialization. After TPL initialization is completed, it will jump back to the BootROM program. The BootROM program continues to load SPL. SPL loads the u-boot.itb file and then jumps to uboor for execution.
  idbloader.img is generated from the tpl/u-boot-tpl.bin and spl/u-boot-spl.bin files and requires the use of the mkimage tool in the tools directory.

tools/mkimage -n rk3399 -T rksd -d tpl/u-boot-tpl.bin idbloader.img
  • -n rk3399 sets the name of the image file to "rk3399";
  • -T rksd specifies the image type as Rockchip SD card boot image;
  • -d tpl/u-boot-tpl.bin specifies the generated TPL image file "tpl/u-boot-tpl.bin" as the input file, and idbloader.img is specified as the output file.

Merge spl/u-boot-spl.bin into idbloader.img:

cat spl/u-boot-spl.bin >> idbloader.img

Insert image description here

5) Generate u-boot.its file

make u-boot.itb ARCH=arm CROSS_COMPILE=aarch64-none-linux-gnu-

This command will report an error when compiling because the script can compile multiple files at one time, and the parameters filled in are only related to its. After compilation is completed, u-boot.its and u-boot.itb files will exist in the current directory.
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_45682654/article/details/131881797