RK 打包脚本 make_ext4fs system.img 、RK3399 Google编译

https://blog.csdn.net/ttxgz/article/details/7542380

一.打包到system.img 报的问题 生成镜像时提示Out of space

1.1.mkimage.sh

#!/bin/bash
set -e
cp -rf  kernel/arch/arm/boot/zImage  									out/target/product/rk312x/kernel

if [ x$1 == x31a ]; then
	MODEL="ZK-R31A"
fi
sed  -i  '/ro.product.usb_model=/s/=.*/='$MODEL'/g'   out/target/product/rk312x/system/build.prop
sed  -i  '/ro.product.model=/s/=.*/='$MODEL'/g'   out/target/product/rk312x/system/build.prop
. build/envsetup.sh >/dev/null && setpaths

export PATH=$ANDROID_BUILD_PATHS:$PATH
TARGET_PRODUCT=`get_build_var TARGET_PRODUCT`
TARGET_HARDWARE=`get_build_var TARGET_BOARD_HARDWARE`
TARGET_DEVICE_DIR=`get_build_var TARGET_DEVICE_DIR`
echo TARGET_PRODUCT=$TARGET_PRODUCT
echo TARGET_HARDWARE=$TARGET_HARDWARE
TARGET="withoutkernel"
if [ "$2"x != ""x  ]; then
         TARGET=$2
fi

IMAGE_PATH=rockdev/Image-$TARGET_PRODUCT

KERNEL_PATH=kernel
KERNEL_CONFIG=$KERNEL_PATH/.config
rm -rf $IMAGE_PATH
mkdir -p $IMAGE_PATH
UBOOT_PATH=u-boot
PARAMETER=${TARGET_DEVICE_DIR}/rk312x.parameter.txt
FSTYPE=ext4
echo system filesysystem is $FSTYPE

BOARD_CONFIG=device/rockchip/common/device.mk

KERNEL_SRC_PATH=`grep TARGET_PREBUILT_KERNEL ${BOARD_CONFIG} |grep "^\s*TARGET_PREBUILT_KERNEL *:= *[\w]*\s" |awk  '{print $3}'`

[ $(id -u) -eq 0 ] || FAKEROOT=fakeroot

BOOT_OTA="ota"

[ $TARGET != $BOOT_OTA -a $TARGET != "withoutkernel" ] && echo "unknow target[${TARGET}],exit!" && exit 0

    if [ ! -f $OUT/kernel ]
    then
	    echo "kernel image not fount![$OUT/kernel] "
        read -p "copy kernel from TARGET_PREBUILT_KERNEL[$KERNEL_SRC_PATH] (y/n) n to exit?"
        if [ "$REPLY" == "y" ]
        then
            [ -f $KERNEL_SRC_PATH ]  || \
                echo -n "fatal! TARGET_PREBUILT_KERNEL not eixit! " || \
                echo -n "check you configuration in [${BOARD_CONFIG}] " || exit 0

            cp ${KERNEL_SRC_PATH} $OUT/kernel

        else
            exit 0
        fi
    fi

if [ $TARGET == $BOOT_OTA ]
then
	echo "make ota images... "
	echo -n "create boot.img with kernel... "
	[ -d $OUT/root ] && \
	mkbootfs $OUT/root | minigzip > $OUT/ramdisk.img && \
        truncate -s "%4" $OUT/ramdisk.img && \
	mkbootimg --kernel $OUT/kernel --ramdisk $OUT/ramdisk.img --second kernel/resource.img --output $OUT/boot.img && \
	cp -a $OUT/boot.img $IMAGE_PATH/
	echo "done."
else
	echo -n "create boot.img without kernel... "
	[ -d $OUT/root ] && \
	mkbootfs $OUT/root | minigzip > $OUT/ramdisk.img && \
        truncate -s "%4" $OUT/ramdisk.img && \
	rkst/mkkrnlimg $OUT/ramdisk.img $IMAGE_PATH/boot.img >/dev/null
	echo "done."
fi
if [ $TARGET == $BOOT_OTA ]
then
	echo -n "create recovery.img with kernel... "
	[ -d $OUT/recovery/root ] && \
	mkbootfs $OUT/recovery/root | minigzip > $OUT/ramdisk-recovery.img && \
        truncate -s "%4" $OUT/ramdisk-recovery.img && \
	mkbootimg --kernel $OUT/kernel --ramdisk $OUT/ramdisk-recovery.img --second kernel/resource.img  --output $OUT/recovery.img && \
	cp -a $OUT/recovery.img $IMAGE_PATH/
	echo "done."
else
	echo -n "create recovery.img with kernel and with out resource... "
	[ -d $OUT/recovery/root ] && \
	mkbootfs $OUT/recovery/root | minigzip > $OUT/ramdisk-recovery.img && \
        truncate -s "%4" $OUT/ramdisk-recovery.img && \
	mkbootimg --kernel $OUT/kernel --ramdisk $OUT/ramdisk-recovery.img --output $OUT/recovery.img && \
	cp -a $OUT/recovery.img $IMAGE_PATH/
	echo "done."
fi
	echo -n "create misc.img.... "
	cp -a rkst/Image/misc.img $IMAGE_PATH/misc.img
	cp -a rkst/Image/pcba_small_misc.img $IMAGE_PATH/pcba_small_misc.img
	cp -a rkst/Image/pcba_whole_misc.img $IMAGE_PATH/pcba_whole_misc.img
	echo "done."
if [ `grep "CONFIG_BUILD_REALTEK_WIFI_MODULES=y" $KERNEL_CONFIG` ]; then
	echo "Install wifi ko to $OUT/system/lib/modules/"
	mkdir -p $OUT/system/lib/modules/
	find kernel/drivers/net/wireless/rockchip_wlan/*  -name "*.ko" | xargs -n1 -i cp {} $OUT/system/lib/modules/
fi
if [ -f $UBOOT_PATH/*Loader*.bin ]; then
		echo -n "create loader..."
		cd $UBOOT_PATH&&make&& cd ..
		echo -n "make loader..."
		cp -a $UBOOT_PATH/*Loader*.bin $IMAGE_PATH/RK3128MiniLoaderAll_V2.31.bin
		cp -a $UBOOT_PATH/uboot.img $IMAGE_PATH/uboot.img
		echo "done."
fi
if [ -f $PARAMETER ];then
				echo -n "create parameter..."
	      cp -a $PARAMETER $IMAGE_PATH/rk312x.parameter.txt
	      echo "done."
else
				echo "${TARGET_DEVICE_DIR}/rk312x.parameter.txt not fount!"
fi
if [ -d $OUT/system ]
then
	echo -n "create system.img... "
	if [ "$FSTYPE" = "cramfs" ]
	then
		chmod -R 777 $OUT/system
		$FAKEROOT mkfs.cramfs $OUT/system $IMAGE_PATH/system.img
	elif [ "$FSTYPE" = "squashfs" ]
	then
		chmod -R 777 $OUT/system
		mksquashfs $OUT/system $IMAGE_PATH/system.img -all-root >/dev/null
	elif [ "$FSTYPE" = "ext3" ] || [ "$FSTYPE" = "ext4" ]
	then
                system_size=`ls -l $OUT/system.img | awk '{print $5;}'`
                [ $system_size -gt "0" ] || { echo "Please make first!!!" && exit 1; }
                MAKE_EXT4FS_ARGS=" -L system -S $OUT/root/file_contexts -a system $IMAGE_PATH/system.img $OUT/system"
		ok=0
		while [ "$ok" = "0" ]; do
			make_ext4fs -l $system_size $MAKE_EXT4FS_ARGS >/dev/null 2>&1 &&
			tune2fs -c -1 -i 0 $IMAGE_PATH/system.img >/dev/null 2>&1 &&
			ok=1 || system_size=$(($system_size + 5242880))
		done
		e2fsck -fyD $IMAGE_PATH/system.img >/dev/null 2>&1 || true
	else
		mkdir -p $IMAGE_PATH/2k $IMAGE_PATH/4k
		mkyaffs2image -c 2032 -s 16 -f $OUT/system $IMAGE_PATH/2k/system.img
		mkyaffs2image -c 4080 -s 16 -f $OUT/system $IMAGE_PATH/4k/system.img
	fi
	echo "done."
fi

chmod a+r -R $IMAGE_PATH/

1.2.这个错误是由于增加了预置apk,导致system.img超过了分配的空间大小导致的

make loader...done.
create parameter...done.
create system.img... ./mkimage.sh: line 151: 12094 Segmentation fault      (core dumped) make_ext4fs -l $system_size MAKE_EXT4FS_ARGS > /dev/null 2>&1
done.

1.3.解决办法 给system加536M 

--- a/device/rockchip/common/BoardConfig.mk
+++ b/device/rockchip/common/BoardConfig.mk
@@ -79,7 +79,7 @@ TARGET_PROVIDES_INIT_RC ?= false
 BOARD_HAL_STATIC_LIBRARIES ?= libdumpstate.$(TARGET_PRODUCT) libhealthd.$(TARGET_PRODUCT)
 
 //MAX-SIZE=512M, for generate out/.../system.img
-BOARD_SYSTEMIMAGE_PARTITION_SIZE ?= 1073741824
+BOARD_SYSTEMIMAGE_PARTITION_SIZE ?= 1610612736
 BOARD_FLASH_BLOCK_SIZE ?= 131072

 二编译Google包 分区不足

error: ext4_allocate_best_fit_partial: failed to allocate 139 blocks, out of space?
Creating filesystem with parameters:
    Size: 1199996928
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 8144
    Inode size: 256
    Journal blocks: 4577
    Label: system
    Blocks: 292968
    Block groups: 9
    Reserved block group size: 71
Out of space? the tree size of out/target/product/rk3399_box/system is (MB): 
1189	out/target/product/rk3399_box/system
The max is 1144 MB.

 加大system     2147483648 ->2G

--- a/device/rockchip/rk3399/BoardConfig.mk
+++ b/device/rockchip/rk3399/BoardConfig.mk
@@ -76,7 +76,7 @@ BOARD_OPENGL_AEP := true
 
 
 //MAX-SIZE=2G, for generate out/.../system.img
-BOARD_SYSTEMIMAGE_PARTITION_SIZE := 1610612736
+BOARD_SYSTEMIMAGE_PARTITION_SIZE := 2147483648

 三.RK3399 Google GMS包编译、Google服务

--- a/device/rockchip/rk3399/rk3399_all.mk
+++ b/device/rockchip/rk3399/rk3399_all.mk
@@ -33,7 +33,7 @@ endif
 BOARD_USE_APP_ALARM_ALIGNMENT ?= false
 
 # google apps
-BUILD_WITH_GOOGLE_MARKET := false
+BUILD_WITH_GOOGLE_MARKET := true
 BUILD_WITH_GOOGLE_MARKET_ALL := false
 BUILD_WITH_GOOGLE_FRP := false

 3.1.device\rockchip\common\device.mk  gms.mk 编译的谷歌服务

ifeq ($(strip $(BUILD_WITH_GOOGLE_MARKET)), true)
ifeq ($(strip $(BUILD_WITH_GOOGLE_MARKET_ALL)), true)
$(call inherit-product-if-exists, vendor/partner_gms/products/gms.mk)
else
$(call inherit-product-if-exists, vendor/partner_gms/products/gms-mandatory.mk)
endif
endif

vendor\partner_gms\products\gms.mk 

 

 

posted @ 2021-07-13 17:33  CrushGirl  阅读(1475)  评论(0编辑  收藏  举报