diff --git a/.gitignore b/.gitignore deleted file mode 100644 index c6127b38c1aa25968a88db3940604d41529e4cf5..0000000000000000000000000000000000000000 --- a/.gitignore +++ /dev/null @@ -1,52 +0,0 @@ -# Prerequisites -*.d - -# Object files -*.o -*.ko -*.obj -*.elf - -# Linker output -*.ilk -*.map -*.exp - -# Precompiled Headers -*.gch -*.pch - -# Libraries -*.lib -*.a -*.la -*.lo - -# Shared objects (inc. Windows DLLs) -*.dll -*.so -*.so.* -*.dylib - -# Executables -*.exe -*.out -*.app -*.i*86 -*.x86_64 -*.hex - -# Debug files -*.dSYM/ -*.su -*.idb -*.pdb - -# Kernel Module Compile Results -*.mod* -*.cmd -.tmp_versions/ -modules.order -Module.symvers -Mkfile.old -dkms.conf diff --git a/LICENSE b/LICENSE deleted file mode 100644 index e21081ab84508df1e8c28c141439e8d025516918..0000000000000000000000000000000000000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2025 wjn740 - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/README.en.md b/README.en.md deleted file mode 100644 index 7edffd95a2fb60e867feec018218c609285b22da..0000000000000000000000000000000000000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# doc - -#### Description -仓库 doc - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md index 7097533c9ed9194e5de221d02293c4d03e91d10d..a90075dc734279ff2f584c38f3454aa9dd2c6c12 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,74 @@ -# doc +# 1 SafetyLinux产品介绍 -#### 介绍 -仓库 doc +中兴 SafetyLinux 产品是具备实时性、确定性、安全性增强的Linux 操作系统,具有业界领先的中断响应和调度处理效率。同时具备主被动结合的立体安全防御机制、支持多芯片/多版本的高效编译构建体系。针对辅助驾驶、智能网关、智能仪表、机器人等多用应用场景。 -#### 软件架构 -软件架构说明 +![SafetyLinux产品介绍](imgs/SafetyLinux产品介绍.png) +# 2 快速上手 +|步骤|指导文档| +|-|-| +|第一步:下载|[源码下载流程](quick_start/01_downloading.md)| +|第二步:编译|[工程编译流程](quick_start/02_compiling.md)| +|第三步:烧写|[烧写运行流程](quick_start/03_Firmware_Image_Flashing_Guide.md)| -#### 安装教程 +# 3 开发指南 +|定制化功能|指导文档| +|-|-| +|SDK开发指南|[SDK开发指南](development_guide​​/SDK_Development_Guide.md)| +|BSP开发指南|[BSP开发指南](BSP_Development_Guide.md)| -1. xxxx -2. xxxx -3. xxxx -#### 使用说明 +# 4 工程代码目录结构 -1. xxxx -2. xxxx -3. xxxx +SafteyLinux代码目录结构如下 -#### 参与贡献 +```bash +. +├── atf +│   └── atf-2.5 # 管理atf代码 +├── buildsystem # 管理yocto构建框架代码 +│   ├── build_docker_image # 容器化构建支持 +│   ├── build.py # 统一编译入口 +│   ├── build.sh # 统一编译入口 +│   ├── configs # 编译配置 +│   ├── Makefile # 编译入口 +│   ├── README.md # 仓库说明 +│   ├── scripts # 构建脚本 +│   └── templates # 配置模版 +├── extentions # 保存核心配方文件管理二次开发、定制功能的构建代码 +│   ├── meta-automotive-gateway # 管理编译构建的核心代码,实现版本构建、三方库集成、sdk移植等功能 +│   ├── meta-commercial-automotive # 管理三方库集成等功能 +│   ├── meta-extended-openembedded # 管理基于开源代码仓库meta-openembedded进行扩展的代码 +│   ├── meta-extended-selinux # 管理基于开源代码仓库meta-selinux进行扩展的代码 +│ └── poky # 基于开源代码仓库meta-poky进行扩展的代码 +│ ├── meta-extended # 基于开源代码仓库meta进行扩展的代码 +├── downloads # 存放开源代码 +├── kernel +│ └── kernel-5.10 # 管理内核代码 +├── soc +│ └── zte +│ ├── meta-m1 # 管理m1构建配方文件 +├── u-boot +│   └── u-boot-2020-04 # 管理u-boot代码 +├── upstreams # 存放支持组件及工程编译的配方文件,来源于yocto/openembedded社区 +│ ├── meta-openembedded +│ ├── meta-security +│ ├── meta-selinux +│ ├── meta-virtualization +│ └── poky +└── work # 编译构建产物目录 +``` -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request +# 5 支持硬件 -#### 特技 +SafetyLinux项目目前支持以下平台: +- m1芯片下EVB板型 +- qemu-aarch64 -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) + +# 6 License + +# 7 Release Note + +- 新增M1板型的支持 diff --git a/development_guide/BSP_Development_Guide.md b/development_guide/BSP_Development_Guide.md new file mode 100644 index 0000000000000000000000000000000000000000..ff7c7a0b57356578ae6a6afe179fc62de1156c76 --- /dev/null +++ b/development_guide/BSP_Development_Guide.md @@ -0,0 +1,50 @@ +# BSP开发指南 +## 适配步骤 +SafetyLinux构建框架支持BSP的适配,这里以ipcf内核模块为例,简述其适配过程: +1. 按照"代码目录结构说明",在SafteyLinux工程主目录下的soc/zte/atf目录下新建ipcf目录,并在该目录下创建ipcf编译构建配方文件,如ipcf_1.0.bb + > *.bb文件后也称为配方文件 +2. 将ipcf模块源码放置到SafteyLinux工程主目录下的src/ipcf目录中(若目录不存在则需要新建) +3. 在ipcf_1.0.bb配方文件中添加ipcf模块编译配置必需的内容 + > 配方文件修改参考如下 + - 指定ipcf源码位置及编译目录,示例如下 + ``` bash + EXTERNALSRC = "${PROJECT_DIR}/src/ipcf" + + EXTERNALSRC_BUILD = "${WORKDIR}/build" + ``` + - Licesne声明等,示例如下 + ``` bash + SUMMARY = "Linux driver for ipc-shm-hpe" + + LICENSE = "MIT" + + LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + ``` + + - 编译设置,示例如下 + ``` bash + do_compile() { + + 自定义 + + } + ``` + - 安装设置,示例如下 + ``` bash + do_install() { + + 自定义 + + } + ``` +4. 将ipcf模块集成到文件系统,参考如下 +``` bash +# 将ipcf加到该文件定义的组件列表中 +${PATH}/products/meta-automotive-gateway/recipes-core/thirdpartypacks/third-party-packages.bb + +``` + +配方的构建过程参考 + +​ ![image.png](../imgs/配方执行流程.png) + diff --git a/development_guide/SDK_Development_Guide.md b/development_guide/SDK_Development_Guide.md new file mode 100644 index 0000000000000000000000000000000000000000..a7612193cc6ba69b0b283feefe0ae3d0e4fe2170 --- /dev/null +++ b/development_guide/SDK_Development_Guide.md @@ -0,0 +1,95 @@ +# SDK 开发指南 +因为编译工具链等差异,用户本地环境中编译出的可执行程序在SafetyLinux系统环境可能无法正常执行,为了解决这个问题,Safetylinux提供了开发sdk(编译工具),该工具可以用于编译用户本地程序,并支持编译后的用户程序在环境中运行。 +## SDK镜像编译 + + 参考[工程编译流程](quick_start/02_compiling.md),修改编译命令为:python3 build.py -c populate_sdk -m m1_evb gateway.json +``` text +# 构建完成后,sdk镜像生成位置 +${PATH}/build/tmp/deploy-m1_evb/sdk/poky-glibc-x86_64-core-image-automotive-cortexa53-m1_evb-toolchian-5.0.6.sh +``` +## SDK镜像安装 + +1. 创建sdk编译工具安装目录,如~/sdk/,完成后执行下面命令将sdk工具安装到指定目录 + ``` bash + sh poky-glibc-x86_64-core-image-automotive-cortexa53-m1_evb-toolchian-5.0.6.sh -d ~/sdk -y + ``` + > 说明:若安装信息中提示”SDK has been successfully set up and is ready to be used.”,说明sdk工具安装成功 + +2. 步骤1完成后,在sdk安装目录下执行如下命令设置交叉编译环境: + ``` bash + source environment-setup-cortexa53-poky-linux + echo $CC + ``` + > 若返回值不为空,则sdk工具环境设置完毕 + +## 基于sdk编译构建应用程序 +在完成sdk编译环境安装及初始化设置后,可以使用其进行二次开发,基本流程如下: + +1. 以使用sdk工具编译示例程序hello.c为例,代码示例如下 + ``` bash + #include + + int main() { + printf("Hello World!\n"); + return 0; + } + ``` + + +2. 执行如下编译命令(注:如果是编译C++文件,则使用$CXX): + ``` bash + $CC hello.c -o hello + ``` + > 编译结果如下 + ``` bash + $ $CC hello.c -o hello + $ ls -l hello + $ 75456 Mar 24 10:15 hello + ``` +3. 将编译出来的hello可执行文件,通过scp方式拷贝到环境中运行,运行结果如下图所示 + ``` bash + $ ./hello + $ Hello World! + ``` + +## 基于sdk编译构建开源组件/三方库 + +1. 这里假设组件源码使用Makefile方式进行编译,以tinyxml2组件为例,将组件源码拷贝到准备好的sdk环境中,如~/sdk目录下,在tinyxml2源码目录下执行make命令,进行编译 + ``` bash + $ make + ``` +2. 指定产物安装路径(路径需存在),如:make install DESTDIR=~/sdk/tinyxml2-9.0.0/output/ 安装编译产物,完成后,查看编译产物如下图 + ``` bash + output/ + └── usr/ + └── local/ + ├── bin/ + │ └── xmltest + ├── include/ + │ └── tinyxml2.h + └── lib/ + └── libtinyxml2.a + ``` +> 说明:tinyxml2示例中因为Makefile文件中指定默认生成.a静态库,如果期望获取.so动态库产物,可以参考如下cmake编译方式 + 将组件源码拷贝到准备好的sdk环境中;并新建build/image目录; + +- 进入build目录下,执行cmake .. -DCMAKE_INSTALL_PREFIX=~/sdk/tinyxml2-9.0.0/build/image -Dtinyxml2_SHARED_LIBS=YES 操作,进行编译配置 + +- 执行make; make install命令执行编译构建,完成后,使用tree命令查看生成产物,可以通过scp方式将其拷贝到环境中 + ``` bash + image/ + ├── include/ + │ └── tinyxml2.h + └── lib/ + ├── cmake/ + │ └── tinyxml2/ + │ ├── tinyxml2-config.cmake + │ ├── tinyxml2-config-version.cmake + │ ├── tinyxml2-shared-targets.cmake + │ └── tinyxml2-shared-targets-noconfig.cmake + ├── libtinyxml2.so -> libtinyxml2.so.9 + ├── libtinyxml2.so.9 -> libtinyxml2.so.9.0.0 + ├── libtinyxml2.so.9.0.0 + └── pkgconfig/ + └── tinyxml2.pc + ``` \ No newline at end of file diff --git "a/imgs/SafetyLinux\321\204\342\225\221\320\267\321\205\320\243\320\221\321\204\342\225\227\320\233\321\207\342\225\227\320\235.png" "b/imgs/SafetyLinux\321\204\342\225\221\320\267\321\205\320\243\320\221\321\204\342\225\227\320\233\321\207\342\225\227\320\235.png" new file mode 100644 index 0000000000000000000000000000000000000000..0b914854f5f9069e66772ecafee011579912cf46 Binary files /dev/null and "b/imgs/SafetyLinux\321\204\342\225\221\320\267\321\205\320\243\320\221\321\204\342\225\227\320\233\321\207\342\225\227\320\235.png" differ diff --git "a/imgs/\321\211\320\225\320\235\321\206\320\246\342\225\243\321\206\320\231\320\267\321\210\320\261\320\234\321\206\342\225\241\320\221\321\207\320\270\320\233.png" "b/imgs/\321\211\320\225\320\235\321\206\320\246\342\225\243\321\206\320\231\320\267\321\210\320\261\320\234\321\206\342\225\241\320\221\321\207\320\270\320\233.png" new file mode 100644 index 0000000000000000000000000000000000000000..8eacb8d6575b282502bcde0cc12277e2310a192b Binary files /dev/null and "b/imgs/\321\211\320\225\320\235\321\206\320\246\342\225\243\321\206\320\231\320\267\321\210\320\261\320\234\321\206\342\225\241\320\221\321\207\320\270\320\233.png" differ diff --git a/quick_start/01_downloading.md b/quick_start/01_downloading.md new file mode 100644 index 0000000000000000000000000000000000000000..fb5448436ebf877d06571971a38958b0f950cce4 --- /dev/null +++ b/quick_start/01_downloading.md @@ -0,0 +1,49 @@ +# 源码下载流程 + +## 服务器资源 + +### 硬件资源 + +| 资源 | 推荐 | +| ---- | ---- | +| CPU | 80核 | +| 内存 | 256G | +| 磁盘 | 1TB | + +### 操作系统 + +| 操作系统 | 推荐版本 | +| -------- | ------------------ | +| Ubuntu | Ubuntu 20.04.6 LTS | + +### 应用组件 + +```text +bzip2 cache-swig chrpath cpio cpp diffstat diffutils file findutils gawk gcc gcc++ git glibc-devel glibc-langpack-en gzip hostname libacl lz4 make patch perl perl-Data-Dumper perl-File-Compare perl-File-Copy perl-File-FindBin perl-Text-ParseWords perl-Thread-Queue perl-bignum perl-locale python python3.8 python3-jinja2 python3-pep8 python3-pip rpcgen socat tar texinfo unzip wget which xz zstd docker +``` +## 容器构建资源 +需要环境支持docker,并将用户加入docker组 +> 参考sudo usermod -aG docker \$USER && newgrp docker + +## 下载代码 +1. 生成ssh秘钥,请按[atomic ssh密钥添加流程](https://docs.atomgit.com/user/sshkey/)进行 +2. 配置git + ```bash + git config --global user.name "替换为您的名字" + git config --global user.email "替换为您的邮箱" + ``` +3. 切换到您存放代码的目录下,运行如下脚本下载代码 + > 提示:这里将代码放在了SafetyLinux目录下 + ```bash + # 根据实际情况替换${}中的内容 + # 获取代码 + cd /SafetyLinux + git clone git@atomgit.com:opennewstart/SafetyLinux_Build.git + + # 进入代码目录 + cd ${PATH} + + # 拉取工程代码 + ./init.sh -t init -m release-cortexa53.xml + ``` + > 关于init.sh 的更多使用,可以输入`./init.sh -h`查看 diff --git a/quick_start/02_compiling.md b/quick_start/02_compiling.md new file mode 100644 index 0000000000000000000000000000000000000000..70587f5cc4350bbcc444b5df15e073ab54a0b211 --- /dev/null +++ b/quick_start/02_compiling.md @@ -0,0 +1,40 @@ +# 工程编译 +## 一键编译 +> 为避免环境被误改,编译不允许root执行,请切换到普通用户执行编译 +- 切换到`${PATH}/buildsystem/`目录(${PATH}表示SafetyLinux工程的根目录): + ``` bash + cd ${PATH}/buildsystem/ + ``` +- 在${PATH}/buildsystem/build_docker_image目录下,执行命令进入容器编译环境 + ``` bash + ./rundocker.sh + ``` +- 编译evb全版本(在${PATH}/buildsystem目录下执行) + ``` bash + python3 build.py -m m1_evb gateway.json + ``` +- 编译qemu全版本(在${PATH}/buildsystem目录下执行) + ``` bash + python3 build.py -m qemu_aarch64 gateway.json + ``` + - 编译sdk(在${PATH}/buildsystem目录下执行) + ``` bash + python3 build.py -c populate_sdk -m m1_evb gateway.json + ``` +## 编译产物获取 + +```bash +# 这里以evb版本为例进行说明 +# 进入产物目录,获取内核、文件系统、设备树、debug工具包等镜像 +cd ${PATH}/build/artifacts-m1_evb +``` +## 更多编译命令 +- 单独编译组件:python3 build.py -c compile -m m1_evb -t ${name} gateway.json ;其中${name}替换为指定组件名称,如busybox + +- 清除普通组件编译缓存:python3 build.py -c cleansstate -m m1_evb -t ${name} gateway.json ;其中${name}替换为指定组件名称,如busybox + +- 单独构建kernel内核:python3 build.py -c compile -m m1_evb -t virtual/kernel gateway.json + +- 清除根文件系统编译缓存:python3 build.py -c cleansstate -m m1_evb gateway.json + + > 说明:以上操作均需要在${PATH}/buildsystem/目录下执行 \ No newline at end of file diff --git a/quick_start/03_Firmware_Image_Flashing_Guide.md b/quick_start/03_Firmware_Image_Flashing_Guide.md new file mode 100644 index 0000000000000000000000000000000000000000..8b105e2d241909956194df43a6067455894a963f --- /dev/null +++ b/quick_start/03_Firmware_Image_Flashing_Guide.md @@ -0,0 +1,287 @@ +# 1. M1-联友单板烧写指南 + +## 1.1. 单板环境 +搭建M1 联友单板硬件烧写调试环境,通过交换机与服务器连接,用户登录到服务器,通过调试串口进行输入输出与单板实现人机交互。 +1)选择Ubuntu18.04/Ubuntu20.04系统作为Host端; +2)从制品库下载对应测试版本; +3)单板通过以太网口,实现与其他设备的数据通信; +4)通过调试串口的输入输出,实现人机交互; + +## 1.2. 烧写FIP镜像 +fip.img 包含U-Boot+ATF+DTB,需通过串口写入到 NorFlash 0x390000 地址(参考Flash空间布局),基于WindTerm串口终端工具,步骤如下: + +步骤一:在Bootloader cli 界面输入命令:image_down。 +```shell +bl->image_down + +ymodem download... ram_addr:0x10B00000 + +CCCymodem_read 607060 bytes +``` + +步骤二:界面上输出字符 'C' 之后,在界面空白处点击右键,选择“二进制传输”,点击“发送YModem...(Y)”, 选择fip.image文件,开始传输,并等待传输完成。 + +步骤三:串口界面输入命令:image_write 0 0x390000,将 fip.image 文件写入 NorFlash。 + +```shell +bl->image_write 0 0x390000 +``` +步骤四:下载完成后,可通过单板重新上电检查是否完成烧录。 + + +## 1.3. SafetyLinux版本烧写 +需要烧写的镜像: +1. fit.img :当前safetylinux版本为了适配安全启动,已经支持fit镜像格式,包含kernel、内核使用的dtb +2. emmc_rootfs.img:根文件系统镜像 +3. gpt_partition.img:分区镜像文件 + +### 1.3.1. uboot环境设置ip +uboot中执行printenv查看环境变量是否设置ip,若未设置ip,则使用以下命令设置ip(根据实际环境修改IP地址): + +```shell +# 设置单板所连接服务器(上位机)IP地址 +setenv serverip 10.234.77.180 +# 设置单板IP地址 +setenv ipaddr 10.234.77.55 +``` + +### 1.3.2. 烧写gpt_partition.img +通过fastboot烧写,启动上一步烧写的fip,在A核串口下停在uboot命令行。 +A核串口执行命令启动传输,执行: +```shell +=> fastboot udp + +Using eth0 device +Listening for fastboot command on 10.234.77.55 +``` + +上位机执行:(举例,根据自己的环境进行配置) +```shell +fastboot -s udp:10.234.77.55 flash gpt ./gpt_partition.img +``` + +### 1.3.3. 烧写fit.img和emmc_rootfs.img +通过fastboot烧写,启动上一步烧写的fip,在A核串口下停在uboot命令行。 +A核串口执行命令启动传输,执行: + +```shell +=> fastboot udp + +Using eth0 device +Listening for fastboot command on 10.234.77.55 +``` + +上位机执行:(举例,根据自己的环境进行配置) + +```shell +# 上位机执行镜像烧写 +fastboot -s udp:10.234.77.55 flash fit ./fit.img + +fastboot -s udp:10.234.77.55 flash emmc_rootfs ./emmc_rootfs.img + +``` + +### 1.3.4. 启动系统 +m1单板侧ctrl + c掉 fastboot,然后执行命令引导内核,命令:boot或者断电启动 +```shell +Abort +fastboot udp error: -4 +=> boot + +MMC read: dev # 0, block # 2048, count 40960 ... 40960 blocks read: OK +## Loading kernel from FIT Image at 870000000 ... + Using 'conf-evb-emmcrootfs' configuration + Verifying Hash Integrity ... OK + Trying 'kernel' kernel subimage + Description: 5.10 Linux kernel + Type: Kernel Image + Compression: uncompressed + Data Start: 0x8700000ec + Data Size: 13244424 Bytes = 12.6 MiB + Architecture: AArch64 + OS: Linux + Load Address: 0x860000000 + Entry Point: 0x860000000 + Hash algo: sha256 + Hash value: ea4b9ba84ac48455a3cdf1c5051216129829c9623301eb609650d5e37956d221 + Verifying Hash Integrity ... sha256+ OK + Decrypting Data ... OK +## Loading fdt from FIT Image at 870000000 ... + Using 'conf-evb-emmcrootfs' configuration + Verifying Hash Integrity ... OK + Trying 'fdt-evb' fdt subimage + Description: Flattened Device Tree blob + Type: Flat Device Tree + Compression: uncompressed + Data Start: 0x870ca1a00 + Data Size: 20481 Bytes = 20 KiB + Architecture: AArch64 + Load Address: 0x863000000 + Hash algo: sha256 + Hash value: 12ecbb8cf98d7a8f58435ada16a575af47fc6b29716423a076b5f5aadc7b18f8 + Verifying Hash Integrity ... sha256+ OK + Decrypting Data ... OK + Loading fdt from 0x870ca1a00 to 0x863000000 + Booting using the fdt blob at 0x863000000 + Loading Kernel Image + Using Device Tree in place at 0000000863000000, end 0000000863008000 + +Starting kernel ... + +[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034] +[ 0.000000] Linux version 5.10.120-rt70-SafetyLinux (oe-user@oe-host) (aarch64-poky-linux-gcc (GCC) 12.3.0, GNU ld (GNU Binutils) 2.42.0.20240723) #1 SMP PREEMPT_RT Thu Jun 12 +03:49:50 UTC 2025 +``` + +# 2. safetylinux分区方案设计 + +主要镜像: +1. fip.img:该镜像需要用串口工具烧写,里面包含uboot使用的dtb、bl2镜像、bl31镜像、bl33镜像 +2. fit.img :当前evb版本为了适配安全启动,已经改成fit镜像格式,包含kernel、内核使用的dtb +3. emmc_rootfs.img:根文件系统镜像 +4. gpt_partition.img:分区镜像文件 + +## 2.1. gpt分区 + +### 2.1.1. 添加gpt分区配置文件partition.json + +配置文件路径:meta-embedded-automotive/recipes-vendor/m1/imgs/files/partition.json +根据上面配置文件添加我们自己的需求方案进行修改。 +文件内容: + - settings用来描述镜像文件大小; + - partitions用来描述分区信息; +```json +{ + "settings" : { + "comment" : "EVB:MMC SIZE IS 29,840MiB", + "disk_size" : "2048", + "disk_unit" : "MiB" + }, + "partitions" : [ + { + "label" : "fit", + "start" : "1MiB", + "end" : "21MiB", + "image_path": "./image.itb" + }, + { + "label" : "emmc_rootfs", + "start" : "21MiB", + "end" : "550MiB", + "image_path": "./core-image-automotive-m1.rootfs.ext4" + }, + { + "label" : "log", + "start" : "550MiB", + "end" : "1062MiB" + }, + { + "label" : "debug", + "start" : "1062MiB", + "end" : "1318MiB" + } + ] +} +``` + +其中json文件中的label:fit 、emmc_rootfs名称是固定的,因为uboot引导过程中会根据对应的名称自动查找镜像位置。 + + +## 2.2. fit.img镜像生成过程 + +ITS: image tree source,使用mkimage和dtc工具可以将.its和对应的image文件打包成itb文件。该文件可以下载到memory中,用bootm执行。 + - images节点:指定所要包含的二进制文件,可以指定多种类型的多个文件,每个文件都是images下的一个子node。 + - configures:可以将不同类型的二进制文件,根据不同场景,组合起来,形成一个配置项。u-boot在boot的时候,以配置项为单位加载、执行,这样就可以根据不同的场景,方便的选择不同的配置,实现unify kernel目标。 + - 其中依赖镜像:Image,zx298091evb1.dtb。 +```shell +/dts-v1/; + +/ { + description = "ZX298091 EVB image with single Linux kernel and FDT blob"; + #address-cells = <2>; + + images { + kernel { + description = "5.10 Linux kernel"; + data = /incbin/("./Image"); + type = "kernel"; + arch = "arm64"; + os = "linux"; + compression = "none"; + load = <0x8 0x60000000>; + entry = <0x8 0x60000000>; + hash-1 { + algo = "sha256"; + }; + }; + fdt-evb { + description = "Flattened Device Tree blob"; + data = /incbin/("./zx298091evb1.dtb"); + type = "flat_dt"; + arch = "arm64"; + compression = "none"; + load = <0x8 0x63000000>; + hash-1 { + algo = "sha256"; + }; + }; + }; + + configurations { + default = "conf-evb-emmcrootfs"; + conf-evb-emmcrootfs { + description = "Boot Linux kernel with FDT blob"; + kernel = "kernel"; + fdt = "fdt-evb"; + }; + }; +}; +``` + +## 2.3. 添加分区构建文件生成对应分区镜像 + +编译构建源码:recipes-vendor/m1/imgs/m1-image-generate.bb +主要流程: +1. 解析配置分区json文件 +2. 依次生成fit.img、emmc_roofts.img +3. 生成分区表镜像gpt_partition.img + +## 2.4. 编译构建镜像 +在SafetyLinux_Build/Buildsystem3.0/SafetyLinux/buildsystem目录下执行以下操作: + +```shell +$ cp ./configs/m1_ly.config .config +$ make +``` +等待编译构建完成输出镜像:SafetyLinux_Build/Buildsystem3.0/SafetyLinux/work/build_m1/evb-ly/tmp/deploy/images/m1 + +## 2.5. 查看分区信息 + +在uboot中烧写完成gpt_partition.img后,可以执行mmc part查看分区信息如下,与json文件配置一致。参考烧写文档即可,例如分区信息如下: +```shell +=> mmc part + +Partition Map for MMC device 0 -- Partition Type: EFI + +PartStart LBAEnd LBAName +Attributes +Type GUID +Partition GUID + 10 x000008000 x0000a7ff "fit" +attrs:0x0000000000000000 +type:0fc63daf-8483-4772-8e79-3d69d8477de4 +guid:94326677-e197-4e3d-8c2e-e7132cb8712c + 20 x0000a8000 x00112fff "emmc_rootfs" +attrs:0x0000000000000000 +type:0fc63daf-8483-4772-8e79-3d69d8477de4 +guid:fd4eab78-bdef-4869-b8a3-e89d95eda2a8 + 30 x001130000 x00212fff "log" +attrs:0x0000000000000000 +type:0fc63daf-8483-4772-8e79-3d69d8477de4 +guid:a5ec5133-c4e1-4d79-9ad0-11e460ad4680 + 40 x002130000 x00292fff "debug" +attrs:0x0000000000000000 +type:0fc63daf-8483-4772-8e79-3d69d8477de4 +guid:e4f8edaa-4c07-4282-ab74-470cb2218a1a +``` +