diff --git a/bin/cros_make_image_bootable b/bin/cros_make_image_bootable index 5d1df71ea4..176d4ee96f 100755 --- a/bin/cros_make_image_bootable +++ b/bin/cros_make_image_bootable @@ -83,8 +83,6 @@ DEFINE_string image "chromiumos_base.img" \ "Full path to the chromiumos image to make bootable." DEFINE_string arch "x86" \ "Architecture to make bootable for: arm, x86, or amd64" -DEFINE_string usb_disk "/dev/sdb3" \ - "Path syslinux should use to do a usb boot." DEFINE_boolean cleanup_dirs ${FLAGS_TRUE} \ "Whether the mount dirs should be removed on completion." @@ -190,6 +188,8 @@ make_image_bootable() { --image "$(basename ${image})" -r "${FLAGS_rootfs_mountpoint}" \ -s "${FLAGS_statefulfs_mountpoint}" + legacy_offset_size_export ${image} + # The rootfs should never be mounted rw again after this point without # re-calling make_image_bootable. sudo mount -o remount,ro "${FLAGS_rootfs_mountpoint}" @@ -226,6 +226,7 @@ make_image_bootable() { -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 \ @@ -259,8 +260,8 @@ make_image_bootable() { fi local rootfs_hash_size=$(stat -c '%s' ${FLAGS_rootfs_hash}) - local rootfs_fs_size=$(get_filesystem_size ${FLAGS_image_type} 3) - local rootfs_partition_size=$(get_partition_size ${FLAGS_image_type} 3) + local rootfs_fs_size=$(get_filesystem_size ${FLAGS_image_type} ${NUM_ROOTFS_A}) + local rootfs_partition_size=$(get_partition_size ${FLAGS_image_type} ${NUM_ROOTFS_A}) local rootfs_hash_pad=$(( rootfs_partition_size - rootfs_fs_size )) info "Appending rootfs.hash (${rootfs_hash_size} bytes) to the root fs" if [[ ${rootfs_hash_size} -gt ${rootfs_hash_pad} ]] @@ -272,7 +273,7 @@ make_image_bootable() { # Unfortunately, mount_gpt_image uses mount and not losetup to create the # 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)" + local hash_offset="$(partoffset ${image} ${NUM_ROOTFS_A})" if [ $FLAGS_enable_squashfs -eq $FLAGS_TRUE ]; then rootfs_file_size=$(stat -c '%s' ${root_dev}) hash_offset=$((hash_offset + (${rootfs_file_size} / 512))) @@ -294,41 +295,21 @@ make_image_bootable() { sudo cp "${FLAGS_output_dir}/vmlinuz_hd.vblock" \ "${FLAGS_statefulfs_mountpoint}" - local koffset="$(partoffset ${image} 2)" - sudo dd if="${FLAGS_output_dir}/vmlinuz.image" of="${image}" \ - conv=notrunc bs=512 seek=${koffset} status=none - - # Update the bootloaders. The EFI system partition will be updated. - local kernel_part= - local usb_disk="${FLAGS_usb_disk}" - # We should update the esp in place in the image. local bootloader_to="${image}" - local esp_offset="$(partoffset ${image} 12)" + local esp_offset="$(partoffset ${image} ${NUM_ESP})" esp_offset=$((esp_offset * 512)) # sectors to bytes - local esp_size="$(partsize ${image} 12)" + local esp_size="$(partsize ${image} ${NUM_ESP})" esp_size=$((esp_size * 512)) # sectors to bytes local bootloader_to_flags="--to_offset=${esp_offset} --to_size=${esp_size}" - if [[ "${FLAGS_arch}" = "x86" || "${FLAGS_arch}" = "amd64" ]]; then - # Use the kernel partition to acquire configuration flags. - kernel_part="--kernel_partition='${FLAGS_output_dir}/vmlinuz.image'" - # Install syslinux on the EFI System Partition. - kernel_part="${kernel_part} --install_syslinux" - elif [[ "${FLAGS_arch}" = "arm" ]]; then - # These flags are not used for ARM update_bootloaders.sh - kernel_part="" - fi - # Update partition 12 ${SCRIPTS_DIR}/update_bootloaders.sh \ --arch=${FLAGS_arch} \ --to="${bootloader_to}" \ --from="${FLAGS_rootfs_mountpoint}"/boot \ --vmlinuz="${FLAGS_rootfs_mountpoint}"/boot/vmlinuz \ - --usb_disk="${usb_disk}" \ - ${bootloader_to_flags} \ - $kernel_part + ${bootloader_to_flags} # We don't need to keep these files around anymore. sudo rm "${FLAGS_rootfs_hash}" "${FLAGS_output_dir}/vmlinuz.image" \ @@ -342,7 +323,7 @@ make_image_bootable() { 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)" + local part_offset="$(partoffset ${image} ${NUM_ROOTFS_A})" sudo dd bs=512 if="${squashfs_img}" of="${image}" \ seek=${part_offset} conv=notrunc status=none sudo rm "${squashfs_img}" diff --git a/build_image b/build_image index c9e487c87d..cd8021e504 100755 --- a/build_image +++ b/build_image @@ -29,8 +29,8 @@ DEFINE_string disk_layout "default" \ "The disk layout type to use for this image." DEFINE_boolean standard_backdoor ${FLAGS_TRUE} \ "Install standard backdoor credentials for testing" -DEFINE_string usb_disk /dev/sdb3 \ - "Path syslinux should use to do a usb boot. Default: /dev/sdb3" +DEFINE_string usb_disk /dev/sdb4 \ + "Path syslinux should use to do a usb boot. Default: /dev/sdb4" DEFINE_string enable_serial "" \ "Enable serial port for printks. Example values: ttyS0" diff --git a/build_library/base_image_util.sh b/build_library/base_image_util.sh index 01abd3b175..39d2da6bde 100755 --- a/build_library/base_image_util.sh +++ b/build_library/base_image_util.sh @@ -71,22 +71,26 @@ create_base_image() { trap "cleanup_mounts && delete_prompt" EXIT cleanup_mounts &> /dev/null + local root_fs_label="ROOT-A" + local root_fs_num=$(get_num ${image_type} ${root_fs_label}) local root_fs_img="${BUILD_DIR}/rootfs.image" - local root_fs_bytes=$(get_filesystem_size ${image_type} 3) - local root_fs_label=$(get_label ${image_type} 3) + local root_fs_bytes=$(get_filesystem_size ${image_type} ${root_fs_num}) + local stateful_fs_label="STATE" + local stateful_fs_num=$(get_num ${image_type} ${stateful_fs_label}) local stateful_fs_img="${BUILD_DIR}/stateful.image" - local stateful_fs_bytes=$(get_filesystem_size ${image_type} 1) - local stateful_fs_label=$(get_label ${image_type} 1) + local stateful_fs_bytes=$(get_filesystem_size ${image_type} ${stateful_fs_num}) local stateful_fs_uuid=$(uuidgen) + local esp_fs_label="EFI-SYSTEM" + local esp_fs_num=$(get_num ${image_type} ${esp_fs_label}) local esp_fs_img="${BUILD_DIR}/esp.image" - local esp_fs_bytes=$(get_filesystem_size ${image_type} 12) - local esp_fs_label=$(get_label ${image_type} 12) + local esp_fs_bytes=$(get_filesystem_size ${image_type} ${esp_fs_num}) + local oem_fs_label="OEM" + local oem_fs_num=$(get_num ${image_type} ${oem_fs_label}) local oem_fs_img="${BUILD_DIR}/oem.image" - local oem_fs_bytes=$(get_filesystem_size ${image_type} 8) - local oem_fs_label=$(get_label ${image_type} 8) + local oem_fs_bytes=$(get_filesystem_size ${image_type} ${oem_fs_num}) local oem_fs_uuid=$(uuidgen) local fs_block_size=$(get_fs_block_size) diff --git a/build_library/build_image_util.sh b/build_library/build_image_util.sh index bb25e26f1e..81bc7fb725 100755 --- a/build_library/build_image_util.sh +++ b/build_library/build_image_util.sh @@ -135,7 +135,6 @@ create_boot_desc() { --image_type=${image_type} --arch="${ARCH}" --keys_dir="${DEVKEYSDIR}" - --usb_disk="${FLAGS_usb_disk}" --boot_args="${FLAGS_boot_args}" --nocleanup_dirs --verity_algorithm=sha1 diff --git a/build_library/cgpt.py b/build_library/cgpt.py index 4a96af8f7e..cd0d89c418 100755 --- a/build_library/cgpt.py +++ b/build_library/cgpt.py @@ -294,16 +294,12 @@ def WriteLayoutFunction(options, sfile, func_name, image_type, config): sfile.write('$GPT add -i %d -b $CURR -s %s -t %s -l %s $1 && ' % ( partition['num'], str(partition['var']), partition['type'], partition['label'])) + if partition['type'] == 'efi': + sfile.write('$GPT boot -p -b $2 -i %d $1\n' % partition['num']) # Increment the CURR counter ready for the next partition. sfile.write('CURR=$(( $CURR + %s ))\n' % partition['var']) - # Set default priorities on kernel partitions - sfile.write('$GPT add -i 2 -S 0 -T 15 -P 15 $1\n') - sfile.write('$GPT add -i 4 -S 0 -T 15 -P 0 $1\n') - sfile.write('$GPT add -i 6 -S 0 -T 15 -P 0 $1\n') - - sfile.write('$GPT boot -p -b $2 -i 12 $1\n') sfile.write('$GPT show $1\n') sfile.write('}\n') @@ -458,6 +454,27 @@ def GetLabel(options, image_type, layout_filename, num): return 'UNTITLED' +def GetNum(options, image_type, layout_filename, label): + """Returns the number for a given label. + + Args: + options: Flags passed to the script + image_type: Type of image eg base/test/dev/factory_install + layout_filename: Path to partition configuration file + label: Label of the partition you want to read from + Returns: + Number of selected partition, or '-1' if there is no number + """ + + partitions = GetPartitionTableFromConfig(options, layout_filename, image_type) + partition = GetPartitionByLabel(partitions, label) + + if 'num' in partition: + return partition['num'] + else: + return '-1' + + def DoDebugOutput(options, image_type, layout_filename): """Prints out a human readable disk layout in on-disk order. @@ -526,6 +543,10 @@ def main(argv): 'usage': ['', '', ''], 'func': GetLabel, }, + 'readnum': { + 'usage': ['', '', '