Board:Nanopi M4 2G
[Toolchain]
sudo tar -jxvf arm-6.4.tar.bz2 -C /usr/local
(加入環境變數)
vim ~/.bashrc (位置home/andy/.bashrc)
export PATH=/usr/local/arm/6.4/bin:$PATH (加新路徑) //編譯器gcc路徑
source ~/.bashrc (立刻載入修改後的設定,使之生效。)
平台配置 配置文件
configs/rk3399_defconfig
CONFIG_SYS_EXTRA_OPTIONS="RKCHIP_RK3399,PRODUCT_MID,NORMAL_WORLD,SECOND_LEVEL_BOOTLOADER,BAUDRATE=115200"
CONFIG_ARM=y
CONFIG_ROCKCHIP_ARCH64=y
CONFIG_PLAT_RK33XX=y
U-BOOT自动生成的配置文件
uboot-rockchip/include/config.h
/* Automatically generated - do not edit */
#define CONFIG_RKCHIP_RK3399 1
#define CONFIG_PRODUCT_MID 1
#define CONFIG_NORMAL_WORLD 1
#define CONFIG_SECOND_LEVEL_BOOTLOADER 1
#define CONFIG_BAUDRATE 115200
#define CONFIG_BOARDDIR board/rockchip/rk33xx
#include <config_defaults.h>
#include <configs/rk33plat.h>
#include <asm/config.h>
#include <config_fallbacks.h>
#include <config_uncmd_spl.h>
------------------------------------------------------------------------------
系统配置
rk_default_config.h:RK平台的公共配置,默认打开所有需要的功能
include/configs/rk_default_config.h 重要檔
/* rk kernel load address */配置Kernel加载的地址,DDR偏移32M的位置
#define CONFIG_KERNEL_LOAD_ADDR (CONFIG_RAM_PHY_START + SZ_32M) /* 32M offset */
/* rk nand api function code address */配置 Nand Flash 驱动API接口地址DDR偏移48M的位置。
#define CONFIG_RKNAND_API_ADDR (CONFIG_RAM_PHY_START + SZ_32M + SZ_16M) /* 48M offset */
/* rk uboot reserve size */ 配置 U-BOOT Reserve空间大小。
#define CONFIG_LMB_RESERVE_SIZE (SZ_32M + SZ_16M + SZ_8M) /* 56M offset */
/* rk ddr max banks */ 配置 DDR驱动传递DDR容量信息中DDR的Banks数目。
#define CONFIG_RK_MAX_DRAM_BANKS 8 /* rk ddr max banks */
/* rk ddr banks address and size */ 配置 DDR驱动传递容量信息的地址,偏移32M的位置。
#define CONFIG_RKDDR_PARAM_ADDR (CONFIG_RAM_PHY_START + SZ_32M)
/*rk trust os banks address and size*/配置使用ARM Trusted Firmware时需要内核保留的空间信息。
#define CONFIG_RKTRUST_PARAM_ADDR (CONFIG_RAM_PHY_START+SZ_32M+ SZ_2M)
配置 HDMI 的一些信息需要内核获取的地址。
/* rk hdmi device information buffer (start: 128M - size: 8K) */
#define CONFIG_RKHDMI_PARAM_ADDR CONFIG_RAM_PHY_END
U-Boot用到的SDRAM的空间范围
#define CONFIG_RAM_PHY_START 0x00000000
#define CONFIG_RAM_PHY_SIZE SZ_128M
#define CONFIG_RAM_PHY_END (CONFIG_RAM_PHY_START + CONFIG_RAM_PHY_SIZE)
RK33系列平台的配置
include/configs/rk33plat.h:
rk33plat.h:
include/configs/rk33plat.h:#include <configs/rk_default_config.h>
#ifndef __RK33PLAT_CONFIG_H
#define __RK33PLAT_CONFIG_H
#include <asm/arch/io.h>
/* gic and rk timer version */
#if defined(CONFIG_RKCHIP_RK3368) || defined(CONFIG_RKCHIP_RK3366) || defined(CONFIG_RKCHIP_RK322XH)
#define CONFIG_GICV2
#define CONFIG_RKTIMER_V2
#elif defined(CONFIG_RKCHIP_RK3399)
#define CONFIG_GICV3
#define CONFIG_RKTIMER_V3
#else
#error "PLS config rk chip for GIC and TIMER version!"
#endif
/* gic base */
#if defined(CONFIG_GICV2)
#define GICD_BASE RKIO_GICD_PHYS
#define GICC_BASE RKIO_GICC_PHYS
#elif defined(CONFIG_GICV3)
#define GICC_BASE RKIO_GICC_PHYS
#define GICD_BASE RKIO_GICD_PHYS
#define GICR_BASE RKIO_GICR_PHYS
#endif /* CONFIG_GICV2 */
/* Generic Timer Definitions */
#define COUNTER_FREQUENCY CONFIG_SYS_CLK_FREQ_CRYSTAL
/*
* uboot ram config.
*/
#include <linux/sizes.h>
#define CONFIG_RAM_PHY_START 0x00000000
#define CONFIG_RAM_PHY_SIZE SZ_128M
#define CONFIG_RAM_PHY_END (CONFIG_RAM_PHY_START + CONFIG_RAM_PHY_SIZE)
定义了SOC能够访问DDR的最大地址物理空间,如果DDR的实际容量大于该值,那么该宏会起作用并最终由DTB传递给内核。
/* reserve iomap memory. */
#define CONFIG_MAX_MEM_ADDR RKIO_IOMEMORYMAP_START
arch/arm/include/asm/arch-rk33xx/io-rk3399.h:
#define RKIO_IOMEMORYMAP_START 0xF8000000 //= 4160749568
/*
* define uboot loader addr.
* notice: CONFIG_SYS_TEXT_BASE must be an immediate,
* so if CONFIG_RAM_PHY_START is changed, also update CONFIG_SYS_TEXT_BASE define.
*
* Resersed 2M space(0 - 2M) for Runtime ARM Firmware bin, such as bl30/bl31/bl32 and so on.
*
*/
#ifdef CONFIG_SECOND_LEVEL_BOOTLOADER
#define CONFIG_SYS_TEXT_BASE 0x00200000 /* Resersed 2M space Runtime Firmware bin. */定义了U-BOOT运行的起始空间。
#else
#define CONFIG_SYS_TEXT_BASE 0x00000000
#endif
指定拷贝kernel的地址,如果定义了该宏,那么U-BOOT在启动的时候会直接将kernel拷贝到该位置并启动,否则默认将拷贝到DDR偏移32M的位置,定义该宏一般是使用没有压缩的kernel,加快开机速度。
/* kernel load to the running address */
#define CONFIG_KERNEL_RUNNING_ADDR (CONFIG_SYS_TEXT_BASE + SZ_512K)
/*
* rk plat default configs.
*/
#include <configs/rk_default_config.h>
/* el3 switch to el1 disable */
#ifndef CONFIG_SECOND_LEVEL_BOOTLOADER
#define CONFIG_SWITCH_EL3_TO_EL1
#endif
/* icache enable when start to kernel */
#define CONFIG_ICACHE_ENABLE_FOR_KERNEL
#define CONFIG_OF_BOARD_SETUP
/* undef some module for rk chip */
#if defined(CONFIG_RKCHIP_RK3399)
#define CONFIG_SECUREBOOT_CRYPTO
#define CONFIG_SECUREBOOT_SHA256
#define CONFIG_RKTIMER_INCREMENTER
#define CONFIG_RK_SDHCI_BOOT_EN
#undef CONFIG_RK_SDMMC_BOOT_EN
#undef CONFIG_RK_FLASH_BOOT_EN
#undef CONFIG_RK_UMS_BOOT_EN
#undef CONFIG_RK_MCU
#undef CONFIG_PERILP_MCU
#undef CONFIG_PMU_MCU
#undef CONFIG_RK_PL330_DMAC
#if (defined(CONFIG_CMD_ROCKUSB) || defined(CONFIG_CMD_FASTBOOT))
#undef CONFIG_RK_UDC
#define CONFIG_RK_DWC3_UDC
#endif
#define CONFIG_RK_GPIO_EXT_FUNC
#define CONFIG_CHARGE_LED
#define CONFIG_POWER_FUSB302
#define CONFIG_OPTEE_CLIENT
#define CONFIG_OPTEE_V1
/*
* we should enable this macro when we use emmc and secure store
* data to security partition, not to rpmb.
*/
#define CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION
#endif
/* if uboot as first level loader, no start mcu. */
#ifndef CONFIG_SECOND_LEVEL_BOOTLOADER
#undef CONFIG_RK_MCU
#endif
/* ARMv8 RSA key in ram, MiniLoader copy RSA KEY to fixed address */
#if defined(CONFIG_SECUREBOOT_CRYPTO)
#if defined(CONFIG_SECOND_LEVEL_BOOTLOADER) && defined(CONFIG_NORMAL_WORLD)
#define CONFIG_SECURE_RSA_KEY_IN_RAM
#define CONFIG_SECURE_RSA_KEY_ADDR (CONFIG_RKNAND_API_ADDR + SZ_2K)
#endif /* CONFIG_NORMAL_WORLD && CONFIG_SECOND_LEVEL_BOOTLOADER */
#endif /* CONFIG_SECUREBOOT_CRYPTO */
/* mod it to enable console commands. */在Shell中启用启动延时
#define CONFIG_BOOTDELAY 6
/* efuse version */
#ifdef CONFIG_RK_EFUSE
#define CONFIG_RKEFUSE_V2
/* store the content of efuse non-secure */
#define CONFIG_EFUSE_NS_INFO_ADDR(CONFIG_RAM_PHY_START+SZ_1M+SZ_1K * 60)
#endif
/* sdhci config */
#ifdef CONFIG_RK_SDHCI_BOOT_EN // RK3399
/* general sdhci driver */
#undef CONFIG_MMC
#undef CONFIG_GENERIC_MMC
#undef CONFIG_PARTITIONS
#undef CONFIG_SDHCI
#undef CONFIG_RK_SDHCI
/* rk arasan sdhci driver */
#define CONFIG_RK_AR_SDHCI
#endif
/* mmc using dma */
#define CONFIG_RK_MMC_DMA
#define CONFIG_RK_MMC_IDMAC /* internal dmac */
#if defined(CONFIG_RKCHIP_RK322XH)
#define CONFIG_RK_MMC_DDR_MODE /* mmc using ddr mode */
#else
#undef CONFIG_RK_MMC_DDR_MODE /* mmc using ddr mode */
#endif
#if (defined(CONFIG_CMD_ROCKUSB) || defined(CONFIG_CMD_FASTBOOT))
#define CONFIG_USBD_MANUFACTURER "Rockchip"
#define CONFIG_USBD_PRODUCT_NAME "rk30xx"
#endif
/* more config for rockusb */
#ifdef CONFIG_CMD_ROCKUSB
/* support rockusb timeout check */
#define CONFIG_ROCKUSB_TIMEOUT_CHECK 1
/* rockusb VID/PID should the same as maskrom */
#define CONFIG_USBD_VENDORID 0x2207
#if defined(CONFIG_RKCHIP_RK3368)
#define CONFIG_USBD_PRODUCTID_ROCKUSB 0x330A
#elif defined(CONFIG_RKCHIP_RK3366)
#define CONFIG_USBD_PRODUCTID_ROCKUSB 0x330B
#elif defined(CONFIG_RKCHIP_RK3399)
#define CONFIG_USBD_PRODUCTID_ROCKUSB 0x330C
#elif defined(CONFIG_RKCHIP_RK322XH)
#define CONFIG_USBD_PRODUCTID_ROCKUSB 0x320C
#else
#error "PLS config rk chip for rockusb PID!"
#endif
系统编译
make CROSS_COMPILE=aarch64-linux- rk3399_defconfig //只需做一次
make CROSS_COMPILE=aarch64-linux- -j8
(or vim ~/.bashrc export CROSS_COMPILE=aarch64-linux)
export 環變設定
export XXX=123
echo XXX 打印環變
123
=============================================================
啟動流程
BOOTROM => TPL(ddr bin) => SPL(miniloader) => TRUST => U-BOOT => KERNEL
TPL 相当于 ddr bin,SPL 相当于 miniloader,所以 SPL+TPL 的组合实现了跟 Rockchip
ddr.bin+miniloader 完全一致的功能,可相互替换
TPL 相當於 ddr bin,SPL 相當於 miniloader。TPL+SPL 的組合實現了跟 RK 閉源 ddr.bin+miniloader 一致的功能,可相互替換。
rk3399_loader_v1.22.119.bin=rk3399_ddr_800MHz_v1.22.bin+rk3399_miniloader_v1.19.bin+rk3399_usbplug_v1.19.bin
RK平臺根據前級Loader程式碼是否開源,目前有兩套啟動管道:下述錯誤
// 前級loader閉源 BOOTROM => ddr bin => Miniloader => TRUST => U-BOOT => KERNEL
// 前級loader開源 BOOTROM => TPL => SPL => TRUST => U-BOOT => KERNEL
重要參考 Boot option - Rockchip open source Document
Boot from eMMC maskrom模式
rkdeveloptool db rkxx_loader_vx.xx.bin rkdeveloptool wl 0x40 idbloader.img //ul rkxx_loader_vx.xx.bin ??? rkdeveloptool wl 0x4000 uboot.img rkdeveloptool wl 0x6000 trust.img rkdeveloptool wl 0x8000 boot.img rkdeveloptool wl 0x40000 rootfs.img rkdeveloptool rd
目前可以通过./make.sh 命令把 u-boot-spl.bin 替换掉 miniloader 生成 loader,然后通过 PC 工具烧
=============================================================
一级 Loader 模式
U-BOOT 作为一级 Loader 模式,那么仅支持 EMMC 存储设备,编译完成后生成的镜像:
rk3399_loader_v1.22.119.bin 其中v1.22.119 是发布的版本号。
二级 Loader 模式
U-Boot 作为二级 Loader 模式,那么固件支持所有的存储设备,该模式下,需要
MiniLoader 支持,通过宏 CONFIG_MERGER_MINILOADER 进行配置生成。同时引入 Arm
Trusted Firmware 后会生成 trust image ,这个通过宏 CONFIG_MERGER_TRUSTIMAGE 进
行配置生成。
以 rk3399 编译生成的镜像为例:
rk3399_loader_v1.22.119.bin
uboot.img
trust.img
########################################################
~/uboot-rockchip/tools 工具 boot_merger / trust_merger / loaderimage
boot_merger 将这三个bin文件最后合并成rk3399_loader_v1.22.119.bin
trust_merger 参数为RK3399TRUST.ini,生成trust.img;
loaderimage 将u-boot.bin变成uboot.img;
###########################################################
1.boot_merger
打包:
./tools/boot_merger --pack ./tools/rk_tools/RKBOOT/RK3399MINIALL.ini
解包:
./tools/boot_merger --unpack rk3399_loader_v1.22.119.bin
tools/rk_tools/RKBOOT/RK3399MINIALL.ini
RK3399MINIALL.ini
[CHIP_NAME]
NAME=RK330C
[VERSION]
MAJOR=1
MINOR=19
[CODE471_OPTION]
NUM=1
Path1=tools/rk_tools/bin/rk33/rk3399_ddr_800MHz_v1.22.bin //开机是800MHz的频率
Sleep=1
[CODE472_OPTION]
NUM=1
Path1=tools/rk_tools/bin/rk33/rk3399_usbplug_v1.19.bin
[LOADER_OPTION]
NUM=2
LOADER1=FlashData
LOADER2=FlashBoot
FlashData=tools/rk_tools/bin/rk33/rk3399_ddr_800MHz_v1.22.bin
FlashBoot=tools/rk_tools/bin/rk33/rk3399_miniloader_v1.19.bin
[OUTPUT]
PATH=rk3399_loader_v1.22.119.bin
----------------------------------------------------------------
2.trust_merger
打包:
./tools/trust_merger --pack ./tools/rk_tools/RKTRUST/RK3399TRUST.ini
解包:
./tools/trust_merger --unpack trust.img
RKTRUST/RK3399TRUST.ini
RK3399TRUST.ini
[VERSION]
MAJOR=1
MINOR=0
[BL30_OPTION]
SEC=0
[BL31_OPTION]
SEC=1
PATH=tools/rk_tools/bin/rk33/rk3399_bl31_v1.28.elf
ADDR=0x00010000
[BL32_OPTION]
SEC=1
PATH=tools/rk_tools/bin/rk33/rk3399_bl32_v1.16.bin
ADDR=0x08400000
[BL33_OPTION]
SEC=0
[OUTPUT]
PATH=trust.img
------------------------------------------------------------------------
3.loaderimage
./tools/loaderimage --pack --uboot ./u-boot.bin uboot.img 0x60000000 --size 1024
--------------------------------------------------------------------------------------------------------------------
4.修改圖片及動畫 用resource.img
Resource_tool工具
pack_resource.sh脚本
----------------------------------------------------------------------------
補充
/uboot-rockchip/board/rockchip/rk33xx板级平台核心文件
rk33xx.c config.mk
/uboot-rockchip/arch/arm/cpu/armv8
start.S cpu初始化
include/configs/rk_default_config.h **重要**
rk平台公共配置
include/configs/rk33plat.h:
rk33xx系列平台配置
arch/arm/include/asm/arch-rk33xx/:
rk33xx系列平台架构头文件
arch/arm/cpu/armv8/rk33xx/:
rk33xx系列平台架构文件, 包括clock, irq, timer等实现。
board/rockchip/rk33xx:
板级平台核心文件,主要是rk33xx.c,里面有熟悉的kernel要用的machine type.
命令相关文件目录:
common/
驱动相关文件目录:
drivers/
工具相关文件目录:
tools/tools/rk_tools