From de703c3d41ebbf2021304c1c77e0e5c9a8d74873 Mon Sep 17 00:00:00 2001 From: Neucrack Date: Tue, 25 Jun 2024 15:23:14 +0800 Subject: [PATCH] add compile os doc --- docs/doc/en/pro/compile_os.md | 81 +++++++++++++++++++++++++++++++++ docs/doc/zh/pro/compile_os.md | 84 +++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+) diff --git a/docs/doc/en/pro/compile_os.md b/docs/doc/en/pro/compile_os.md index e69de29..12f63b7 100644 --- a/docs/doc/en/pro/compile_os.md +++ b/docs/doc/en/pro/compile_os.md @@ -0,0 +1,81 @@ +--- +title: Building the System for MaixCAM +--- + +## Customizing and Compiling the System + +You can download the latest system suitable for MaixCAM from [https://github.com/sipeed/MaixPy/releases](https://github.com/sipeed/MaixPy/releases). + +For the latest base system, download it from [https://github.com/sipeed/LicheeRV-Nano-Build/releases](https://github.com/sipeed/LicheeRV-Nano-Build/releases). Please note that this system cannot be directly flashed to MaixCAM as it may damage the screen. + +For system source code and compilation instructions, refer to [https://github.com/sipeed/LicheeRV-Nano-Build](https://github.com/sipeed/LicheeRV-Nano-Build). It is recommended to use the Docker compilation method mentioned in the README to avoid compilation issues (note that the compiled system cannot be directly flashed to MaixCAM as it may damage the screen). + +## Copying Files for MaixCAM + +After compilation, you will get an img file. For MaixCAM, additional files need to be added to this img file. Download the [compressed package](https://github.com/sipeed/MaixPy/releases/download/v4.3.2/sys_builtin_files_2024.6.19.tar.xz), extract it, and save the script from the appendix as `update_img.sh`. Copy the `img` file, then execute `./update_img.sh path_to_sys_builtin_files path_to_copied_img`. This `img` can now be used for flashing to MaixCAM. + +However, note that the compressed package is of version `v4.3.2` and not the latest version. Adjust its contents according to your needs. Additionally, MaixPy is in the `usr/lib` directory, which can also be manually updated. + +## Appendix `update_img.sh`: + +```shell +#!/bin/sh + +set -e + +source_dir=$1 +img_file=$2 +mount_root=img_root + +img_file=$(readlink -f "$img_file") +THISDIR=$(dirname $(realpath $0)) + +if [ -z $img_file ] +then + echo "usage: $0 new_rootfs_dir image_file" +fi + +if [ ! -e $mount_root ] +then + mkdir -pv $mount_root +fi + +set -eux + +PART=2 + +PART_OFFSET=$(partx -s $img_file | head -n 3 | tail -n 1 | awk '{print $2}') +PART_OFFSET=$((PART_OFFSET * 512)) # sector size is 512 + +echo "PART: $PART" +echo "PART OFFSET: $PART_OFFSET" + +# some old version fuse2fs not support offset +$THISDIR/fuse2fs -o fakeroot -o offset=$PART_OFFSET $img_file $mount_root + +# copy root files +echo "copy root files now" +find $source_dir -mindepth 1 -maxdepth 1 -type d ! -name "boot" -exec cp -r {} $mount_root \; +sync +echo "copy root files done" + +# umount +umount $mount_root + +echo "copy boot files now" +# Change to source directory +cd "$source_dir/boot" || exit + +# Iterate through all files in the source directory +for file in *; do + # Check if the file is a regular file + if [ -f "$file" ]; then + # Copy individual file to the target directory + mcopy -o -i "$img_file@@1s" "$file" ::/ + echo "Copied $file to $img_file boot partition" + fi +done + +sync +echo "copy boot files done" +``` diff --git a/docs/doc/zh/pro/compile_os.md b/docs/doc/zh/pro/compile_os.md index e69de29..4f98ad6 100644 --- a/docs/doc/zh/pro/compile_os.md +++ b/docs/doc/zh/pro/compile_os.md @@ -0,0 +1,84 @@ +--- +title: 为 MaixCAM 编译系统 +--- + +## 定制和编译系统 + +你可以从 [https://github.com/sipeed/MaixPy/releases](https://github.com/sipeed/MaixPy/releases) 下载到适合 MaixCAM 的最新系统。 + +你可以从 [https://github.com/sipeed/LicheeRV-Nano-Build/releases](https://github.com/sipeed/LicheeRV-Nano-Build/releases)下载到最新的基础系统(不能直接给 MaixCAM 烧录使用,否则有烧坏屏幕风险)。 + +系统源码和编译请参考 [https://github.com/sipeed/LicheeRV-Nano-Build](https://github.com/sipeed/LicheeRV-Nano-Build),尽量用 readme 提到的 docker 编译以避免遇到编译问题(注意编译出来的系统不能直接给 MaixCAM 烧录使用,否则有烧坏屏幕风险)。 + + +## 为 MaixCAM 拷贝文件 + +编译通过后会得到一个 img 文件,对于 MaixCAM 还需要放一些额外的文件进去,下载[压缩包](https://github.com/sipeed/MaixPy/releases/download/v4.3.2/sys_builtin_files_2024.6.19.tar.xz),解压后将附录中的脚本保存成`update_img.sh`, 复制一份`img`, 然后执行`./update_img.sh sys_builtin_files_路径 复制的_img_路径`,这个 `img` 就能用来烧录给 MaixCAM 使用了。 + +不过需要注意,这里的压缩包是 `v4.3.2` 版本的,不是最新的版本,根据你自己的情况合理删减里面的内容即可,以及 MaixPy 在`usr/lib`目录下,也可以手动更新。 + + +## 附录 `update_img.sh`: + +```shell +#!/bin/sh + +set -e + +source_dir=$1 +img_file=$2 +mount_root=img_root + +img_file=$(readlink -f "$img_file") +THISDIR=$(dirname $(realpath $0)) + +if [ -z $img_file ] +then + echo "usage: $0 new_rootfs_dir image_file" +fi + +if [ ! -e $mount_root ] +then + mkdir -pv $mount_root +fi + +set -eux + +PART=2 + +PART_OFFSET=$(partx -s $img_file | head -n 3 | tail -n 1 | awk '{print $2}') +PART_OFFSET=$((PART_OFFSET * 512)) # sector size is 512 + +echo "PART: $PART" +echo "PART OFFSET: $PART_OFFSET" + +# some old version fuse2fs not support offset +$THISDIR/fuse2fs -o fakeroot -o offset=$PART_OFFSET $img_file $mount_root + +# copy root files +echo "copy root files now" +find $source_dir -mindepth 1 -maxdepth 1 -type d ! -name "boot" -exec cp -r {} $mount_root \; +sync +echo "copy root files done" + +# umount +umount $mount_root + + +echo "copy boot files now" +# 切换到源目录 +cd "$source_dir/boot" || exit + +# 遍历源目录中的所有文件 +for file in *; do + # 检查文件是否为普通文件 + if [ -f "$file" ]; then + # 拷贝单个文件到目标目录 + mcopy -o -i "$img_file@@1s" "$file" ::/ + echo "Copied $file to $img_file boot partition" + fi +done + +sync +echo "copy boot files done" +```