From 87465ea7353fc0a68ba90ab8cc32a7c22aa02ae6 Mon Sep 17 00:00:00 2001 From: Da Zheng Date: Sat, 30 Jul 2011 16:25:28 -0700 Subject: [PATCH] Create squashfs as the rootfs. This give users the choice to have rootfs formatted with squashfs. When --squash_image is specified, the rootfs will be formatted to squashfs. Users can also use --squash_sort_file to specify the file priority when squashfs is created. BUG=None TEST=Manually tested "--squash_image", and the image can be installed from USB stick. Also tried "--squash_sort_file=sort-prio.list", and files in squashfs are sorted. Change-Id: I5fd818ac9d1203598926efa82e94fa105cd86ebc Reviewed-on: http://gerrit.chromium.org/gerrit/5664 Tested-by: Da Zheng Reviewed-by: Da Zheng --- bin/cros_make_image_bootable | 38 ++++++++++++++++++++++++++++++++++-- build_kernel_image.sh | 11 +++++++++-- exclude-list | 2 ++ 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 exclude-list diff --git a/bin/cros_make_image_bootable b/bin/cros_make_image_bootable index a82348f9d0..6c59f05d05 100755 --- a/bin/cros_make_image_bootable +++ b/bin/cros_make_image_bootable @@ -128,6 +128,11 @@ DEFINE_string arm_extra_bootargs "" "DEPRECATED FLAG. Do not use." DEFINE_boolean force_developer_mode ${FLAGS_FALSE} \ "Add cros_debug to boot args." +DEFINE_boolean enable_squashfs ${FLAGS_FALSE} \ + "Make the rootfs of the image squashfs." +DEFINE_string squash_sort_file "" \ + "Specify the priority of files when squashing the rootfs." + # Parse the boot.desc and any overrides eval set -- "${BOOT_DESC} ${FLAG_OVERRIDES}" FLAGS "${@}" || exit 1 @@ -185,6 +190,17 @@ make_image_bootable() { FLAGS_boot_args="${FLAGS_boot_args} cros_debug" fi + local squash_sort_flag= + if [ -n "${FLAGS_squash_sort_file}" ]; then + squash_sort_flag="-sort ${FLAGS_squash_sort_file}" + fi + + if [ $FLAGS_enable_squashfs -eq $FLAGS_TRUE ]; then + local squashfs_img="${FLAGS_output_dir}/squashfs.image" + sudo mksquashfs "${FLAGS_rootfs_mountpoint}" ${squashfs_img} -comp lzo \ + -noI -noF -ef ${SCRIPTS_DIR}/exclude-list -wildcards ${squash_sort_flag} + root_dev=$squashfs_img + fi # Builds the kernel partition image. The temporary files are kept around # so that we can perform a load_kernel_test later on the final image. ${SCRIPTS_DIR}/build_kernel_image.sh \ @@ -214,7 +230,12 @@ make_image_bootable() { # loop devices. This means that they are not the correct size. We have to # write directly to the image to append the hash tree data. local hash_offset="$(partoffset ${image} 3)" - hash_offset=$((hash_offset + ((1024 * 1024 * ${FLAGS_rootfs_size}) / 512))) + if [ $FLAGS_enable_squashfs -eq $FLAGS_TRUE ]; then + rootfs_file_size=$(stat -c '%s' ${root_dev}) + hash_offset=$((hash_offset + (${rootfs_file_size} / 512))) + else + hash_offset=$((hash_offset + ((1024 * 1024 * ${FLAGS_rootfs_size}) / 512))) + fi sudo dd bs=512 \ seek=${hash_offset} \ if="${FLAGS_rootfs_hash}" \ @@ -273,6 +294,16 @@ make_image_bootable() { trap - EXIT ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${FLAGS_rootfs_mountpoint}" \ -s "${FLAGS_statefulfs_mountpoint}" + + # I can only copy the squashfs image to the image only when it is umounted. + if [ $FLAGS_enable_squashfs -eq $FLAGS_TRUE ]; then + # copy the squashfs image to the partition + info "copy the squashfs to the partition" + local part_offset="$(partoffset ${image} 3)" + sudo dd bs=512 if="${squashfs_img}" of="${image}" \ + seek=${part_offset} conv=notrunc + sudo rm "${squashfs_img}" + fi } verify_image_rootfs() { @@ -309,7 +340,10 @@ mkdir -p ${FLAGS_statefulfs_mountpoint} mkdir -p ${FLAGS_espfs_mountpoint} make_image_bootable "${IMAGE}" -if [ ${FLAGS_fsck_rootfs} -eq ${FLAGS_TRUE} ]; then +# We can't verify the image if squashfs is enabled because the kernel +# on the host does not support squashfs with LZO +if [ ${FLAGS_fsck_rootfs} -eq ${FLAGS_TRUE} \ + -a ${FLAGS_enable_squashfs} -eq ${FLAGS_FALSE} ]; then verify_image_rootfs "${IMAGE}" fi diff --git a/build_kernel_image.sh b/build_kernel_image.sh index c50521ea75..6c5c72f7d3 100755 --- a/build_kernel_image.sh +++ b/build_kernel_image.sh @@ -80,14 +80,21 @@ verity_args= # Even with a rootfs_image, root= is not changed unless specified. if [[ -n "${FLAGS_rootfs_image}" && -n "${FLAGS_rootfs_hash}" ]]; then # Gets the number of blocks. 4096 byte blocks _are_ expected. - root_fs_blocks=$(sudo dumpe2fs "${FLAGS_rootfs_image}" 2> /dev/null | + if [ -f "${FLAGS_rootfs_image}" ]; then + root_fs_block_sz=4096 + root_fs_sz=$(stat -c '%s' ${FLAGS_rootfs_image}) + root_fs_blocks=$((root_fs_sz / ${root_fs_block_sz})) + else + root_fs_blocks=$(sudo dumpe2fs "${FLAGS_rootfs_image}" 2> /dev/null | grep "Block count" | tr -d ' ' | cut -f2 -d:) - root_fs_block_sz=$(sudo dumpe2fs "${FLAGS_rootfs_image}" 2> /dev/null | + root_fs_block_sz=$(sudo dumpe2fs "${FLAGS_rootfs_image}" 2> /dev/null | grep "Block size" | tr -d ' ' | cut -f2 -d:) + fi + info "rootfs is ${root_fs_blocks} blocks of ${root_fs_block_sz} bytes" if [[ ${root_fs_block_sz} -ne 4096 ]]; then error "Root file system blocks are not 4k!" diff --git a/exclude-list b/exclude-list new file mode 100644 index 0000000000..cc9da248f3 --- /dev/null +++ b/exclude-list @@ -0,0 +1,2 @@ +var/* +usr/local/*