rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | STATE_DIR_IMAGE_SIZE ?= "131072"
|
| 2 | STATE_DIR_IMAGE_PATH = "${DEPLOY_DIR_IMAGE}/state"
|
| 3 | STATE_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"
|
| 4 | IMAGE_FSTYPES_NO_WHITESPACE="$(echo "${IMAGE_FSTYPES}" | tr -d '[:space:]')"
|
| 5 | DEPENDS += "mtd-utils-native"
|
| 6 |
|
| 7 | mk_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]
|
| 31 | mode=ubi
|
| 32 | image=${DEPLOY_DIR_IMAGE}/${STATE_PARTITION}
|
| 33 | vol_id=0
|
| 34 | vol_type=dynamic
|
| 35 | vol_name=state
|
| 36 | vol_flags=autoresize
|
| 37 | EOF
|
| 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 |
|
| 49 | ROOTFS_POSTPROCESS_COMMAND += " mk_state_image;"
|
| 50 |
|
| 51 | mk_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 |
|
| 58 | ROOTFS_PREPROCESS_COMMAND += " mk_rootfs_folder;"
|
| 59 |
|
| 60 | do_sparse_userdata_image() {
|
| 61 | if test -e ${DEPLOY_DIR_IMAGE}/userdata.ubi ; then
|
| 62 | img2simg ${DEPLOY_DIR_IMAGE}/userdata.ubi ${DEPLOY_DIR_IMAGE}/userdata.img
|
| 63 | elif test -e ${DEPLOY_DIR_IMAGE}/userdata.ext4 ; then
|
| 64 | img2simg ${DEPLOY_DIR_IMAGE}/userdata.ext4 ${DEPLOY_DIR_IMAGE}/userdata.img
|
| 65 | fi
|
| 66 | }
|
| 67 |
|
| 68 | do_image_complete[postfuncs] += "do_sparse_userdata_image"
|