Commit dd875441 authored by 付燕斌's avatar 付燕斌
Browse files

Merge branch 'test_pack_rockchip' into 'main'

fix: system 分区空间不足

See merge request !1
parents a4b5f319 3fcd85b6
...@@ -58,9 +58,11 @@ update_img_tmp_dir="$build_dir/img_dir" ...@@ -58,9 +58,11 @@ update_img_tmp_dir="$build_dir/img_dir"
super_img_tmp_dir="$build_dir/img_dir/super" super_img_tmp_dir="$build_dir/img_dir/super"
ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME="system_a" ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME="system_a"
ROCKCHIP_DEFAULT_SYSTEM_PARTITION_NAME="system"
is_amlogic=0 is_amlogic=0
is_allwinner=0 is_allwinner=0
is_rockchip=0
outfile_path="" outfile_path=""
...@@ -132,11 +134,31 @@ resize_system_image() { ...@@ -132,11 +134,31 @@ resize_system_image() {
qemu-img resize -f raw "$c_system_file" "$image_size" qemu-img resize -f raw "$c_system_file" "$image_size"
loopdev=$(losetup -P -f --show "$c_system_file") loopdev=$(losetup -P -f --show "$c_system_file")
yes | e2fsck -f "$loopdev" e2fsck -f -y "$loopdev"
resize2fs "$loopdev" resize2fs "$loopdev"
losetup -d "$loopdev" losetup -d "$loopdev"
} }
__unpack_super_img() {
local system_partition_name="$1"
if __is_sparse_super
then
simg2img "$super_file" "$super_file_ext4"
lpunpack "$super_file_ext4" "$super_img_tmp_dir"
else
lpunpack "$super_file" "$super_img_tmp_dir"
fi
systemfile="$super_img_tmp_dir/${system_partition_name}.img"
systemfile_ext4="$super_img_tmp_dir/${system_partition_name}.img.ext4"
if file "$systemfile" | grep "Android sparse image"
then
resize_system_image "$systemfile_ext4"
else
resize_system_image "$systemfile"
fi
}
unpack_and_mount_image() { unpack_and_mount_image() {
local img="$1" local img="$1"
local loopdev local loopdev
...@@ -159,37 +181,30 @@ unpack_and_mount_image() { ...@@ -159,37 +181,30 @@ unpack_and_mount_image() {
cp "$img" "$update_img_tmp_dir/update.img" cp "$img" "$update_img_tmp_dir/update.img"
imgrepacker /skip "$update_img_tmp_dir/update.img" imgrepacker /skip "$update_img_tmp_dir/update.img"
rm -f "$update_img_tmp_dir/update.img" rm -f "$update_img_tmp_dir/update.img"
super_file="$update_img_tmp_dir/update.img.dump/super.fex" super_file="$update_img_tmp_dir/update.img.dump/super.fex"
super_file_ext4="$update_img_tmp_dir/update.img.dump/super.fex.ext4" super_file_ext4="$update_img_tmp_dir/update.img.dump/super.fex.ext4"
__unpack_super_img "$ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME"
if file "$super_file" | grep "Android sparse image"
then
simg2img "$super_file" "$super_file_ext4"
lpunpack "$super_file_ext4" "$super_img_tmp_dir"
else else
lpunpack "$super_file" "$super_img_tmp_dir" echo "Rockchip Format Detected.."
fi is_rockchip=1
systemfile="$super_img_tmp_dir/${ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME}.img" cp "$img" "$update_img_tmp_dir/update.img"
systemfile_ext4="$super_img_tmp_dir/${ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME}.img.ext4" mkdir -p "$update_img_tmp_dir/update.img.dump"
if file "$systemfile" | grep "Android sparse image" rkImageMaker -unpack "$update_img_tmp_dir/update.img" "$update_img_tmp_dir/update.img.dump"
then # workround: afptool 工具好像有路径读取问题
resize_system_image "$systemfile_ext4" pushd "$update_img_tmp_dir"
else afptool -unpack "./update.img.dump/firmware.img" "./update.img.dump"
resize_system_image "$systemfile"
fi
else
local update_img="${build_dir}/$(basename "$img")-update.img"
is_amlogic=0
img_unpack "$img" "$update_img"
# fix: afptool 只能用相对路径创建Image目录
pushd "$build_dir"
afptool -unpack "$update_img" "./img_dir"
popd popd
systemfile="$update_img_tmp_dir/Image/system.img" rm -f "$update_img_tmp_dir/update.img"
systemfile_ext4="$update_img_tmp_dir/Image/system.img.ext4" rm -f "$update_img_tmp_dir/update.img.dump/firmware.img"
rm -f "$update_img_tmp_dir/update.img.dump/boot.bin"
super_file="$update_img_tmp_dir/update.img.dump/Image/super.img"
super_file_ext4="$update_img_tmp_dir/update.img.dump/Image/super.img.ext4"
__unpack_super_img "$ROCKCHIP_DEFAULT_SYSTEM_PARTITION_NAME"
fi fi
if file "$systemfile" | grep "Android sparse image" if __is_sparse_system
then then
simg2img "$systemfile" "$systemfile_ext4" simg2img "$systemfile" "$systemfile_ext4"
loopdev=$(losetup -P -f --show "$systemfile_ext4") loopdev=$(losetup -P -f --show "$systemfile_ext4")
...@@ -278,13 +293,18 @@ install_dianxin() { ...@@ -278,13 +293,18 @@ install_dianxin() {
cp -f "$build_dir/hugep-all.zip" "$system_path"/bin/hugep-all.zip cp -f "$build_dir/hugep-all.zip" "$system_path"/bin/hugep-all.zip
find ./services/ -type f ! -name "*.rc" ! -name "*.zip" -exec install -m 0777 -t "$system_path"/bin/ {} \; find ./services/ -type f ! -name "*.rc" ! -name "*.zip" ! -name "hugep" ! -name "hugep-start.sh" -exec install -m 0777 -t "$system_path"/bin/ {} \;
for file in $(find ./services/ -type f ! -name "*.rc" ! -name "*.zip") for file in $(find ./services/ -type f ! -name "*.rc" ! -name "*.zip" ! -name "hugep" ! -name "hugep-start.sh")
do do
chcon u:object_r:drmserver_exec:s0 "$system_path/bin/$(basename "$file")" chcon u:object_r:drmserver_exec:s0 "$system_path/bin/$(basename "$file")"
done done
for file in $(find ./services/ -type f -name "*.zip")
do
chcon u:object_r:system_file:s0 "$system_path/bin/$(basename "$file")"
done
for file in $(find ./services/ -type f -name "*.rc" ! -name "*.zip") for file in $(find ./services/ -type f -name "*.rc" ! -name "*.zip")
do do
chcon u:object_r:drmserver_exec:s0 "$system_path/etc/init/$(basename "$file")" chcon u:object_r:drmserver_exec:s0 "$system_path/etc/init/$(basename "$file")"
...@@ -293,65 +313,163 @@ install_dianxin() { ...@@ -293,65 +313,163 @@ install_dianxin() {
pack_image "$img" pack_image "$img"
} }
pack_image() { __is_sparse_super() {
local img if file "$super_file" | grep "Android sparse image"
img="$1"
umount "$system_mount_point"
rm -rf "$system_mount_point"
sync
if [[ -f "$systemfile_ext4" ]]
then then
rm -f "$systemfile" return 0
img2simg "$systemfile_ext4" "$systemfile" else
rm -f "$systemfile_ext4" return 1
fi fi
}
outfile_path="${packge_dir}/${CHANNELID}-$(basename "$img")" __pack_super_img() {
if [[ "$is_amlogic" == "1" ]] local system_partition_name="$1"
then local c_super_file
echo "Amlogic Image Format Detected.." if __is_sparse_super
aml_image_v2_packer -r "/$build_dir/image.cfg" "$build_dir" "$outfile_path"
elif [[ "$is_allwinner" == "1" ]]
then
echo "Allwinner PhoenixSute Image Format Detected.."
local c_super_file=
if [[ -f "$super_file_ext4" ]]
then then
c_super_file="$super_file_ext4" c_super_file="$super_file_ext4"
else else
c_super_file="$super_file" c_super_file="$super_file"
fi fi
local c_group_name local c_group_name
c_group_name="$(get_group_name "$c_super_file" "$ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME")" c_group_name="$(get_group_name "$c_super_file" "$system_partition_name")"
if validate_partition_size_change "$c_super_file" "$ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME" if validate_partition_size_change "$c_super_file" "$system_partition_name"
then then
lpadd --readonly \ lpadd --readonly \
--replace \ --replace \
"$c_super_file" \ "$c_super_file" \
"$ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME" \ "$system_partition_name" \
"$c_group_name" \ "$c_group_name" \
"$systemfile" "$systemfile"
if [[ -f "$super_file_ext4" ]] if __is_sparse_super
then then
img2simg "$super_file_ext4" "$super_file" img2simg "$super_file_ext4" "$super_file"
rm -rf "$super_file_ext4" rm -rf "$super_file_ext4"
fi fi
else else
repack.sh "$c_super_file" "$c_group_name" "$systemfile" "$ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME" repack.sh "$c_super_file" "$c_group_name" "$systemfile" "$system_partition_name"
mv "$(dirname "$c_super_file")/super.new.img" "$c_super_file" if __is_sparse_super
then
mv "$(dirname "$c_super_file")/super.new.img" "$super_file"
else
simg2img "$(dirname "$c_super_file")/super.new.img" "$super_file"
rm -f "$(dirname "$c_super_file")/super.new.img"
fi
fi
}
__get_chip_from_parameter() {
local parameter_file
local chip
local arg
parameter_file="$1"
chip=$(grep "MACHINE:" "$parameter_file" | grep -P -o "rk\d+")
chip=${chip^^}
case $chip in
PX30 | RK3358)
parameter="RKPX30"
;;
RK1808 | RK3399PRO_NPU)
parameter="RK180A"
;;
RK3036)
parameter="RK303A"
;;
RK3126 | RK3128)
parameter="RK312A"
;;
RK3128H)
parameter="RK312X"
;;
RK3229)
parameter="RK3229"
;;
RK3288)
parameter="RK320A"
;;
RK3308)
parameter="RK3308"
;;
RK3326)
parameter="RK3326"
;;
RK3328)
parameter="RK322H"
;;
RK3399)
parameter="RK330C"
;;
RK3568)
parameter="RK3568"
;;
RK3566)
parameter="RK3568"
;;
RK3562)
parameter="RK3562"
;;
RK3588)
parameter="RK3588"
;;
RV1126)
parameter="RK1126"
;;
*)
echo "Bad MACHINE_MODEL: $chip in parameter.txt"
esac
printf "%s" "$parameter"
}
__is_sparse_system() {
if file "$systemfile" | grep "Android sparse image"
then
return 0
else
return 1
fi
}
pack_image() {
local img
img="$1"
umount "$system_mount_point"
rm -rf "$system_mount_point"
sync
if __is_sparse_system
then
rm -f "$systemfile"
img2simg "$systemfile_ext4" "$systemfile"
rm -f "$systemfile_ext4"
fi fi
outfile_path="${packge_dir}/${CHANNELID}-$(basename "$img")"
if [[ "$is_amlogic" == "1" ]]
then
echo "Amlogic Image Format Detected.."
aml_image_v2_packer -r "/$build_dir/image.cfg" "$build_dir" "$outfile_path"
elif [[ "$is_allwinner" == "1" ]]
then
echo "Allwinner PhoenixSute Image Format Detected.."
__pack_super_img "$ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME"
sleep 5 sleep 5
imgrepacker "$update_img_tmp_dir/update.img.dump" imgrepacker "$update_img_tmp_dir/update.img.dump"
mv "$update_img_tmp_dir/update.img" "$outfile_path" mv "$update_img_tmp_dir/update.img" "$outfile_path"
else elif [[ "$is_rockchip" == "1" ]]
local update_img_tmp_dir="$build_dir/img_dir" then
find "$update_img_tmp_dir/Image/" -name parameter.txt -exec cp {} "$update_img_tmp_dir/parameter" \; echo "Rockchip Image Format Detected.."
afptool -pack "$update_img_tmp_dir" "${outfile_path}.tmp" __pack_super_img "$ROCKCHIP_DEFAULT_SYSTEM_PARTITION_NAME"
cp "$build_dir/img_dir/Image/MiniLoaderAll.bin" "${packge_dir}/MiniLoaderAll.bin" cp -f "$update_img_tmp_dir/update.img.dump/MiniLoaderAll.bin" "$update_img_tmp_dir/update.img.dump/Image/MiniLoaderAll.bin"
img_maker "${packge_dir}/MiniLoaderAll.bin" "${outfile_path}.tmp" "$outfile_path" cp -f "$update_img_tmp_dir/update.img.dump/parameter.txt" "$update_img_tmp_dir/update.img.dump/Image/parameter.txt"
afptool -pack "$update_img_tmp_dir/update.img.dump" "$update_img_tmp_dir/update.img"
local chip_parameter
chip_parameter="$(__get_chip_from_parameter "${update_img_tmp_dir}/update.img.dump/parameter.txt")"
# e.g. rkImageMaker -RK322H output/MiniLoaderAll.bin output/Image/update.img update.img -os_type:androidos
rkImageMaker "-${chip_parameter}" \
"$update_img_tmp_dir/update.img.dump/MiniLoaderAll.bin" "$update_img_tmp_dir/update.img" "$outfile_path" \
-os_type:androidos
fi fi
rm -rf "$build_dir" rm -rf "$build_dir"
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment