From ddeb9c8e76090dea46b56efcc3720cb197b6da51 Mon Sep 17 00:00:00 2001 From: Dominik Adamski Date: Fri, 16 Nov 2018 09:14:56 +0100 Subject: [PATCH] Make vfat partition offset dependent on alignment and U-Boot env space In case of BBB only partition alignment takes part in offset calculation. In case of RPI3 besides partition alignment also the U-Boot environment spaces must be considered. Issues: MEN-2241 Signed-off-by: Dominik Adamski --- mender-convert | 35 ++++++++------- mender-convert-functions.sh | 85 +++++++++++++++++++++++++------------ 2 files changed, 76 insertions(+), 44 deletions(-) diff --git a/mender-convert b/mender-convert index 74c93f3..50a9557 100755 --- a/mender-convert +++ b/mender-convert @@ -196,6 +196,9 @@ do_raw_disk_image_shrink_rootfs() { local rootfssize= local bootflag= + # For root filesystem partition set 8MB alignment for shrinking purpose. + partition_alignment=$PART_ALIGN_8MB + # Gather information about raw disk image. get_image_info $raw_disk_image count sector_size bootstart bootsize \ rootfsstart rootfssize bootflag @@ -287,8 +290,10 @@ do_raw_disk_image_create_partitions() { mender_disk_image=$output_dir/mender-${device_type}-${artifact_name}.sdimg fi - analyse_raw_disk_image ${raw_disk_image} pboot_start pboot_size prootfs_size \ - sector_size raw_disk_counts + set_boot_part_alignment $device_type partition_alignment vfat_storage_offset + + analyse_raw_disk_image ${raw_disk_image} ${partition_alignment} ${vfat_storage_offset} \ + pboot_start pboot_size prootfs_size sector_size raw_disk_counts [ -z "${prootfs_size}" ] && \ { log "root filesystem size not set. Aborting."; return 1; } @@ -302,14 +307,11 @@ do_raw_disk_image_create_partitions() { log "\tCreating Mender disk image:\ \n\t\timage size: ${mender_disk_image_size} bytes\ + \n\t\tboot partition size: $((${pboot_size} * $sector_size)) bytes\ \n\t\troot filesystem size: $((${prootfs_size} * $sector_size)) bytes\ \n\t\tdata partition size: $(($pdata_size * $sector_size)) bytes" - local vfat_storage_offset= - [[ $raw_disk_counts -eq 1 ]] && { vfat_storage_offset=$vfat_storage_offset_regular; } \ - || { vfat_storage_offset=$vfat_storage_offset_extended; } - - create_test_config_file $device_type $partition_alignment $vfat_storage_offset \ + create_test_config_file $device_type $partition_alignment $pboot_start \ $pboot_size $prootfs_size $pdata_size $mender_disk_image_size \ $sector_size @@ -379,11 +381,11 @@ do_make_sdimg_beaglebone() { do_make_sdimg_raspberrypi3() { log "$step/$total Setting boot partition..." ((step++)) - image_boot_part=$(fdisk -l ${raw_disk_image} | grep FAT32) + local image_boot_part=$(fdisk -l ${raw_disk_image} | grep FAT32) - boot_part_start=$(echo ${image_boot_part} | awk '{print $2}') - boot_part_end=$(echo ${image_boot_part} | awk '{print $3}') - boot_part_size=$(echo ${image_boot_part} | awk '{print $4}') + local boot_part_start=$(echo ${image_boot_part} | awk '{print $2}') + local boot_part_end=$(echo ${image_boot_part} | awk '{print $3}') + local boot_part_size=$(echo ${image_boot_part} | awk '{print $4}') log "\tExtracting boot partition from raw disk image." extract_file_from_image ${raw_disk_image} ${boot_part_start} \ @@ -395,11 +397,11 @@ do_make_sdimg_raspberrypi3() { log "$step/$total Setting root filesystem partition..." ((step++)) - image_rootfs_part=$(fdisk -l ${raw_disk_image} | grep Linux) + local image_rootfs_part=$(fdisk -l ${raw_disk_image} | grep Linux) - rootfs_part_start=$(echo ${image_rootfs_part} | awk '{print $2}') - rootfs_part_end=$(echo ${image_rootfs_part} | awk '{print $3}') - rootfs_part_size=$(echo ${image_rootfs_part} | awk '{print $4}') + local rootfs_part_start=$(echo ${image_rootfs_part} | awk '{print $2}') + local rootfs_part_end=$(echo ${image_rootfs_part} | awk '{print $3}') + local rootfs_part_size=$(echo ${image_rootfs_part} | awk '{print $4}') log "\tExtracting root filesystem partition from raw disk image." extract_file_from_image ${raw_disk_image} ${rootfs_part_start} \ @@ -508,7 +510,8 @@ do_install_bootloader_to_mender_disk_image() { [[ $ret -ne 0 ]] && { log "\nInstalling Bootloader failed."; return $ret; } # Update test configuration file - update_test_config_file $device_type mount-location "\/uboot" + update_test_config_file $device_type distro-feature "mender-uboot" \ + mount-location "\/uboot" ;; esac diff --git a/mender-convert-functions.sh b/mender-convert-functions.sh index d4a429a..7dc8563 100755 --- a/mender-convert-functions.sh +++ b/mender-convert-functions.sh @@ -1,16 +1,17 @@ #!/bin/bash -# Partition alignment value in bytes (8MB). -partition_alignment=8388608 -# Boot partition storage offset in bytes (equal to alignment). -vfat_storage_offset_regular=$partition_alignment -#erase_block=12582912 -# Boot partition storage offset in bytes (alignment * 2). -vfat_storage_offset_extended=$(($partition_alignment*2 )) +# Partition alignment value in bytes. +declare -i partition_alignment +# Boot partition storage offset in bytes. +declare -i vfat_storage_offset + +PART_ALIGN_4MB=4194304 +PART_ALIGN_8MB=8388608 + # Number of required heads in a final image. -heads=255 +declare -i -r heads=255 # Number of required sectors in a final image. -sectors=63 +declare -i -r sectors=63 declare -a mender_disk_partitions=("boot" "primary" "secondary" "data") declare -a raw_disk_partitions=("boot" "rootfs") @@ -183,6 +184,33 @@ get_image_info() { { return 0; } } +# Takes the following argument +# $1 - device type +# +# Calculates the following arguments: +# $2 - partition alignment +# $3 - vfat storage offset + +set_boot_part_alignment() { + local rvar_partition_alignment=$2 + local rvar_vfat_storage_offset=$3 + + case "$1" in + "beaglebone") + local lvar_partition_alignment=${PART_ALIGN_8MB} + local lvar_vfat_storage_offset=$lvar_partition_alignment + ;; + "raspberrypi3") + local lvar_partition_alignment=${PART_ALIGN_4MB} + local lvar_uboot_env_size=$(( $lvar_partition_alignment * 2 )) + local lvar_vfat_storage_offset=$(( $lvar_partition_alignment + $lvar_uboot_env_size )) + ;; + esac + + eval $rvar_partition_alignment="'$lvar_partition_alignment'" + eval $rvar_vfat_storage_offset="'$lvar_vfat_storage_offset'" +} + # Takes following arguments: # # $1 - raw disk image path @@ -244,7 +272,7 @@ get_mender_disk_info() { # $2 - size of the sector # align_partition_size() { - # Final size is aligned to 8MiB. + # Final size is aligned with reference to 'partition_alignment' variable. local rvar_size=$1 local -n ref=$1 @@ -263,16 +291,20 @@ align_partition_size() { # Takes following arguments: # # $1 - raw_disk image +# $2 - partition alignment +# $3 - vfat storage offset # # Returns: # -# $2 - boot partition start offset (in sectors) -# $3 - boot partition size (in sectors) -# $4 - root filesystem partition size (in sectors) -# $5 - sector size (in bytes) -# $6 - number of detected partitions +# $4 - boot partition start offset (in sectors) +# $5 - boot partition size (in sectors) +# $6 - root filesystem partition size (in sectors) +# $7 - sector size (in bytes) +# $8 - number of detected partitions analyse_raw_disk_image() { local image=$1 + local alignment=$2 + local offset=$3 local count= local sectorsize= local bootstart= @@ -281,14 +313,14 @@ analyse_raw_disk_image() { local rootfssize= local bootflag= - local rvar_bootstart=$2 - local rvar_bootsize=$3 - local rvar_rootfssize=$4 - local rvar_sectorsize=$5 - local rvar_partitions=$6 + local rvar_bootstart=$4 + local rvar_bootsize=$5 + local rvar_rootfssize=$6 + local rvar_sectorsize=$7 + local rvar_partitions=$8 - get_image_info $image count sectorsize bootstart bootsize \ - rootfsstart rootfssize bootflag + get_image_info $image count sectorsize bootstart bootsize rootfsstart \ + rootfssize bootflag [[ $? -ne 0 ]] && \ { log "Error: invalid/unsupported raw disk image. Aborting."; exit 1; } @@ -296,14 +328,11 @@ analyse_raw_disk_image() { if [[ $count -eq 1 ]]; then rootfssize=$bootsize # Default size of the boot partition: 16MiB. - bootsize=$(( ($partition_alignment * 2) / $sectorsize )) - # Boot partition storage offset is defined from the top down. - bootstart=$(( $vfat_storage_offset_regular / $sectorsize )) - elif [[ $count -eq 2 ]]; then - # Boot partition storage offset is defined from the top down. - bootstart=$(( $vfat_storage_offset_extended / $sectorsize )) + bootsize=$(( (${alignment} * 2) / ${sectorsize} )) fi + # Boot partition storage offset is defined from the top down. + bootstart=$(( ${offset} / ${sectorsize} )) align_partition_size bootsize $sectorsize align_partition_size rootfssize $sectorsize