mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-23 22:51:03 +02:00
build_image,update_bootloaders: directly update the built image
Instead of playing mount and loop device games, this change adds support for update_bootloaders.sh to directly update the EFI system partition living in the image if a file, offset, and size is supplied. TEST=build_image for x86-generic; booted resulting image BUG=broken build Change-Id: I3d891fd965df6fb4abfc63d660e314c497a4184d Review URL: http://codereview.chromium.org/3006006
This commit is contained in:
parent
3172b7e296
commit
721d94f429
32
build_image
32
build_image
@ -291,7 +291,7 @@ make_image_bootable() {
|
||||
trap "mount_gpt_cleanup" EXIT
|
||||
${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \
|
||||
--image "${image_name}" -r "${ROOT_FS_DIR}" \
|
||||
-s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}"
|
||||
-s "${STATEFUL_FS_DIR}"
|
||||
|
||||
sudo mount -o remount,ro "${ROOT_FS_DIR}"
|
||||
root_dev=$(mount | grep -- "${ROOT_FS_DIR}" | cut -f1 -d' ' | tail -1)
|
||||
@ -332,14 +332,27 @@ make_image_bootable() {
|
||||
|
||||
# Update the bootloaders. For legacy/efi x86, the EFI system partition
|
||||
# will be updated and for arm, the mbr will be updated (for u-boot).
|
||||
local kernel_part="--kernel_partition='${OUTPUT_DIR}/vmlinuz.image'"
|
||||
kernel_part="${kernel_part} --install_syslinux"
|
||||
local bootloader_to="${ESP_FS_IMG}"
|
||||
local kernel_part=
|
||||
local bootloader_to=
|
||||
local bootloader_to_flags=
|
||||
local usb_disk="${FLAGS_usb_disk}"
|
||||
local bootloader_to="$(mount | grep ${ESP_FS_DIR} | cut -f1 -d' ')"
|
||||
if [[ "${ARCH}" == "arm" ]]; then
|
||||
|
||||
if [[ "${ARCH}" = "x86" ]]; then
|
||||
# x86 should update the esp in place in the image.
|
||||
bootloader_to="${OUTPUT_DIR}/${image_name}"
|
||||
local esp_offset="$(partoffset ${OUTPUT_DIR}/${image_name} 12)"
|
||||
esp_offset=$((esp_offset * 512)) # sectors to bytes
|
||||
local esp_size="$(partsize ${OUTPUT_DIR}/${image_name} 12)"
|
||||
esp_size=$((esp_size * 512)) # sectors to bytes
|
||||
bootloader_to_flags="--to_offset=${esp_offset} --to_size=${esp_size}"
|
||||
# Use the kernel partition to acquire configuration flags.
|
||||
kernel_part="--kernel_partition='${OUTPUT_DIR}/vmlinuz.image'"
|
||||
# Install syslinux on the EFI System Partition.
|
||||
kernel_part="${kernel_part} --install_syslinux"
|
||||
elif [[ "${ARCH}" = "arm" ]]; then
|
||||
# TODO(wad) mmcblk1p3 is hardcoded for arm for now!
|
||||
usb_disk="/dev/mmcblk1p3"
|
||||
# ARM doesn't support using the kernel image for kernel cmdline flags yet.
|
||||
kernel_part="--kernel_cmdline=\"${FLAGS_arm_extra_bootargs}\" "
|
||||
# TODO(wad) Integrate dmtable extraction into the arm build
|
||||
# E.g. $(cat ${OUTPUT_DIR}/boot.config | tr -s '\n' ' ')"
|
||||
@ -351,9 +364,6 @@ make_image_bootable() {
|
||||
bootloader_to="${OUTPUT_DIR}/arm.mbr"
|
||||
fi
|
||||
|
||||
# Temporary hack to fix syslinux building:
|
||||
sudo umount ${ESP_FS_DIR}
|
||||
|
||||
# Update partition 12 / legacy bootloaders and arm.
|
||||
${SCRIPTS_DIR}/update_bootloaders.sh \
|
||||
--arch=${ARCH} \
|
||||
@ -361,6 +371,7 @@ make_image_bootable() {
|
||||
--from="${OUTPUT_DIR}"/boot \
|
||||
--vmlinuz="${OUTPUT_DIR}"/boot/vmlinuz \
|
||||
--usb_disk="${usb_disk}" \
|
||||
${bootloader_to_flags} \
|
||||
$kernel_part
|
||||
|
||||
if [[ "${ARCH}" == "arm" ]]; then
|
||||
@ -370,9 +381,6 @@ make_image_bootable() {
|
||||
fi
|
||||
|
||||
trap - EXIT
|
||||
# Temporary hack to fix syslinux building, comment out -e ${ESP_FS_DIR}
|
||||
# ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \
|
||||
# -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}"
|
||||
${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \
|
||||
-s "${STATEFUL_FS_DIR}"
|
||||
}
|
||||
|
@ -22,6 +22,10 @@ DEFINE_string from "/tmp/boot" \
|
||||
"Path the legacy bootloader templates are copied from. (Default /tmp/boot)"
|
||||
DEFINE_string to "/tmp/esp.img" \
|
||||
"Path to esp image or ARM output MBR (Default: /tmp/esp.img)"
|
||||
DEFINE_integer to_offset 0 \
|
||||
"Offset in bytes into 'to' if it is a file (Default: 0)"
|
||||
DEFINE_integer to_size -1 \
|
||||
"Size in bytes of 'to' to use if it is a file. -1 is ignored. (Default: -1)"
|
||||
DEFINE_string vmlinuz "/tmp/vmlinuz" \
|
||||
"Path to the vmlinuz file to use (Default: /tmp/vmlinuz)"
|
||||
# The kernel_partition and the kernel_cmdline each are used to supply
|
||||
@ -106,13 +110,23 @@ if [[ ! -e "${FLAGS_to}" ]]; then
|
||||
ESP_BLOCKS=16384
|
||||
/usr/sbin/mkfs.vfat -C "${FLAGS_to}" ${ESP_BLOCKS}
|
||||
ESP_DEV=$(sudo losetup -f)
|
||||
test -z "${ESP_DEV}" && error "No free loop devices."
|
||||
if [ -z "${ESP_DEV}" ]; then
|
||||
die "No free loop devices."
|
||||
fi
|
||||
sudo losetup "${ESP_DEV}" "${FLAGS_to}"
|
||||
else
|
||||
if [[ -f "${FLAGS_to}" ]]; then
|
||||
ESP_DEV=$(sudo losetup -f)
|
||||
test -z "${ESP_DEV}" && error "No free loop devices."
|
||||
sudo losetup "${ESP_DEV}" "${FLAGS_to}"
|
||||
if [ -z "${ESP_DEV}" ]; then
|
||||
die "No free loop devices."
|
||||
fi
|
||||
|
||||
esp_offset="--offset ${FLAGS_to_offset}"
|
||||
esp_size="--sizelimit ${FLAGS_to_size}"
|
||||
if [ ${FLAGS_to_size} -lt 0 ]; then
|
||||
esp_size=
|
||||
fi
|
||||
sudo losetup ${esp_offset} ${esp_size} "${ESP_DEV}" "${FLAGS_to}"
|
||||
else
|
||||
# If it is a block device or something else, try to mount it anyway.
|
||||
ESP_DEV="${FLAGS_to}"
|
||||
@ -167,7 +181,7 @@ if [[ "${FLAGS_arch}" = "x86" ]]; then
|
||||
# we cut over from rootfs booting (extlinux).
|
||||
if [[ ${FLAGS_install_syslinux} -eq ${FLAGS_TRUE} ]]; then
|
||||
sudo umount "${ESP_FS_DIR}"
|
||||
sudo syslinux -d /syslinux "${FLAGS_to}"
|
||||
sudo syslinux -d /syslinux "${ESP_DEV}"
|
||||
fi
|
||||
elif [[ "${FLAGS_arch}" = "arm" ]]; then
|
||||
# Extract kernel flags
|
||||
|
Loading…
x
Reference in New Issue
Block a user