blob: 446d4ca8db3ad4b045f7ab716b52633bfdc00bac [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001STATE_DIR_IMAGE_SIZE ?= "131072"
2STATE_DIR_IMAGE_PATH = "${DEPLOY_DIR_IMAGE}/state"
3STATE_DIR_CONTENT ?= "${IMAGE_ROOTFS}/home ${IMAGE_ROOTFS}/var ${IMAGE_ROOTFS}/usr/lib/tmpfiles.d ${STATE_DIR_IMAGE_PATH}/usr/local ${STATE_DIR_IMAGE_PATH}/srv"
4IMAGE_FSTYPES_NO_WHITESPACE="$(echo "${IMAGE_FSTYPES}" | tr -d '[:space:]')"
5DEPENDS += "mtd-utils-native"
6
7mk_state_image() {
8 rm -rf ${STATE_DIR_IMAGE_PATH}
9 install -d ${STATE_DIR_CONTENT}
10 for i in ${STATE_DIR_CONTENT}; do
11 STATE_DIR_FILE_PATH=${STATE_DIR_IMAGE_PATH}/${i##${IMAGE_ROOTFS}}
12 install -d ${STATE_DIR_FILE_PATH}
13 cp -a ${i}/. ${STATE_DIR_FILE_PATH}
14 done
15
16 # remove package management data
17 if [ -d "${STATE_DIR_IMAGE_PATH}/var/lib/dnf" ]; then
18 rm -rf ${STATE_DIR_IMAGE_PATH}/var/lib/dnf
19 fi
20 if [ -d "${STATE_DIR_IMAGE_PATH}/var/lib/rpm" ]; then
21 rm -rf ${STATE_DIR_IMAGE_PATH}/var/lib/rpm
22 fi
23
24 if test "${IMAGE_FSTYPES_NO_WHITESPACE}" = "ubi" || test "${IMAGE_FSTYPES_NO_WHITESPACE}" = "squashfs"; then
25 STATE_PARTITION="userdata.ubifs"
26 STATE_UBI="userdata.ubi"
27 STATE_UBINIZE_CFG="ubinize-state.cfg"
28 dd if=/dev/zero of=${DEPLOY_DIR_IMAGE}/${STATE_PARTITION} seek=${STATE_DIR_IMAGE_SIZE} count=0 bs=1k
29 cat << EOF > ${STATE_UBINIZE_CFG}
30[ubifs]
31mode=ubi
32image=${DEPLOY_DIR_IMAGE}/${STATE_PARTITION}
33vol_id=0
34vol_type=dynamic
35vol_name=state
36vol_flags=autoresize
37EOF
38 mkfs.ubifs -r ${STATE_DIR_IMAGE_PATH} -o ${DEPLOY_DIR_IMAGE}/${STATE_PARTITION} ${MKUBIFS_ARGS}
39 ubinize -o ${DEPLOY_DIR_IMAGE}/${STATE_UBI} ${UBINIZE_ARGS} ${STATE_UBINIZE_CFG}
40 elif test "${IMAGE_FSTYPES_NO_WHITESPACE}" = "ext4"; then
41 STATE_PARTITION="userdata.ext4"
42 dd if=/dev/zero of=${DEPLOY_DIR_IMAGE}/${STATE_PARTITION} seek=${STATE_DIR_IMAGE_SIZE} count=0 bs=1k
43 mkfs.ext4 -F -i 4096 ${DEPLOY_DIR_IMAGE}/${STATE_PARTITION} -d ${STATE_DIR_IMAGE_PATH}
44 else
45 echo "No method to make ${IMAGE_FSTYPES_NO_WHITESPACE} type state image"
46 fi
47}
48
49ROOTFS_POSTPROCESS_COMMAND += " mk_state_image;"
50
51mk_rootfs_folder() {
52 install -d ${IMAGE_ROOTFS}/mnt/userdata ${IMAGE_ROOTFS}/srv
53 if test "${DISTRO}" != "poky-agl"; then
54 install -d ${IMAGE_ROOTFS}/usr/local
55 fi
56}
57
58ROOTFS_PREPROCESS_COMMAND += " mk_rootfs_folder;"
59
60do_sparse_userdata_image() {
61if test -e ${DEPLOY_DIR_IMAGE}/userdata.ubi ; then
62 img2simg ${DEPLOY_DIR_IMAGE}/userdata.ubi ${DEPLOY_DIR_IMAGE}/userdata.img
63elif test -e ${DEPLOY_DIR_IMAGE}/userdata.ext4 ; then
64 img2simg ${DEPLOY_DIR_IMAGE}/userdata.ext4 ${DEPLOY_DIR_IMAGE}/userdata.img
65fi
66}
67
68do_image_complete[postfuncs] += "do_sparse_userdata_image"