Browse Source

Implement MENDER_COPY_BOOT_GAP feature

This is necessary for the U-boot -> EFI -> GRUB integration to be
complete as many boards embedd the U-Boot binary at the start
of the SD/eMMC a.k.a boot-gap.

When MENDER_COPY_BOOT_GAP is enabled, it will be copied from the
input disk image to the output ".sdimg"

MEN-2784

Changelog: Title

Signed-off-by: Mirza Krak <mirza.krak@northern.tech>
2.0.x
Mirza Krak 5 years ago
parent
commit
7320b42f0b
  1. 3
      configs/beaglebone_black_base_config
  2. 7
      configs/mender_convert_config
  3. 3
      configs/qemux86-64_config
  4. 3
      configs/raspberrypi_config
  5. 3
      configs/rockpro64_config
  6. 7
      mender-convert-extract
  7. 16
      mender-convert-package

3
configs/beaglebone_black_base_config

@ -6,6 +6,9 @@
# There are reported issues with GRUB bootloader integration, fallback to U-boot.
MENDER_GRUB_EFI_INTEGRATION=n
# We will write a modified bootloader
MENDER_COPY_BOOT_GAP=n
# 4MB alignment
MENDER_PARTITION_ALIGNMENT="4194304"

7
configs/mender_convert_config

@ -120,6 +120,13 @@ MENDER_KERNEL_DEVICETREE=kernel.dtb
# https://github.com/intel/bmap-tools
MENDER_USE_BMAP="n"
# Copy the boot gap, which is the area from sector 1 until first parition,
# this is done because some images might contain the bootloader embedded here
# and we need to copy the bootloader to the output image.
#
# In most cases you would like this enabled.
MENDER_COPY_BOOT_GAP="y"
source configs/mender_grub_config
# Function to create Mender Artifact

3
configs/qemux86-64_config

@ -14,3 +14,6 @@
MENDER_STORAGE_DEVICE=/dev/sda
MENDER_DEVICE_TYPE="qemux86_64"
# Nothing to copy
MENDER_COPY_BOOT_GAP="n"

3
configs/raspberrypi_config

@ -1,6 +1,9 @@
# Raspberry Pi does not support GRUB bootloader integration, fallback to U-boot.
MENDER_GRUB_EFI_INTEGRATION=n
# Nothing to copy
MENDER_COPY_BOOT_GAP=n
# 4MB alignment
MENDER_PARTITION_ALIGNMENT="4194304"

3
configs/rockpro64_config

@ -1,6 +1,9 @@
# ROCKPro64 do not support GRUB bootloader integration, fallback to U-boot.
MENDER_GRUB_EFI_INTEGRATION=n
# We will write a modified bootloader
MENDER_COPY_BOOT_GAP=n
ROCKPRO64_BINARIES_URL="${MENDER_STORAGE_URL}/mender-convert/armbian/rockpro64/${ROCKPRO64_BINARIES}"
function platform_modify() {

7
mender-convert-extract

@ -102,5 +102,8 @@ fi
# this is done because some images might contain the bootloader embedded here
# and we might need to keep this area intact when we generate our custom
# image.
disk_extract_part "${disk_image}" \
1 $(( $(disk_get_part_value ${disk_image} 1 START) - 1)) work/boot-gap.bin
if [ "${MENDER_COPY_BOOT_GAP}" == "y" ]; then
log_info "Extracting boot gap to work/boot-gap.bin"
disk_extract_part "${disk_image}" \
1 $(( $(disk_get_part_value ${disk_image} 1 START) - 1)) work/boot-gap.bin
fi

16
mender-convert-package

@ -102,6 +102,16 @@ else
overhead_sectors=$(( ${alignment_sectors} * 6 ))
fi
# Validate boot-gap.bin size, ensuring it will fit between MBR and boot_part_start
if [ "${MENDER_COPY_BOOT_GAP}" == "y" ]; then
# Add one block for MBR
boot_gap_sectors=$(( $(stat --printf="%b" work/boot-gap.bin) + 1))
if [ ${boot_gap_sectors} -ge ${boot_part_start} ]; then
log_warn "The work/boot-gap.bin file will overwrite the boot partition"
log_fatal "Please increase MENDER_PARTITION_ALIGNMENT (2x will typically solve this))"
fi
fi
# Validate boot part size
actual_boot_size=$(du --apparent-size -s --block-size=512 ${boot_part} | cut -f 1)
if [ ${actual_boot_size} -gt ${boot_part_sectors} ]; then
@ -199,6 +209,12 @@ run_and_log_cmd "${PARTED} -s ${sdimg_path} -- unit s mkpart primary ext2 ${root
run_and_log_cmd "${PARTED} -s ${sdimg_path} -- unit s mkpart primary ext2 ${data_start} ${data_end}"
run_and_log_cmd "${PARTED} -s ${sdimg_path} print"
# Write boot-gap
if [ "${MENDER_COPY_BOOT_GAP}" == "y" ]; then
log_info "Writing boot gap of size: ${boot_part_sectors} (sectors)"
disk_write_at_offset "${output_dir}/boot-gap.bin" "${sdimg_path}" "1"
fi
# Burn Partitions
disk_write_at_offset "${boot_part}" "${sdimg_path}" "${boot_part_start}"
disk_write_at_offset "${output_dir}/rootfs.img" "${sdimg_path}" "${rootfsa_start}"

Loading…
Cancel
Save