Skip to content

Commit 939e4a5

Browse files
committed
optimize build scripts
1 parent 265b688 commit 939e4a5

File tree

3 files changed

+31
-34
lines changed

3 files changed

+31
-34
lines changed

tools/os/maixcam/gen_os.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ echo "pack and copy MaixCDK projects"
117117
cd "$MAIXCDK_PATH/projects"
118118
if [ $skip_build_apps == 0 ]; then
119119
chmod +x ./build_all.sh
120-
./build_all.sh
120+
./build_all.sh maixcam
121121
fi
122122
cd -
123123
if [ -d $MAIXCDK_PATH/projects/apps/ ]; then

tools/os/maixcam2/gen_os.sh

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ set -x
1515

1616
function usage() {
1717
echo "Usage:"
18-
echo " ./gen_os.sh <base_os_filepath> <maixpy_whl_filepath> <builtin_files_dir_path> [skip_build_apps] [board_name] [rootfs_size] [delete_first_files]"
18+
echo " ./gen_os.sh <base_os_filepath> <maixpy_whl_filepath> <builtin_files_dir_path> [skip_build_apps] [board_name] [delete_first_files]"
1919
echo "skip_build_apps can be 0 or 1"
2020
echo "board_name can be maixcam or maixcam-pro"
21-
echo "rootfs_size default AUTO means same with original, you can change it like 5120M"
2221
echo "delete_first_files before copy new builtin files, delete some files, one line one item, format same with command rm"
2322
echo ""
2423
}
@@ -58,13 +57,9 @@ if [ -n "$5" ]; then
5857
fi
5958
fi
6059

61-
rootfs_size=AUTO
6260
delete_first_files=""
6361
if [ -n "$6" ]; then
64-
rootfs_size=$6
65-
fi
66-
if [ -n "$7" ]; then
67-
delete_first_files=$7
62+
delete_first_files=$6
6863
fi
6964

7065

@@ -96,9 +91,12 @@ rm -rf tmp/maixpy_whl
9691
rm -rf tmp/sys_builtin_files
9792
rm -rf tmp/*.img
9893
rm -rf tmp/$os_version_str.img.xz
99-
rm tmp/delete_files.txt
94+
rm -rf tmp/delete_files.txt
10095
sync
10196

97+
# get sudo permission for update_img.sh later
98+
sudo echo "Need sudo permission for update_img.sh later, grant permission now"
99+
102100
# 1. 检查参数 文件或者文件夹是否存在,然后拷贝一份 builtin_files_dir_path 到 tmp,不要影响原目录,检查 base os file 是不是 xz, 如果是解压到临时目录 tmp,并改名为 os_version_str.img,不是则拷贝一份到 tmp 目录下 os_version_str.img
103101
echo "copy builtin files"
104102

@@ -148,7 +146,7 @@ echo "pack and copy MaixCDK projects"
148146
cd "$MAIXCDK_PATH/projects"
149147
if [ $skip_build_apps == 0 ]; then
150148
chmod +x ./build_all.sh
151-
./build_all.sh
149+
./build_all.sh maixcam2
152150
fi
153151
cd -
154152
if [ -d $MAIXCDK_PATH/projects/apps/ ]; then
@@ -180,7 +178,7 @@ delete_first_files=tmp/delete_files.txt
180178

181179
# 9. 拷贝 tmp/sys_builtin_files 生成新镜像,通过 ./update_img.sh tmp/sys_builtin_files tmp/os_version_str.img
182180
echo "Now update system image, need sudo permition to mount rootfs:"
183-
sudo ./update_img.sh $base_os_path tmp/sys_builtin_files $delete_first_files tmp/${os_version_str}.axp $rootfs_size
181+
sudo ./update_img.sh $base_os_path tmp/sys_builtin_files $delete_first_files tmp/${os_version_str}.axp
184182

185183
mkdir -p images
186184
mv tmp/${os_version_str}.axp images/${os_version_str}.axp

tools/os/maixcam2/update_img.sh

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
###
4-
# update_image.sh <xxxx.axp> <builtin_files.tar.xz/builtin_files_dir> <delete_first_files.txt> <out_path> [rootfs_size]
4+
# update_image.sh <xxxx.axp> <builtin_files.tar.xz/builtin_files_dir> <delete_first_files.txt> <out_path>
55
###
66

77
set -e
@@ -13,11 +13,6 @@ out_path=$4
1313

1414
rootfs_name=ubuntu_rootfs_sparse.ext4
1515
bootfs_name=bootfs.fat32
16-
rootfs_image_size=AUTO
17-
# if rootf_size is not set, use default value
18-
if [ -n "$5" ]; then
19-
rootfs_image_size=$5
20-
fi
2116

2217
# check root permition
2318
if [ "$(id -u)" -ne 0 ]; then
@@ -98,15 +93,6 @@ if [ $? -ne 0 ]; then
9893
exit 1
9994
fi
10095
echo "Converting $axp_file to raw image done"
101-
file_size=$(stat -c%s tmp2/rootfs.ext4.raw)
102-
rootfs_image_size0=$(($file_size / 1024 / 1024))M
103-
resize_image=0
104-
if [[ $rootfs_image_size == "AUTO" ]]; then
105-
rootfs_image_size=$rootfs_image_size0
106-
elif [[ $rootfs_image_size0 != "$rootfs_image_size" ]]; then
107-
echo "will create new image with size $rootfs_image_size"
108-
resize_image=1
109-
fi
11096

11197
echo "Mounting raw image to tmp2/rootfs"
11298
mkdir -p tmp2/rootfs
@@ -143,32 +129,45 @@ while IFS= read -r line; do
143129
fi
144130
done < "$delete_first_files"
145131

132+
# check image size
133+
# get tmp2/rootfs + builtin_files size, if > rootfs_image_size, update rootfs_image_size -> rootfs_image_size + 100M
134+
rootfs_image_size0=$(du -s --block-size=1M tmp2/rootfs | cut -f1)
135+
rootfs_image_size0=$(($rootfs_image_size0 + $(du -s --block-size=1M $builtin_files | cut -f1)))
136+
rootfs_image_size=$(($rootfs_image_size0 + 300))
137+
echo "=============================="
138+
echo "rootfs_dir_size: $rootfs_image_size0 M"
139+
echo "final rootfs_image_size: $rootfs_image_size M"
140+
echo "=============================="
141+
146142
# copy builtin_files rootfs
147143
echo "Copying files from directory $builtin_files"
148144
target_rootfs_path=tmp2/rootfs
149-
if [[ "$resize_image" == "1" ]]; then
150-
mkdir tmp2/rootfs_new
151-
cp -r tmp2/rootfs/* tmp2/rootfs_new/
152-
target_rootfs_path=tmp2/rootfs_new
153-
fi
145+
# copy to new dir
146+
rm -rf tmp2/rootfs_new
147+
mkdir tmp2/rootfs_new
148+
cp -rP tmp2/rootfs/* tmp2/rootfs_new/
149+
target_rootfs_path=tmp2/rootfs_new
150+
# copy rootfs files
154151
find $builtin_files -mindepth 1 -maxdepth 1 -type d ! -name "boot" | while read -r dir; do
155-
cp -r "$dir" "$target_rootfs_path"
152+
cp -rP "$dir" "$target_rootfs_path"
156153
done
157154

158155
# copy boot files
159156
if [[ -e ${builtin_files}/boot ]]; then
160157
echo "Copying boot files from ${builtin_files}/boot..."
161158
mkdir -p tmp2/bootfs
162159
mount -o loop,rw tmp2/axp/$bootfs_name tmp2/bootfs
163-
cp -rf ${builtin_files}/boot/* tmp2/bootfs/
160+
cp -rfP ${builtin_files}/boot/* tmp2/bootfs/
161+
sync
164162
umount tmp2/bootfs
165163
echo "Copying boot files done"
166164
fi
167165

168166
# convert raw image to ext4 sparse image
169167
echo "Making sparse rootfs ..."
170168
rm -f tmp2/axp/${rootfs_name}
171-
./make_ext4fs/make_ext4fs -s -l $rootfs_image_size tmp2/axp/${rootfs_name} $target_rootfs_path
169+
./make_ext4fs/make_ext4fs -s -l ${rootfs_image_size}M tmp2/axp/${rootfs_name} $target_rootfs_path
170+
sync
172171
echo "Making sparse rootfs done"
173172

174173
# unmount rootfs

0 commit comments

Comments
 (0)