blob: 657bc92deb81f5e3f9781b4776a15015dcb7a01b [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001STATE_DIR_IMAGE_SIZE ?= "${MKUBIFS_USRDATA_IMAGE_SZ}"
2STATE_DIR_IMAGE_PATH = "${DEPLOY_DIR_IMAGE}/userdata"
3STATE_DIR_CONTENT = "${IMAGE_ROOTFS}/../usrdata"
4IMAGE_FSTYPES_NO_WHITESPACE="$(echo "${IMAGE_FSTYPES}" | tr -d '[:space:]')"
5USERDATA_FS_PARTITION = "userdata_fs.ubi"
6USERDATA_PARTITION = "userdata.ubi"
7CRYPT_HOST_TOOL = "${TOPDIR}/../src/devtools/nfsb/crypt_tool/crypt_host_tool"
8DEPENDS += "mtd-utils-native"
9mk_userdata_image() {
10 mkdir -p ${STATE_DIR_CONTENT}/tmp
11 mkdir -p ${STATE_DIR_CONTENT}/etc
12 mkdir -p ${STATE_DIR_CONTENT}/var
13 mkdir -p ${STATE_DIR_CONTENT}/usr
14 mkdir -p ${STATE_DIR_CONTENT}/usr/bin
15 mkdir -p ${STATE_DIR_CONTENT}/usr/sbin
16 mkdir -p ${STATE_DIR_CONTENT}/config
17
18 if [ -d ${IMAGE_ROOTFS}/data ]; then
19 cp -a ${IMAGE_ROOTFS}/data/* ${STATE_DIR_CONTENT}
20 rm -rf ${IMAGE_ROOTFS}/data/*
21 fi
22 if test "${CONFIG_ICU_SUPPORT}" = "no"; then
23 rm -fr ${IMAGE_ROOTFS}/usr/lib/libicudata.so.59.1
24 rm -fr ${IMAGE_ROOTFS}/usr/lib/libicui18n.so.59.1
25 rm -fr ${IMAGE_ROOTFS}/usr/lib/libicuuc.so.59.1
26 fi
27
28 rm -rf ${STATE_DIR_IMAGE_PATH}
29
30 install -d ${STATE_DIR_CONTENT}
31
32 for i in ${STATE_DIR_CONTENT}; do
33 STATE_DIR_FILE_PATH=${STATE_DIR_IMAGE_PATH}/${i##${STATE_DIR_CONTENT}}
34 install -d ${STATE_DIR_FILE_PATH}
35 if [ "$(ls -A ${i})" ]; then
36 cp -a ${i}/* ${STATE_DIR_FILE_PATH}
37 else
38 echo "${i} is empty"
39 fi
40 done
41
42 if test "${IMAGE_FSTYPES_NO_WHITESPACE}" = "ubi"; then
43 echo \[ubifs\] > ubinize.cfg
44 echo mode=ubi >> ubinize.cfg
45 echo image=${USERDATA_FS_PARTITION} >> ubinize.cfg
46 echo vol_id=0 >> ubinize.cfg
47 echo vol_size=${MKUBIFS_USRDATA_VOL_SZ}
48 echo vol_type=dynamic >> ubinize.cfg
49 echo vol_name=useradata >> ubinize.cfg
50 echo vol_flags=autoresize >> ubinize.cfg
51 dd if=/dev/zero of=${DEPLOY_DIR_IMAGE}/${USERDATA_FS_PARTITION} seek=${STATE_DIR_IMAGE_SIZE} count=0 bs=1k
52 mkfs.ubifs -r ${STATE_DIR_FILE_PATH} ${MKUBIFS_USRDATA_ARGS} -o ${USERDATA_FS_PARTITION}
53 ubinize -o ${USERDATA_PARTITION} ${UBINIZE_ARGS} ubinize.cfg
54 cp ${USERDATA_PARTITION} ${DEPLOY_DIR_IMAGE}/${USERDATA_PARTITION}
55 elif test "${IMAGE_FSTYPES_NO_WHITESPACE}" = "ext4"; then
56 STATE_PARTITION="userdata.ext4"
57 dd if=/dev/zero of=${DEPLOY_DIR_IMAGE}/${STATE_PARTITION} seek=${STATE_DIR_IMAGE_SIZE} count=${MKEXT4_USRDATA_CNT} bs=1k
58 mkfs.ext4 -F -i 4096 ${DEPLOY_DIR_IMAGE}/${STATE_PARTITION} -d ${STATE_DIR_IMAGE_PATH}
59 if test "${ENABLE_USRDATA_DM_CRYPT}" = "yes"; then
60 mv ${DEPLOY_DIR_IMAGE}/${STATE_PARTITION} ${DEPLOY_DIR_IMAGE}/plain_${STATE_PARTITION}
61 ${CRYPT_HOST_TOOL} ${DM_CRYPT_ALG} `cat ${MTK_KEY_DIR}/${DM_CRYPT_KEY}` 0 0 ${DEPLOY_DIR_IMAGE}/plain_${STATE_PARTITION} ${DEPLOY_DIR_IMAGE}/${STATE_PARTITION} usrdata `cat ${MTK_KEY_DIR}/${DM_PROTECT_KEY}`
62 fi
63 else
64 echo "No method to make ${IMAGE_FSTYPES_NO_WHITESPACE} type state image"
65 fi
66}
67
68ROOTFS_POSTPROCESS_COMMAND += " mk_userdata_image;"
69
70