首页 > 其他分享 >rockchip uboot 应用dts overlays

rockchip uboot 应用dts overlays

时间:2024-05-15 09:41:27浏览次数:26  
标签:fs addr overlay rockchip dtbo dts build overlays fdt

提供一种基于rkSDK buildroot使用dtbo的方法

简单说明:

  1. uboot中默认加载default-dtb-overlay.dtbo
  2. app/dtbo-tools/S03checkDTBO 开机检查拨码开关,并将/boot/overlays/default-dtb-overlay.dtbo链接到目标dtbo,有效的dtbo名全部存放于dtbo_table变量中
  3. build.sh中:新增dtbo编译选项,根据RK_KERNEL_DTS_OVERLAYS配置自动更新S03checkDTBOdtbo_table变量,并将dtbo与S03checkDTBO安装到rootfs
  4. 在.BoardConfig 添加RK_KERNEL_DTS_OVERLAYS环境变量

uboot补丁

diff --git a/arch/arm/mach-rockchip/boot_rkimg.c b/arch/arm/mach-rockchip/boot_rkimg.c
index 097d976b1f..1ace5da174 100644
--- a/arch/arm/mach-rockchip/boot_rkimg.c
+++ b/arch/arm/mach-rockchip/boot_rkimg.c
@@ -35,6 +35,7 @@
 #include <u-boot/sha1.h>
 #include <u-boot/sha256.h>
 #include <linux/usb/phy-rockchip-usb2.h>
+#include <mapmem.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -552,6 +553,136 @@ static int rkimg_traverse_read_dtb(void *fdt, int where)
        return -EINVAL;
 }
 
+static int do_get_ext2(cmd_tbl_t *cmdtp, const char *file_path, char *file_addr)
+{
+       static char *fs_argv[5];
+       disk_partition_t part_info;
+       char part_num[4]= {0};
+
+       int ret = part_get_info_by_name(dev_desc, "rootfs", &part_info);
+       if (ret < 0){
+               printf("[warning] not found partion:%s\n","rootfs");
+               return ret;
+       }
+
+       sprintf(part_num, "%s:%d", env_get("devnum"), ret);
+
+       fs_argv[0] = "ext2load";
+       fs_argv[1] = env_get("devtype");
+       fs_argv[2] = part_num;
+       fs_argv[3] = file_addr;
+       fs_argv[4] = (void *)file_path;
+
+       printf("runcmd: <%s %s %s %s %s>\n",fs_argv[0],fs_argv[1],fs_argv[2],fs_argv[3],fs_argv[4]);
+
+       if (!do_ext2load(cmdtp, 0, 5, fs_argv))
+               return 1;
+       return -ENOENT;
+}
+
+static int get_relfile_envaddr(cmd_tbl_t *cmdtp, const char *file_path, const char *envaddr_name)
+{
+       unsigned long file_addr;
+       char *envaddr;
+       char addr_buf[18];
+
+       envaddr = env_get(envaddr_name);
+
+       if (!envaddr){
+               printf("missing environment variable: %s\n", envaddr_name);
+               return -ENOENT;
+       }
+
+       if (strict_strtoul(envaddr, 16, &file_addr) < 0)
+               return -EINVAL;
+
+       sprintf(addr_buf, "%lx", file_addr);
+
+       return do_get_ext2(cmdtp, file_path, addr_buf);
+}
+
+static void kernel_fdt_overlay_apply( char *fdtoverlay)
+{
+       struct fdt_header *working_fdt;
+       char *fdtoverlay_addr_env;
+       ulong fdtoverlay_addr;
+       ulong fdt_addr;
+       int err;
+
+       /* Get the main fdt and map it */
+       fdt_addr = simple_strtoul(env_get("fdt_addr_r"), NULL, 16);
+       working_fdt = map_sysmem(fdt_addr, 0);
+       err = fdt_check_header(working_fdt);
+       if (err){
+               printf("Invalid fdt_addr_r for loading dtb\n");
+               return;
+       }
+       /* Get the specific overlay loading address */
+       env_set("fdtoverlay_addr_r","0x08000000");
+       fdtoverlay_addr_env =  env_get("fdtoverlay_addr_r");
+       if (!fdtoverlay_addr_env) {
+               printf("Invalid fdtoverlay_addr_r for loading overlays\n");
+               return;
+       }
+
+       fdtoverlay_addr = simple_strtoul(fdtoverlay_addr_env, NULL, 16);
+
+       /* Cycle over the overlay files and apply them in order */
+       do {
+               struct fdt_header *blob;
+               char *overlayfile;
+               char *end;
+               int len;
+
+               /* Drop leading spaces */
+               while (*fdtoverlay == ' ')
+                       ++fdtoverlay;
+
+               /* Copy a single filename if multiple provided */
+               end = strstr(fdtoverlay, " ");
+               if (end) {
+                       len = (int)(end - fdtoverlay);
+                       overlayfile = malloc(len + 1);
+                       strncpy(overlayfile, fdtoverlay, len);
+                       overlayfile[len] = '\0';
+               } else
+                       overlayfile = fdtoverlay;
+
+               if (!strlen(overlayfile))
+                       goto skip_overlay;
+
+               /* Load overlay file */
+               err = get_relfile_envaddr(NULL, overlayfile,
+                                         "fdtoverlay_addr_r");
+               if (err < 0) {
+                       printf("Failed loading overlay %s\n", overlayfile);
+                       goto skip_overlay;
+               }
+
+               /* Resize main fdt */
+               fdt_shrink_to_minimum(working_fdt, 8192);
+
+               blob = map_sysmem(fdtoverlay_addr, 0);
+               err = fdt_check_header(blob);
+               if (err) {
+                       printf("Invalid overlay %s, skipping\n",
+                              overlayfile);
+                       goto skip_overlay;
+               }
+
+               err = fdt_overlay_apply_verbose(working_fdt, blob);
+               if (err) {
+                       printf("Failed to apply overlay %s, skipping\n",
+                              overlayfile);
+                       goto skip_overlay;
+               }
+
+skip_overlay:
+               if (end)
+                       free(overlayfile);
+       } while ((fdtoverlay = strstr(fdtoverlay, " ")));
+}
+
 int rockchip_read_dtb_file(void *fdt)
 {
        int locate, ret;
@@ -584,7 +715,7 @@ int rockchip_read_dtb_file(void *fdt)
 #if defined(CONFIG_ANDROID_BOOT_IMAGE) && defined(CONFIG_OF_LIBFDT_OVERLAY)
        android_fdt_overlay_apply((void *)fdt);
 #endif
-
+       kernel_fdt_overlay_apply("/boot/overlays/default-dtb-overlay.dtbo");
        return 0;
 }
 #endif

build.sh 补丁


+function build_kernel_dtbo(){
+
+       fs_overlay_dir="$TOP_DIR/buildroot/board/rockchip/rk356x/huaqi/fs-overlay"
+       fs_dtbo_dir="$fs_overlay_dir/boot/overlays"
+       kernel_dts_dir="$TOP_DIR/kernel/arch/arm64/boot/dts/rockchip"
+       DTC="dtc-1.6.0"
+       dtbo_tools="$TOP_DIR/app/dtbo-tools/S03checkDTBO"
+
+       if [ -z "$RK_KERNEL_DTS_OVERLAYS" ];then
+               echo "Don't set RK_KERNEL_DTS_OVERLAYS, exit ..."
+               rm $fs_overlay_dir/etc/init.d/S03checkDTBO
+               rm $fs_overlay_dir/boot -r
+               return
+       fi
+
+       cd $kernel_dts_dir
+       echo "cd $kernel_dts_dir"
+
+       for dts in $RK_KERNEL_DTS_OVERLAYS
+       do      
+               if [ -e "$dts.dts" ];then
+                       $DTC -I dts -O dtb $dts.dts -o $dts.dtbo
+                       if [ "$?" = "0" ];then
+                               echo "[DTC]     $dts.dtbo"
+                       fi
+                       dtbo_table="$dtbo_table $dts.dtbo"
+               else
+                       echo "[DTC]     $dts.dtbo failed,no such file $dts.dts"
+               fi
+       done
+       
+       if [ -e "$fs_overlay_dir" ];then
+               mkdir -p "$fs_dtbo_dir"
+       fi
+
+       echo "Install `ls *.dtbo` to $fs_dtbo_dir"
+
+
+       cp $kernel_dts_dir/*.dtbo $fs_dtbo_dir
+
+       if [ -e "$dtbo_tools" ];then
+               sed  "s/dtbo_table=/dtbo_table=($dtbo_table)/g" $dtbo_tools > $fs_overlay_dir/etc/init.d/S03checkDTBO
+               echo "Install $dtbo_tools to $fs_overlay_dir/etc/init.d/S03checkDTBO"
+               chmod +x $fs_overlay_dir/etc/init.d/S03checkDTBO
+               cat $fs_overlay_dir/etc/init.d/S03checkDTBO | grep "dtbo_table="
+       else
+               echo "[WARN]: Not found $dtbo_tools!!!"
+       fi
+
+       finish_build
+}
+
 function build_kernel(){
        check_config RK_KERNEL_DTS RK_KERNEL_DEFCONFIG || return 0
 
@@ -670,8 +723,9 @@ function build_kernel(){
        fi
 
        build_check_power_domain
-
        finish_build
+
+       build_kernel_dtbo
 }
 
 function build_modules(){
@@ -1015,6 +1069,7 @@ function build_all(){
        check_security_condition
        build_loader
        build_kernel
+       build_kernel_dtbo
        build_toolchain
        build_rootfs ${RK_ROOTFS_SYSTEM:-buildroot}
        build_recovery
@@ -1272,6 +1327,7 @@ for option in ${OPTIONS}; do
                uefi) build_uefi ;;
                loader) build_loader ;;
                kernel) build_kernel ;;
+               dtbo) build_kernel_dtbo;;
                modules) build_modules ;;
                rootfs|buildroot|debian|yocto) build_rootfs $option ;;
                pcba) build_pcba ;;

BoardConfig-rk3568-evb1-ddr4-v10.mk 中新增环境变量

+export RK_KERNEL_DTS_OVERLAYS="rk3568-test rk3568-test2 rk3568-test3 rk3568-test4"

app/dtbo-tools/S03checkDTBO

build.sh中根据RK_KERNEL_DTS_OVERLAYS配置自动更新dtbo_table

#!/bin/sh

### BEGIN INIT INFO
# Provides:             check device tree overlay plugin
# Required-Start:
# Required-Stop:
# Default-Start:        S
# Default-Stop:
### END INIT INFO

OverlaysPath="/boot/overlays"
OverlaysHeader="rk3568-huaqi-overlays"
dtbo_table=
EXE_NAME=$0
switchGPIO="28 29 30"

function log()
{
	logger -s -t "[$EXE_NAME]" $@
}

function getSwichValue(){

	for i in $switchGPIO
	do
		value="$value`gpioget -l 2 $i`" 
	done

	val_hex=$(printf "%02x" $((2#$value)))
	echo "0x$val_hex"
}

start() {
	log "checkDTBO start ..."
	if [ -d "$OverlaysPath" ];then
		cd $OverlaysPath
	else
		log "Not found dir:$OverlaysPath,skip check device tree overlay!!!"
	fi
	
	if [ -z "${dtbo_table[0]}" ];then
		log "dtbo_table is empty,skip check device tree overlay!!!"
		return
	fi

	OLD_DTBO=`readlink default-dtb-overlay.dtbo`

	let swichValue="`getSwichValue`"

	if [ $swichValue -gt ${#dtbo_table[@]} ];then
		log "dtbo_table[0-${#dtbo_table[@]}]:<${dtbo_table[@]}>"
		log "Not define dtbo_table[$swichValue],exit..."
		return
	fi

	NEW_DTBO=${dtbo_table[$swichValue]}

	if [ ! -e "$NEW_DTBO" ];then
		log "No such file:$NEW_DTBO"
		log "skip set default-dtb-overlay.dtbo link to $NEW_DTBO!!!"
		syslog 
		return
	fi

	if  [ "$OLD_DTBO" != "$NEW_DTBO" ];then
		log "set default-dtb-overlay.dtbo link to $NEW_DTBO"
		ln -sf $NEW_DTBO default-dtb-overlay.dtbo
		sync
		reboot
	fi	
}

stop() {
	echo "checkDTBO stop ..."
}

restart() {
	echo "checkDTBO restart ..."
	stop
	start
}

case "$1" in
	start|stop|restart)
		"$1";;
	reload)
		# Restart, since there is no true "reload" feature.
		restart;;
	*)
		echo "Desc: Check device tree overlay plugin script"
		echo "Usage: $0 {start|stop|restart|reload}"
		exit 1
esac

标签:fs,addr,overlay,rockchip,dtbo,dts,build,overlays,fdt
From: https://www.cnblogs.com/Amumu1/p/18192755

相关文章

  • Rockchip RK3399 - DRM eDP调试
    ----------------------------------------------------------------------------------------------------------------------------开发板:NanoPC-T4开发板eMMC:16GBLPDDR3:4GB显示屏:15.6英寸HDMI接口显示屏u-boot:2023.04linux:6.3----------------------------------......
  • 世界读书日 | 开发者必读书单重磅来袭,华为云DTSE专家天团力荐
    本文分享自华为云社区《世界读书日|开发者必读书单重磅来袭,华为云DTSE专家天团力荐》,作者:华为云社区精选。春色恰如许,读书正当时。读书,就像解锁一把神秘钥匙,为开发者洞开新世界的大门,赋予他们破译复杂难题的能力、挑战未知领域的勇气。书页翻动间,开发者得以站在巨人的肩膀上,......
  • Kingbase-KDTS数据迁移mysql_to_kingbase
    一、启动kingbase服务cd/opt/Kingbase/ES/V8/Server/bin/启动 ./sys_ctlstart-D/opt/Kingbase/ES/V8/data/停止 ./sys_ctlstop-D/opt/Kingbase/ES/V8/data/ 二、启动kingbase自带的DTS数据同步服务cd  /opt/Kingbase/ES/V8/ClientTools/guitools/KDts/KDTS-WEB......
  • 光纤软件DTS的主要功能
    软件主要功能包括:测井曲线:提供调入模板、批量调入数据,导入射孔数据,测深、垂深数据,对井和地层参数进行设置。图形操作:提供设置图形框架,测井曲线进行深度、时间阶段,选择数据拖动曲线进行图形操作。数据处理:提供选定静温、选定流温、深度校正和时间校正等操作。三维图形:提供三维......
  • 六、使用jsPlumb实现流程图--Overlays使用
    一、Overlay的功能叠层(Overlay)可以是任意的DOM元素,用于叠加在Connection或Endpoint元素上--绝大部分都是用于叠加在线条上。jsPlumb把Overlay分为了五类:Arrow、Label、PlainArrow、Diamond、Custom。除了Custom和Label类型,其他三类就是jsPlumb提供的可以直接使用的图形;Label类......
  • dts overlay
    参考资料:https://blog.csdn.net/weixin_45668170/article/details/130967094https://wenku.csdn.net/column/5s90hefd57 一个常规的设备树主要由源文件.dts和头文件.dtsi以及一些.h文件共同编译出可以由Linux系统加载的.dtb二进制文件,内核就会在初始化后根据uboot加......
  • 设备树DTS简介及DTS基本语法
    参考资料:https://www.bilibili.com/video/BV1fJ411i7PB?p=16&vd_source=432ba293ecfc949a4174ab91ccc526d6 在linux3.1版本引入设备树设备树用来描述板级信息编译设备树:makeall//全编译,包括内核镜像和dtbmakedtbs//编译所有的设备树文件makeimx6ull-14x1......
  • Rockchip RK3399 - DRM vop驱动程序
    ----------------------------------------------------------------------------------------------------------------------------开发板:NanoPC-T4开发板eMMC:16GBLPDDR3:4GB显示屏:15.6英寸HDMI接口显示屏u-boot:2023.04linux:6.3----------------------------------......
  • Rockchip RK3399 - DRM edp驱动程序
    ----------------------------------------------------------------------------------------------------------------------------开发板:NanoPC-T4开发板eMMC:16GBLPDDR3:4GB显示屏:15.6英寸HDMI接口显示屏u-boot:2023.04linux:6.3----------------------------------......
  • rdtsc时间戳
    【tsc】timestampcounter【性能】大概只要chrono接口的1/6时延【测试程序】#include<x86intrin.h>#include<chrono>#include<cstdio>usingnamespacestd::chrono;intmain(){u_int64_tbegin=duration_cast<nanoseconds>(steady_clock::now().tim......