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"
super_img_tmp_dir="$build_dir/img_dir/super"
ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME="system_a"
ROCKCHIP_DEFAULT_SYSTEM_PARTITION_NAME="system"
is_amlogic=0
is_allwinner=0
is_rockchip=0
outfile_path=""
......@@ -132,11 +134,31 @@ resize_system_image() {
qemu-img resize -f raw "$c_system_file" "$image_size"
loopdev=$(losetup -P -f --show "$c_system_file")
yes | e2fsck -f "$loopdev"
e2fsck -f -y "$loopdev"
resize2fs "$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() {
local img="$1"
local loopdev
......@@ -159,37 +181,30 @@ unpack_and_mount_image() {
cp "$img" "$update_img_tmp_dir/update.img"
imgrepacker /skip "$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_ext4="$update_img_tmp_dir/update.img.dump/super.fex.ext4"
if file "$super_file" | grep "Android sparse image"
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/${ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME}.img"
systemfile_ext4="$super_img_tmp_dir/${ALLWINNER_DEFAULT_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_super_img "$ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME"
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"
echo "Rockchip Format Detected.."
is_rockchip=1
cp "$img" "$update_img_tmp_dir/update.img"
mkdir -p "$update_img_tmp_dir/update.img.dump"
rkImageMaker -unpack "$update_img_tmp_dir/update.img" "$update_img_tmp_dir/update.img.dump"
# workround: afptool 工具好像有路径读取问题
pushd "$update_img_tmp_dir"
afptool -unpack "./update.img.dump/firmware.img" "./update.img.dump"
popd
systemfile="$update_img_tmp_dir/Image/system.img"
systemfile_ext4="$update_img_tmp_dir/Image/system.img.ext4"
rm -f "$update_img_tmp_dir/update.img"
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
if file "$systemfile" | grep "Android sparse image"
if __is_sparse_system
then
simg2img "$systemfile" "$systemfile_ext4"
loopdev=$(losetup -P -f --show "$systemfile_ext4")
......@@ -278,13 +293,18 @@ install_dianxin() {
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
chcon u:object_r:drmserver_exec:s0 "$system_path/bin/$(basename "$file")"
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")
do
chcon u:object_r:drmserver_exec:s0 "$system_path/etc/init/$(basename "$file")"
......@@ -293,6 +313,123 @@ install_dianxin() {
pack_image "$img"
}
__is_sparse_super() {
if file "$super_file" | grep "Android sparse image"
then
return 0
else
return 1
fi
}
__pack_super_img() {
local system_partition_name="$1"
local c_super_file
if __is_sparse_super
then
c_super_file="$super_file_ext4"
else
c_super_file="$super_file"
fi
local c_group_name
c_group_name="$(get_group_name "$c_super_file" "$system_partition_name")"
if validate_partition_size_change "$c_super_file" "$system_partition_name"
then
lpadd --readonly \
--replace \
"$c_super_file" \
"$system_partition_name" \
"$c_group_name" \
"$systemfile"
if __is_sparse_super
then
img2simg "$super_file_ext4" "$super_file"
rm -rf "$super_file_ext4"
fi
else
repack.sh "$c_super_file" "$c_group_name" "$systemfile" "$system_partition_name"
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"
......@@ -301,7 +438,7 @@ pack_image() {
rm -rf "$system_mount_point"
sync
if [[ -f "$systemfile_ext4" ]]
if __is_sparse_system
then
rm -f "$systemfile"
img2simg "$systemfile_ext4" "$systemfile"
......@@ -316,42 +453,23 @@ pack_image() {
elif [[ "$is_allwinner" == "1" ]]
then
echo "Allwinner PhoenixSute Image Format Detected.."
local c_super_file=
if [[ -f "$super_file_ext4" ]]
then
c_super_file="$super_file_ext4"
else
c_super_file="$super_file"
fi
local c_group_name
c_group_name="$(get_group_name "$c_super_file" "$ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME")"
if validate_partition_size_change "$c_super_file" "$ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME"
then
lpadd --readonly \
--replace \
"$c_super_file" \
"$ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME" \
"$c_group_name" \
"$systemfile"
if [[ -f "$super_file_ext4" ]]
then
img2simg "$super_file_ext4" "$super_file"
rm -rf "$super_file_ext4"
fi
else
repack.sh "$c_super_file" "$c_group_name" "$systemfile" "$ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME"
mv "$(dirname "$c_super_file")/super.new.img" "$c_super_file"
fi
__pack_super_img "$ALLWINNER_DEFAULT_SYSTEM_PARTITION_NAME"
sleep 5
imgrepacker "$update_img_tmp_dir/update.img.dump"
mv "$update_img_tmp_dir/update.img" "$outfile_path"
else
local update_img_tmp_dir="$build_dir/img_dir"
find "$update_img_tmp_dir/Image/" -name parameter.txt -exec cp {} "$update_img_tmp_dir/parameter" \;
afptool -pack "$update_img_tmp_dir" "${outfile_path}.tmp"
cp "$build_dir/img_dir/Image/MiniLoaderAll.bin" "${packge_dir}/MiniLoaderAll.bin"
img_maker "${packge_dir}/MiniLoaderAll.bin" "${outfile_path}.tmp" "$outfile_path"
elif [[ "$is_rockchip" == "1" ]]
then
echo "Rockchip Image Format Detected.."
__pack_super_img "$ROCKCHIP_DEFAULT_SYSTEM_PARTITION_NAME"
cp -f "$update_img_tmp_dir/update.img.dump/MiniLoaderAll.bin" "$update_img_tmp_dir/update.img.dump/Image/MiniLoaderAll.bin"
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
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