系统移植 androidS

提示:本文为系统的本地化文档,想要按照本文档完成系统的移植,需要你提前准备好Android的原生SDK。


前言

提示:感谢北京迅为电子

感谢【北京迅为电子】,本文是参考北京迅为电子的相关文档总结而成。


常用ubuntu操作
关在虚拟盘:

提示:以下是本篇文章正文内容

第一部分 前沿准备

一、基本准备

ubuntu盘符挂载

mkfs.ext4 /dev/sdb1
sudo mount -t ext4 -o rw,relatime /dev/sdb /work

git配置

git config --global user.name “user”
git config --global user.email “user@user.com”
git config --list

二、环境安装

环境配置-一键安装

sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig

执行./install.sh

点此下载

第二部分 AOSP

一、AOSP官网

android官网

二、代码拉取

git clone https://gerrit-googlesource.lug.ustc.edu.cn/git-repo
./repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-security-11.0.0_r54
./repo sync -j4

三、编译

source build/envsetup.sh;lunch aosp_x86_64-eng;make -j4
ls out/target/product/generic_x86_64/

镜像说明

简称名称说明
系统镜像system.imgAndroid 系统主要的目录和文件,通过 init.c进行解析并 mount 挂载到/system 目录下。
用户镜像userdata.imgAndroid 系统中存放用户数据的,通过 init.c 进行解析并 mount 挂载到/data 目录下。
根文件系统ramdisk.img一些启动 Android 系统的重要文件,比如init.rc

四、模拟器运行

source build/envsetup.sh;lunch aosp_x86_64-eng;emulator
cd out/host/linux-x86/bin/;./adb shell

第三部分 芯片原厂代码

一、厂家官网

瑞芯微电子

二、代码获取

(之后补充)

三、代码编译

# 快捷指令
source javaenv.sh;java -version;source build/envsetup.sh;lunch rk3568_r-userdebug;./build.sh -AUCKu

# 清除原先编译内容
make clean

# 初始化编译环境
source javaenv.sh;java -version;source build/envsetup.sh;lunch rk3568_r-userdebug
source javaenv.sh;java -version;source build/envsetup.sh;lunch topeet_rk3568_r-userdebug

# 获取配置文件Uboot
get_build_var PRODUCT_UBOOT_CONFIG

##############
# 编译指令
##############

# Uboot
./build.sh -U
# Kernel
./build.sh -CKA
# Android
./build.sh -AUCKu

# 一键全编
source javaenv.sh;java -version;source build/envsetup.sh;lunch topeet_rk3568_r-userdebug;./build.sh -AUCKu

四、文件烧录

RK3568烧写指南

第四部分 源码本地化配置

一、快速本地化

itop_rk3568_r为例

前置方法

source javaenv.sh;java -version;source build/envsetup.sh;lunch topeet_rk3568_r-userdebug
1.Android

新建产品目录-> itop_rk3568_r

cp -r device/rockchip/rk356x/rk3568_r  device/rockchip/rk356x/topeet_rk3568_r
mv device/rockchip/rk356x/topeet_rk3568_r/rk3568_r.mk device/rockchip/rk356x/topeet_rk3568_r/topeet_rk3568_r.mk

修改lunch-> device/rockchip/rk356x/AndroidProducts.mk

PRODUCT_MAKEFILES := \
		...
         $(LOCAL_DIR)/rk3568_r/rk3568_r.mk \
         $(LOCAL_DIR)/rk3566_eink/rk3566_eink.mk \
-        $(LOCAL_DIR)/rk3566_einkw6/rk3566_einkw6.mk
+        $(LOCAL_DIR)/rk3566_einkw6/rk3566_einkw6.mk \
+        $(LOCAL_DIR)/topeet_rk3568_r/topeet_rk3568_r.mk
COMMON_LUNCH_CHOICES := \
	...
     rk3566_einkw6-userdebug \
-    rk3566_einkw6-user
+    rk3566_einkw6-user \
+    topeet_rk3568_r-userdebug \
+    topeet_rk3568_r

device/rockchip/rk356x/topeet_rk3568_r/topeet_rk3568_r.mk

 include device/rockchip/common/build/rockchip/DynamicPartitions.mk
-include device/rockchip/rk356x/rk3568_r/BoardConfig.mk
+include device/rockchip/rk356x/topeet_rk3568_r/BoardConfig.mk
 include device/rockchip/common/BoardConfig.mk
@@ -32,10 +33,10 @@ DEVICE_PACKAGE_OVERLAYS += $(LOCAL_PATH)/../overlay
 
 PRODUCT_CHARACTERISTICS := tablet
 
-PRODUCT_NAME := rk3568_r
-PRODUCT_DEVICE := rk3568_r
+PRODUCT_NAME := topeet_rk3568_r
+PRODUCT_DEVICE := topeet_rk3568_r
 PRODUCT_BRAND := rockchip
-PRODUCT_MODEL := rk3568_r
+PRODUCT_MODEL := topeet_rk3568_r
 PRODUCT_MANUFACTURER := rockchip
 PRODUCT_AAPT_PREF_CONFIG := mdpi
2.uboot
# 新建deconfig文件-> itop_rk3568_defconfig
cp u-boot/configs/rk3568_defconfig u-boot/configs/itop_rk3568_defconfig

# 新建设备树-> itop_rk3568-evb.dts
cp u-boot/arch/arm/dts/rk3568-evb.dts  u-boot/arch/arm/dts/itop_rk3568-evb.dts

添加编译脚本提示语:u-boot/make.sh

	echo "  ./make.sh evb-rk3399               --- build for evb-rk3399_defconfig"
(+)	echo "	./make.sh itop_rk3568	           --- build for itop_rk3568_defconfig"

修改产品配置:device/rockchip/rk356x/topeet_rk3568_r/BoardConfig.mk

-PRODUCT_UBOOT_CONFIG ?= rk3568
+PRODUCT_UBOOT_CONFIG ?= itop_rk3568

修改设备树:u-boot/configs/itop_rk3568_defconfig

-CONFIG_DEFAULT_DEVICE_TREE="rk3568-evb"
+CONFIG_DEFAULT_DEVICE_TREE="itop_rk3568-evb"
3.kernel
# 新建deconfig文件-> rockchip_defconfig
cp kernel/arch/arm64/configs/rockchip_defconfig kernel/arch/arm64/configs/itop_rockchip_defconfig

# 新建deconfig文件-> itop_android-11.config
cp kernel/kernel/configs/android-11.config kernel/kernel/configs/itop_android-11.config

# 新建设备树-> 
cp kernel/arch/arm64/boot/dts/rockchip/rk3568-evb1-ddr4-v10.dts kernel/arch/arm64/boot/dts/rockchip/itop_rk3568-evb1-ddr4-v10.dts 

配置编译规则:device/rockchip/rk356x/topeet_rk3568_r/BoardConfig.mk

-PRODUCT_KERNEL_CONFIG ?= rockchip_defconfig
+PRODUCT_KERNEL_CONFIG ?= itop_rockchip_defconfig

配置编译规则:device/rockchip/common/BoardConfig.mk

ifeq ($(BUILD_WITH_GO_OPT), true)
PRODUCT_KERNEL_CONFIG += android-11-go.config
else
+PRODUCT_KERNEL_CONFIG += itop_android-11.config
endif

添加设备树编译规则:device/rockchip/rk356x/rk3568_r/BoardConfig.mk

+PRODUCT_KERNEL_DTS := itop_rk3568-evb1-ddr4-v10

二、详细配置

1.修改启动提示语

u-boot/arch/arm/dts/itop_rk3568-evb.dts

-       model = "Rockchip RK3568 Evaluation Board";
+       model = "Rockchip ITOP-RK3568 Evaluation Board";
2.修改开机计时

u-boot/configs/itop_rk3568_defconfig

-CONFIG_BOOTDELAY=0
+CONFIG_BOOTDELAY=10

第四部分 uboot

一、编译&运行

清除现有编译输出文件

# 快速指令 查看配置
source javaenv.sh;java -version;source build/envsetup.sh;lunch rk3568_r-userdebug;get_build_var PRODUCT_UBOOT_CONFIG

# 清除编译记录
make clean

# 初始化环境
source javaenv.sh;java -version;
source build/envsetup.sh;
lunch rk3568_r-userdebug;

# 获取默认配置文件
get_build_var PRODUCT_UBOOT_CONFIG

# 编译命令
./build.sh -U

编译输出文件

u-boot
├── rk356x_spl_loader_v1.10.111.bin
├── spl
├── tpl
├── u-boot.bin
├── uboot.img
├── u-boot.lds
├── u-boot.map
├── u-boot-nodtb.bin
├── u-boot.srec
└── u-boot.sym

二、编译脚本解析

build.sh脚本解析

#!/bin/bash
usage()
{
   echo "USAGE: [-U] [-CK] [-A] [-p] [-o] [-u] [-v VERSION_NAME]  "
    echo "No ARGS means use default build option                  "
    echo "WHERE: -U = build uboot                                 "
    echo "       -C = build kernel with Clang                     "
    echo "       -K = build kernel                                "
    echo "       -A = build android                               "
    echo "       -p = will build packaging in IMAGE      "
    echo "       -o = build OTA package                           "
    echo "       -u = build update.img                            "
    echo "       -v = build android with 'user' or 'userdebug'    "
    echo "       -d = huild kernel dts name    "
    echo "       -V = build version    "
    echo "       -J = build jobs    "
    exit 1
}

while getopts "UCKABpouv:d:V:J:" arg
do
    case $arg in
        U)
            echo "will build u-boot"
            BUILD_UBOOT=true
        ?)
            usage ;;
    esac
done

# build uboot
if [ "$BUILD_UBOOT" = true ] ; then
echo "start build uboot"
cd u-boot && make clean &&  make mrproper &&  make distclean \
&& ./make.sh $UBOOT_DEFCONFIG && cd -
if [ $? -eq 0 ]; then
    echo "Build uboot ok!"
else
    echo "Build uboot failed!"
    exit 1
fi
fi

三、Uboot烧录

编译

./build.sh -U

u-boot.bin添加头部(IVT、DCD)成为u-boot.imx

bootargs/cmdline查看的三种方法

①ctrl+C后输入pri
bootargs=storagemedia=emmc androidboot.storagemedia=emmc
androidboot.mode=normal androidboot.dtb_idx=0 androidboot.dtbo_idx=0
②内核启动后查看Kernel command line
Kernel command line: storagemedia=emmc
androidboot.storagemedia=emmc androidboot.mode=normal
androidboot.dtb_idx=0 androidboot.dtbo_idx=0
androidboot.verifiedbootstate=orange androidboot.slot_suffix=
androidboot.serialno=2353afe6e6ffd5dc console=ttyFIQ0
androidboot.baseband=N/A androidboot.wificountrycode=CN
androidboot.veritymode=enforcing androidboot.hardware=rk30board
androidboot.console=ttyFIQ0 androidboot.verifiedbootstate=orange
firmware_class.path=/vendor/etc/firmware init=/init rootwait ro
loop.max_part=7 androidboot.selinux=permissive buildvariant=userdebug
earlycon=uart8250,mmio32,0xfe660000
androidboot.boot_devices=fe310000.sdhci,fe330000.nandc
③内核启动后,切到root执行cat /proc/cmdline

四、u-boot本地化

本地化config文件

./make.sh -h
./make.sh rk3568
make rk3568_defconfig #需要本地化的config文件
chmod 777 rk3568_defconfig #可以让他变绿
configs/${ARG_BOARD}_defconfig

编译方法
u-boot执行

./build.sh -h

根文件执行
构建环境:

source javaenv.sh;source build/envsetup.sh;lunch 55;./build.sh -U

build.sh 调用 u-boot/make.sh

build.sh
UBOOT_DEFCONFIG=`get_build_var PRODUCT_UBOOT_CONFIG`

device/rockchip/rk356x/rk3568_r/BoardConfig.mk
PRODUCT_UBOOT_CONFIG := rk3568

新建defconfig

cp rk3568_defconfig itop_rk3568_defconfig
①u-boot内使用
传参为:itop_rk3568
增加./make.sh -h打印信息
echo "	./make.sh itop_rk3568               --- build for itop_rk3568_defconfig"
②根目录使用
device/rockchip/rk356x/rk3568_r/BoardConfig.mk
PRODUCT_UBOOT_CONFIG := itop_rk3568

设备树本地化

1.现有的设备树
u-boot/arch/arm/dts
rk3568.dtsi  rk3568-evb.dts  rk3568-pinctrl.dtsi  rk3568-spi-nand.dts  rk3568-u-boot.dtsi
编译后多出设备树
rk3568-evb.dtb
u-boot使用的设备树文件rk3568-evb.dts

2.新建一份设备树
u-boot/arch/arm/dts
cp rk3568-evb.dts itop-rk3568-evb.dts

修改编译位置
u-boot/arch/arm/dts/Makefile
dtb-$(CONFIG_ARCH_ROCKCHIP) += \
	rk3036-sdk.dtb \
	rk3066a-mk808.dtb \
	...
	rk3399-puma-ddr1866.dtb \
	rv1108-evb.dtb

u-boot/configs/rk3568_defconfig
CONFIG_DEFAULT_DEVICE_TREE="rk3568_evb"

五、u-boot的一些配置

1.修改启动名称

u-boot/arch/arm/dts/rk3568-evb.dts
/ {
	model = "Rockchip RK3568 Evaluation Board";
	compatible = "rockchip,rk3568-evb", "rockchip,rk3568";

	adc-keys {
		compatible = "adc-keys";
		io-channels = <&saradc 0>;
		io-channel-names = "buttons";
		keyup-threshold-microvolt = <1800000>;
		u-boot,dm-spl;
		status = "okay";

		volumeup-key {
			u-boot,dm-spl;
			linux,code = <KEY_VOLUMEUP>;
			label = "volume up";
			press-threshold-microvolt = <9>;
		};
	};
};

2.开发板uboot倒计时

①配置修改
u-boot/configs/rk3568_defconfig
CONFIG_BOOTDELAY=10  10秒
②手动修改
setenv bootdelay 10
saveenv
添加环境变量存储位置
make menuconfig
Environment  --->Select the location of the environment (Environment in an MMC device)
./make.sh直接编译

六、瑞芯微特殊机制

1.rk uboot启动时用到两份设备树(uboot+kernel)

make menuconfig
ARM architecture
Using dtb from Kernel/resource for U-Boot
(dts/kern.dtb) Embeded kernel dtb file path

//内核设备树的加载
[16:38:41.482]Found DTB in boot part
[16:38:41.482]DTB: rk-kernel.dtb
//对应内核设备树中的model属性
[16:38:41.582]Model: Rockchip RK3568 EVB1 DDR4 V10 Board

u-boot/arch/arm/mach-rockchip/board.c

int board_init(void)
{
	board_debug_init();

#ifdef CONFIG_USING_KERNEL_DTB
	...//在此之前使用uboot设备树,把关键(存储等)设备初始化完成
	init_kernel_dtb();//读取kernel dtb
	...
}

u-boot/arch/arm/mach-rockchip/kernel_dtb.c

int init_kernel_dtb(void)
{
	//从env中获取到fdt_addr1_r设备树文件的加载地址
	if (gd->ram_size <= SZ_128M)
		fdt_addr = env_get_ulong("fdt_addr1_r", 16, 0);
	//读取设备树文件,建表绑定device-driver
	ret = rockchip_read_dtb_file((void *)fdt_addr);

	ufdt_blob = (void *)gd->fdt_blob;
	gd->fdt_blob = (void *)fdt_addr;//指向内核中的设备树文件

	hotkey_run(HK_FDT);
	...
}

u-boot/arch/arm/mach-rockchip/boot_rkimg.c

// 路径:CONFIG_ROCKCHIP_EARLY_DISTRO_DTB_PATH
int rockchip_read_dtb_file(void *fdt_addr)
{
	/* 如果资源为空,从默认存储设备去读取 */
	resource_traverse_init_list();
	...
	ret = rockchip_read_resource_dtb(fdt_addr, &hash, &hash_size);
	...
}

u-boot/arch/arm/mach-rockchip/resource_img.c

int rockchip_read_resource_dtb(void *fdt_addr, char **hash, int *hash_size)
{
	//硬件引脚控制设备树的选择
#ifdef CONFIG_ROCKCHIP_HWID_DTB
	file = resource_read_hwid_dtb();
#endif
	//默认的#define DEFAULT_DTB_FILE		"rk-kernel.dtb"
	if (!file)
		file = get_file_info(DEFAULT_DTB_FILE);//
	ret = rockchip_read_resource_file(fdt_addr, file->name, 0, 0);
	*hash = file->hash;
	*hash_size = file->hash_size;
	printf("DTB: %s\n", file->name);
	return 0;
}

第五部分Kernel

一、编译&运行

构建环境

source javaenv.sh;source build/envsetup.sh;lunch 55;

编译的两种方法:
方法一:独立编译内核

./build.sh -CKA

方法二:编译boot.img
使用本方法编译的产物可以直接烧入android系统

make ARCH=arm64 CC=../prebuilts/clang/host/linux-x86/clang-r383902b/bin/clang LD=../prebuilts/clang/host/linux-x86/clang-r383902b/bin/ld.lld rockchip_defconfig android-11.config && make ARCH=arm64 CC=../prebuilts/clang/host/linux-x86/clang-r383902b/bin/clang LD=../prebuilts/clang/host/linux-x86/clang-r383902b/bin/ld.lld BOOT_IMG=../rockdev/Image-rk3568_r/boot.img rk3568-evb1-ddr4-v10.img

编译过程分析

make ARCH=arm64
# 编译器路径
CC=../prebuilts/clang/host/linux-x86/clang-r383902b/bin/clang
# 链接器路径
LD=../prebuilts/clang/host/linux-x86/clang-r383902b/bin/ld.lld 
# 内核源码配置config
rockchip_defconfig android-11.config

make ARCH=arm64
CC=../prebuilts/clang/host/linux-x86/clang-r383902b/bin/clang
LD=../prebuilts/clang/host/linux-x86/clang-r383902b/bin/ld.lld
# 覆盖boot.img
BOOT_IMG=../rockdev/Image-rk3568_r/boot.img rk3568-evb1-ddr4-v10.img

二、源码本地化

查看现有文件

执行编译指令查看defconfig

在build.sh 中添加输出详细信息
set -x

build.sh
:cd kernel && make clean && make $ADDON_ARGS ARCH=$KERNEL_ARCH $KERNEL_DEFCONFIG
:KERNEL_DEFCONFIG=`get_build_var PRODUCT_KERNEL_CONFIG`

get_build_var PRODUCT_KERNEL_CONFIG
:rockchip_defconfig android-11.config
find -name rockchip_defconfig
:./arch/arm/configs/rockchip_defconfig
:★./arch/arm64/configs/rockchip_defconfig

find -name android-11.config
:./configs/rockchip/android-11.config
:★./kernel/configs/android-11.config

config文件本地化

//新增本地文件
kernel/arch/arm64/configs/:
cp rockchip_defconfig itop_rockchip_defconfig
kernel/kernel/configs/:
cp android-11.config itop_android-11.config


//配置编译规则
device/:grep "rockchip_defconfig" -rw
★rockchip/rk356x/BoardConfig.mk:PRODUCT_KERNEL_CONFIG ?= rockchip_defconfig
PRODUCT_KERNEL_CONFIG ?= rockchip_defconfig

device/:grep "android-11.config" -rw
★rockchip/common/BoardConfig.mk:PRODUCT_KERNEL_CONFIG += android-11.config
PRODUCT_KERNEL_CONFIG += android-11.config

//检验方法
get_build_var PRODUCT_KERNEL_CONFIG

设备树文件本地化

默认赋值:
device/rockchip/rk356x/BoardConfig.mk
PRODUCT_KERNEL_DTS ?= rk3568-evb1-ddr4-v10
实际复制:
device/rockchip/rk356x/rk3568_r/BoardConfig.mk
PRODUCT_KERNEL_DTS := rk3568-evb1-ddr4-v10

验证方法
./build.sh -CAK

第六部分 电源配置

专业名词

PMIC:电源管理

一、RK809电源芯片

DCDC5、LDO9、SWITCH2、RTC1、CODEC*1

DCDC特性介绍:

  • PWM:波纹瞬态较好,出于对系统稳定性,上电时用PWM
  • PFM:效率高

功能

1.regulator-寄存器配置功能
CONFIG_REGULATOR_RK808
kernel/drivers/regulator/rk808-regulator.c

2.RTC
CONFIG_RTC_RK808
kernel/drivers/rtc/rtc-rk808.c

3.gpio,当作pinctrl
CONFIG_PINCTRL_RK805
kernel/drivers/pinctrl/pinctrl-rk805.c

4.pwrkey按键
CONFIG_MFD_RK808
kernel/drivers/mfd/rk808.c

5.clk功能
CONFIG_INPUT_RK805_PWRKEY
kernel/drivers/input/misc/rk805-pwrkey.c

6.codec
CONFIG_COMMON_CLK_RK808
kernel/drivers/clk/clk-rk808.c

PMIC管理部分

RK809引脚LINEGPIO复用功能
SDAI2C0_SDA_PMICGPIO0_B2_uI2C0_SDA
SCLI2C0_SCL_PMICGPIO0_B1_uI2C0_SCL
INTPMIC_INT_LGPIO0_A3_u
SLEEPPMIC_SLEEP_HGPIO0_A2_d
PWRONRK809_PWRON按键PWRON(按下接地)
RESETBRESETn按键RESET(按下接地)
EXT_ENEXT_EN

二、电源芯片基本配置

设备树

kernel/arch/arm64/boot/dts/rockchip/rk3568-evb1-ddr4-v10.dts
#include "rk3568-evb1-ddr4-v10.dtsi"
#include "rk3568-android.dtsi"

kernel/arch/arm64/boot/dts/rockchip/rk3568-evb1-ddr4-v10.dtsi
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/rockchip.h>
#include "rk3568.dtsi"
#include "rk3568-evb.dtsi"

kernel/arch/arm64/boot/dts/rockchip/rk3568-evb.dtsi
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pwm/pwm.h>
#include <dt-bindings/pinctrl/rockchip.h>
#include <dt-bindings/input/rk-input.h>
#include <dt-bindings/display/drm_mipi_dsi.h>
#include <dt-bindings/sensor-dev.h>
&i2c0 {
	status = "okay";
	rk809: pmic@20 {	//rk809:节点的标签    pmic:节点名称   @20:有可能是寄存器的首地址或者器件地址
		compatible = "rockchip,rk809";//匹配驱动的,不能修改
		reg = <0x20>;//rk809器件地址
		interrupt-parent = <&gpio0>;	//对应GPIO0_A3_u
		interrupts = <3 IRQ_TYPE_LEVEL_LOW>;

		pinctrl-names = "default", "pmic-sleep",
				"pmic-power-off", "pmic-reset";
		pinctrl-0 = <&pmic_int>;
		pinctrl-1 = <&soc_slppin_slp>, <&rk817_slppin_slp>;
		pinctrl-2 = <&soc_slppin_gpio>, <&rk817_slppin_pwrdn>;
		pinctrl-3 = <&soc_slppin_gpio>, <&rk817_slppin_rst>;

		rockchip,system-power-controller;
		wakeup-source;
		#clock-cells = <1>;
		clock-output-names = "rk808-clkout1", "rk808-clkout2";
		//fb-inner-reg-idxs = <2>;
		/* 1: rst regs (default in codes), 0: rst the pmic */
		pmic-reset-func = <0>;
		/* not save the PMIC_POWER_EN register in uboot */
		not-save-power-en = <1>;
	};
};

三、电压域配置

kernel/arch/arm64/boot/dts/rockchip/rk3568-evb.dtsi
电压域,决定IO输出电压
3.3V/1.8V

RK3566/RK3568有10个独立IO电压域

种类数量电压域说明
固定2PMUIO[0:1]PMUIO1固定为3V3
可调节7PMUIO[2]、VCCIO[1]、VCCIO[3:7]可选择1V8或者3V3
特定1VCCIO[2]GPIO决定引脚(FLASH_VOL_SEL/GPIO0_A7 H:3.3V L:1.8V)

引脚分布

电压域DescrptionLine
PMUIO0
PMUIO1(固定)VCC3V3_PMU
PMUIO2(1V8/3V3)VCC3V3_PMU
VCCIO3(1V8/3V3)VCCIO_ACODEC
VCCIO2FLASH_VOL_SELVCCIO_FLASH >>> VCC_1V8(VCC_3V3备选)
VCCIO3(1V8/3V3)VCCIO_SD
VCCIO4(1V8/3V3)VCCIO4 >>> VCC_1V8(VCC_3V3备选)
VCCIO5(1V8/3V3)VCC_3V3
VCCIO6(1V8/3V3)VCCIO6 >>> VCC_1V8(VCC_3V3备选)
VCCIO7(1V8/3V3)VCC_3V3

接线配置

LineRK809引脚
VCC3V3_PMULDO6
VCCIO_ACODECLDO4(Codec vddio)
VCCIO_SDLDO5
VCC_1V8BUCK5(DCDC5)
VCC_3V3SWOUT1

电压域配置设备树

&pmu_io_domains {
	status = "okay";
	pmuio2-supply = <&vcc3v3_pmu>;
	vccio1-supply = <&vccio_acodec>;
	vccio3-supply = <&vccio_sd>;
	vccio4-supply = <&vcc_1v8>;
	vccio5-supply = <&vcc_3v3>;
	vccio6-supply = <&vcc_1v8>;
	vccio7-supply = <&vcc_3v3>;
};

四、电源芯片输出配置

电源芯片RK809配置
RK809电源供电

电源电源接口Line
VCC5LDO1VDDA0V9_IMAGE
LDO2VDDA_0V9
LDO3VDDA0V9_PMU
VCC6LDO4VCCIO_ACODEC
LDO5VCCIO_SD
LDO6VCC3V3_PMU
VCC7LDO7VCCA_1V8
LDO8VCCA1V8_PMU
LDO9VCCA1V8_IMAGE
&i2c0 {
	status = "okay";
	rk809: pmic@20 {
		compatible = "rockchip,rk809";
		reg = <0x20>;
		interrupt-parent = <&gpio0>;
		interrupts = <3 IRQ_TYPE_LEVEL_LOW>;

		pinctrl-names = "default", "pmic-sleep",
				"pmic-power-off", "pmic-reset";
		pinctrl-0 = <&pmic_int>;
		pinctrl-1 = <&soc_slppin_slp>, <&rk817_slppin_slp>;
		pinctrl-2 = <&soc_slppin_gpio>, <&rk817_slppin_pwrdn>;
		pinctrl-3 = <&soc_slppin_gpio>, <&rk817_slppin_rst>;

		rockchip,system-power-controller;
		wakeup-source;
		#clock-cells = <1>;
		clock-output-names = "rk808-clkout1", "rk808-clkout2";
		//fb-inner-reg-idxs = <2>;
		/* 1: rst regs (default in codes), 0: rst the pmic */
		pmic-reset-func = <0>;
		/* not save the PMIC_POWER_EN register in uboot */
		not-save-power-en = <1>;

		vcc1-supply = <&vcc3v3_sys>;
		vcc2-supply = <&vcc3v3_sys>;
		vcc3-supply = <&vcc3v3_sys>;
		vcc4-supply = <&vcc3v3_sys>;
		vcc5-supply = <&vcc3v3_sys>;
		vcc6-supply = <&vcc3v3_sys>;
		vcc7-supply = <&vcc3v3_sys>;
		vcc8-supply = <&vcc3v3_sys>;
		vcc9-supply = <&vcc3v3_sys>;

		regulators {
			vdd_logic: DCDC_REG1 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <500000>;
				regulator-max-microvolt = <1350000>;
				regulator-init-microvolt = <900000>;
				regulator-ramp-delay = <6001>;
				regulator-initial-mode = <0x2>;
				regulator-name = "vdd_logic";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};
			
			vcc3v3_pmu: LDO_REG6 {//LDO6	3.3 休眠不断电
				regulator-always-on;//运行的时候,这一路电源不允许关闭
				regulator-boot-on;//使能这一路电源
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3300000>;
				regulator-name = "vcc3v3_pmu";
				regulator-state-mem {
					regulator-on-in-suspend;
					regulator-suspend-microvolt = <3300000>;
				};
			};
			vccio_acodec: LDO_REG4 {//LDO4 3.3 休眠断电
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3300000>;
				regulator-name = "vccio_acodec";
				regulator-state-mem {//休眠时断电
					regulator-off-in-suspend;
				};
			};
			vcc_1v8: DCDC_REG5 {//DCDC5 1.8 休眠断电
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-name = "vcc_1v8";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};
			vccio_sd: LDO_REG5 {//LDO5 1.8-3.3 休眠断电
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <3300000>;
				regulator-name = "vccio_sd";
				regulator-state-mem {//休眠时断电
					regulator-off-in-suspend;
				};
			};
			vcc_1v8: DCDC_REG5 {//DCDC5 1.8 休眠断电
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-name = "vcc_1v8";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};
			vcc_3v3: SWITCH_REG1 {//SWITCH1 3.3 休眠断电
				regulator-always-on;
				regulator-boot-on;
				regulator-name = "vcc_3v3";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};
		};
	};
};

其他设备配置

&sdmmc0 {
	max-frequency = <150000000>;
	supports-sd;
	bus-width = <4>;
	cap-mmc-highspeed;
	cap-sd-highspeed;
	disable-wp;
	sd-uhs-sdr104;
	vmmc-supply = <&vcc3v3_sd>;
	vqmmc-supply = <&vccio_sd>;
	pinctrl-names = "default";
	pinctrl-0 = <&sdmmc0_bus4 &sdmmc0_clk &sdmmc0_cmd &sdmmc0_det>;
	status = "okay";
};

第七部分 调试串口

一、UART配置

电路图
在这里插入图片描述

本地化设备树文件
kernel/arch/arm64/boot/dts/rockchip/rk3568-evb1-ddr4-v10.dts

#include "rk3568-evb1-ddr4-v10.dtsi"
#include "rk3568-android.dtsi"

kernel/arch/arm64/boot/dts/rockchip/rk3568-android.dtsi

#include "rk3568.dtsi"
fiq-debugger {
	compatible = "rockchip,fiq-debugger";
	rockchip,serial-id = <2>;//★使用串口2
	rockchip,wake-irq = <0>;
	/* If enable uart uses irq instead of fiq */
	rockchip,irq-mode-enable = <1>;
	rockchip,baudrate = <115200>; //★波特率115200
	interrupts = <GIC_SPI 252 IRQ_TYPE_LEVEL_LOW>;
	
	//★修改串口2至串口1还需要修改pinctrl,将串口1的引脚设置为串口
	pinctrl-names = "default";//对应到->pinctrl-0
	pinctrl-0 = <&uart2m0_xfer>;
	status = "okay";
};

修改串口2至串口1还需要修改pinctrl,将串口1的引脚设置为串口

在这里插入图片描述

底板Line核心板Line
UART2_RX_M0_DEBUGUART2_RX_M0-GPIO0_D0_u
UART2_TX_M0_DEBUGUART2_TX_M0-GPIO0_D1_u

kernel/arch/arm64/boot/dts/rockchip/rk3568.dtsi

#include "rk3568-pinctrl.dtsi"

二、pinctrl引脚配置

kernel/arch/arm64/boot/dts/rockchip/rk3568-pinctrl.dtsi

uart2 {
	/omit-if-no-ref/
	uart2m0_xfer: uart2m0-xfer {//★GPIO0-PD0、GPIO0-PD1
		rockchip,pins =
			/* uart2_rxm0 */
			<0 RK_PD0 1 &pcfg_pull_up>,	//GPIO0这一组D0引脚RK_PD0,上拉,1代表使用GPIO的第1个复用(串口)
			/* uart2_txm0 */
			<0 RK_PD1 1 &pcfg_pull_up>;	//GPIO0这一组D1引脚RK_PD0,上拉
	};

	/omit-if-no-ref/
	uart2m1_xfer: uart2m1-xfer {
		rockchip,pins =
			/* uart2_rxm1 */
			<1 RK_PD6 2 &pcfg_pull_up>,
			/* uart2_txm1 */
			<1 RK_PD5 2 &pcfg_pull_up>;
	};
};

查看函数复用
kernel/include/dt-bindings/pinctrl/rockchip.h

#define RK_GPIO0		0
#define RK_PD0			24
#define RK_PD1			25
#define RK_FUNC_GPIO	0
#define RK_FUNC_0		0
#define RK_FUNC_1		1
#define RK_FUNC_2		2

或者打开

《Technical Reference Manual》
<Chapter 3 General Register Files (GRF) >
< 3.3 PMU_GRF Register Description >

设置复用的寄存器会带有_IOMUX_后缀,找到GPIO0D相关的位置。
设置复用的寄存器
PMU_GRF_GPIO0D_IOMUX_L

BitAttrReset ValueDescrption
31:16RW0x0000写使能(0:禁用 1:启用)
15RO0x0reserved
14:12RW0x0gpio0d3_sel(1:GPIO0_D3)
11:7RO0x0reserved
6:4RW0x0gpio0d1_sel (3’h0: GPIO0_D1 ★3’h1: UART2_TXM0
3RO0x0reserved
2:0RW0x0gpio0d0_sel (3’h0: GPIO0_D0 ★3’h1: UART2_RXM0

第八部分 device目录

一、目录结构

device
├── common
├── generic
│   ├── arm64
│   ├── armv7-a-neon
│   ├── x86
│   └── x86_64
├── rockchip//公司
│   ├── common
│   ├── rk3288 //SOC
│   ├── rk356x //SOC
│   │   ├── Android.mk
│   │   ├── ★AndroidProducts.mk
│   │   ├── ★BoardConfig.mk
│   │   ├── ★device.mk
│   │   ├── init.recovery.rk30board.rc
│   │   ├── init.rk356x.rc
│   │   ├── overlay
│   │   ├── package_performance.xml
│   │   ├── public.libraries.txt
│   │   ├── ★rk3568_r	//产品
│   │   │   ├── ★AndroidBoard.mk
│   │   │   ├── Android.mk
│   │   │   ├── ★BoardConfig.mk
│   │   │   ├── bt_vendor.conf
│   │   │   ├── config.cfg
│   │   │   ├── config.cfg_ab
│   │   │   ├── config.cfg_ab_gki
│   │   │   ├── dt-overlay.in
│   │   │   ├── media_profiles_default.xml
│   │   │   ├── ota
│   │   │   ├── recovery.fstab
│   │   │   ├── recovery.fstab_AB
│   │   │   └── ★rk3568_r.mk
│   │   ├── rk356x.prop

device/rockchip/rk356x/AndroidProducts.mk

  1. 描述当前这个soc做的产品
  2. lunch显示的产品列表
//产品的列表
PRODUCT_MAKEFILES := \
        $(LOCAL_DIR)/rk3566_rgo/rk3566_rgo.mk \
        $(LOCAL_DIR)/rk3566_32bit/rk3566_32bit.mk \
        $(LOCAL_DIR)/rk3566_r/rk3566_r.mk \
        $(LOCAL_DIR)/rk3568_r/rk3568_r.mk \
        $(LOCAL_DIR)/rk3566_eink/rk3566_eink.mk \
        $(LOCAL_DIR)/rk3566_einkw6/rk3566_einkw6.mk
//lunch命令出来对话框的内容
COMMON_LUNCH_CHOICES := \
    rk3566_32bit-userdebug \
    rk3566_32bit-user \
    rk3566_rgo-userdebug \
    rk3566_rgo-user \
    rk3566_r-userdebug \
    rk3566_r-user \
    rk3568_r-userdebug \
    rk3568_r-user \
    rk3566_eink-userdebug \
    rk3566_eink-user \
    rk3566_einkw6-userdebug \
    rk3566_einkw6-user

device/rockchip/rk356x/BoardConfig.mk
描述一些底层信息

CURRENT_SDK_VERSION := rk356x_ANDROID10.0_MID_V1.0

TARGET_ARCH := arm64  #CPU的架构
TARGET_ARCH_VARIANT := armv8-a
TARGET_CPU_ABI := arm64-v8a
TARGET_CPU_ABI2 :=
TARGET_CPU_VARIANT := cortex-a55
TARGET_CPU_SMP := true

TARGET_PREBUILT_KERNEL := kernel/arch/arm64/boot/Image
BOARD_PREBUILT_DTBIMAGE_DIR := kernel/arch/arm64/boot/dts/rockchip

PRODUCT_UBOOT_CONFIG ?= rk3568 #**使用的Uboot config的前缀**
PRODUCT_KERNEL_ARCH ?= arm64
PRODUCT_KERNEL_DTS ?= rk3568-evb1-ddr4-v10  #内核设备树名称
PRODUCT_KERNEL_CONFIG ?= rockchip_defconfig  #内核config文件

# Sensors
BOARD_SENSOR_ST := true
BOARD_SENSOR_MPU_VR := false
BOARD_SENSOR_MPU_PAD := false

device/rockchip/rk356x/device.mk
通用的信息,rk356x通用的一些配置,下级文件夹会包含此文件

device/rockchip/rk356x/rk3568_r/rk3568_r.mk
用来描述rk3568_r这个产品

PRODUCT_SHIPPING_API_LEVEL := 30
PRODUCT_DTBO_TEMPLATE := $(LOCAL_PATH)/dt-overlay.in
PRODUCT_SDMMC_DEVICE := fe2b0000.dwmmc

include device/rockchip/common/build/rockchip/DynamicPartitions.mk
include device/rockchip/rk356x/rk3568_r/BoardConfig.mk
include device/rockchip/common/BoardConfig.mk
$(call inherit-product, device/rockchip/rk356x/device.mk)
$(call inherit-product, device/rockchip/common/device.mk)
$(call inherit-product, frameworks/native/build/tablet-10in-xhdpi-2048-dalvik-heap.mk)

DEVICE_PACKAGE_OVERLAYS += $(LOCAL_PATH)/../overlay

PRODUCT_CHARACTERISTICS := tablet

PRODUCT_NAME := rk3568_r	# 产品名称
PRODUCT_DEVICE := rk3568_r	#设备
PRODUCT_BRAND := rockchip
PRODUCT_MODEL := rk3568_r
PRODUCT_MANUFACTURER := rockchip	#厂家
PRODUCT_AAPT_PREF_CONFIG := mdpi	#屏幕的密度
#
## add Rockchip properties
#
PRODUCT_PROPERTY_OVERRIDES += ro.sf.lcd_density=320
PRODUCT_PROPERTY_OVERRIDES += ro.wifi.sleep.power.down=true
PRODUCT_PROPERTY_OVERRIDES += persist.wifi.sleep.delay.ms=0
PRODUCT_PROPERTY_OVERRIDES += persist.bt.power.down=true

# add by lgq 2022-01-08
PRODUCT_PROPERTY_OVERRIDES += \
       persist.sys.language=zh \
       persist.sys.country=CN \
       persist.sys.timezone=Asia/Shanghai
#end add

device/rockchip/rk356x/rk3568_r/BoardConfig.mk
描述具体的功能,比如是否支持摄像头等

include device/rockchip/rk356x/BoardConfig.mk
BUILD_WITH_GO_OPT := false

# AB image definition
BOARD_USES_AB_IMAGE := false
BOARD_ROCKCHIP_VIRTUAL_AB_ENABLE := false

ifeq ($(strip $(BOARD_USES_AB_IMAGE)), true)
    include device/rockchip/common/BoardConfig_AB.mk
    TARGET_RECOVERY_FSTAB := device/rockchip/rk356x/rk3566_r/recovery.fstab_AB
endif

PRODUCT_UBOOT_CONFIG := rk3568 #uboot config的前缀
PRODUCT_KERNEL_DTS := rk3568-evb1-ddr4-v10	#内核设备树
BOARD_GSENSOR_MXC6655XA_SUPPORT := true #支持加速度
BOARD_CAMERA_SUPPORT_EXT := true #支持摄像头
BOARD_HS_ETHERNET := true #支持网络

device/rockchip/rk356x/rk3568_r/AndroidBoard.mk
包含了一些其他的mk文件

# generate fstab file for device
-include device/rockchip/common/build/rockchip/RebuildFstab.mk

# generate dtbo image for device
-include device/rockchip/common/build/rockchip/RebuildDtboImg.mk
# generate parameter.txt for device
-include device/rockchip/common/build/rockchip/RebuildParameter.mk

二、目录下变量

变量分为三类:自定义变量、通用变量、功能变量

功能变量

PRODUCT_COPY_FILES
会在编译的时候,把需要编译到系统中的文件拷贝到out/target/product/rk3568_r目录里面,最终打包成镜像。
将冒号前面的拷贝到后面的路径out/target/product/rk3568_r

device/rockchip/rk356x/device.mk

...
PRODUCT_COPY_FILES += \
    $(LOCAL_PATH)/init.recovery.rk30board.rc:recovery/root/init.recovery.rk30board.rc \
    vendor/rockchip/common/bin/$(TARGET_ARCH)/busybox:recovery/root/sbin/busybox \
...

include:当 include 文件出错或者不存在的时候,make 会报错并退出。
-include:可以忽略包含文件不存在或者包含的文件出现的错误,make 会继续执行,不会报错退出。
inherit-product:变量的值包含两个包含文件的共存

$(call inherit-product, device/rockchip/rk356x/device.mk)
函数语法:$(call variable, param,param)
函数功能:它会把参数“param”依次赋值给变量“$(1)”、“$(2)”,call 函数对参数
的数量没有限制,也可以没有参数值,没有参数值“call”就没有实际存在的意义。
返回值:参数值“param”依次替换“$(1)”、“$(2)...的变量值。

ret=$(2)$(1)
val = $(call ret,a,b)
all:
@echo “val=$(val)

三、本地化产品

新建产品目录

device/rockchip/rk356x

cp -r rk3568_r topeet_rk3568_r

重命名产品文件
device/rockchip/rk356x/topeet_rk3568_r

mv rk3566_r.mk topeet_rk3566_r.mk

新增lunch列表
device/rockchip/rk356x/AndroidProducts.mk

PRODUCT_MAKEFILES := \
		...
        $(LOCAL_DIR)/rk3566_einkw6/rk3566_einkw6.mk \
        $(LOCAL_DIR)/topeet_rk3568_r/topeet_rk3568_r.mk	#★新增

COMMON_LUNCH_CHOICES := \
	...
    rk3566_einkw6-userdebug \
    rk3566_einkw6-user \
    topeet_rk3568_r-userdebug \ #★新增
	topeet_rk3568_r				#★新增

修改产品名称
device/rockchip/rk356x/topeet_rk3566_r/topeet_rk3566_r.mk

PRODUCT_SHIPPING_API_LEVEL := 30
PRODUCT_DTBO_TEMPLATE := $(LOCAL_PATH)/dt-overlay.in
PRODUCT_SDMMC_DEVICE := fe2b0000.dwmmc

include device/rockchip/common/build/rockchip/DynamicPartitions.mk
include device/rockchip/rk356x/★topeet_rk3568_r/BoardConfig.mk
include device/rockchip/common/BoardConfig.mk
$(call inherit-product, device/rockchip/rk356x/device.mk)
$(call inherit-product, device/rockchip/common/device.mk)
$(call inherit-product, frameworks/native/build/tablet-10in-xhdpi-2048-dalvik-heap.mk)

DEVICE_PACKAGE_OVERLAYS += $(LOCAL_PATH)/../overlay

PRODUCT_CHARACTERISTICS := tablet

PRODUCT_NAME := ★topeet_rk3568_r
PRODUCT_DEVICE := rk3568_r
PRODUCT_BRAND := rockchip
PRODUCT_MODEL := rk3568_r
PRODUCT_MANUFACTURER := rockchip
PRODUCT_AAPT_PREF_CONFIG := mdpi

编译

source javaenv.sh
source build/envsetup.sh
lunch

四、烧录调试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值