| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 | 2 |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 # Utility methods used to resize a stateful partition and update the GPT table | 7 # Utility methods used to resize a stateful partition and update the GPT table |
| 8 | 8 |
| 9 # Source constants and utility functions | 9 # Source constants and utility functions |
| 10 . "$(dirname "$0")/common.sh" | 10 . "$(dirname "$0")/common.sh" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 echo "${resized_sectors}" | 57 echo "${resized_sectors}" |
| 58 } | 58 } |
| 59 | 59 |
| 60 # Update partition table with resized stateful partition | 60 # Update partition table with resized stateful partition |
| 61 update_partition_table() { | 61 update_partition_table() { |
| 62 local src_img=$1 # source image | 62 local src_img=$1 # source image |
| 63 local temp_state=$2 # stateful partition image | 63 local temp_state=$2 # stateful partition image |
| 64 local resized_sectors=$3 # number of sectors in resized stateful partition | 64 local resized_sectors=$3 # number of sectors in resized stateful partition |
| 65 local temp_img=$4 | 65 local temp_img=$4 |
| 66 | 66 |
| 67 local kernel_offset=$(partoffset ${src_img} 2) | 67 local kern_a_offset=$(partoffset ${src_img} 2) |
| 68 local kernel_count=$(partsize ${src_img} 2) | 68 local kern_a_count=$(partsize ${src_img} 2) |
| 69 local kern_b_offset=$(partoffset ${src_img} 4) |
| 70 local kern_b_count=$(partsize ${src_img} 4) |
| 69 local rootfs_offset=$(partoffset ${src_img} 3) | 71 local rootfs_offset=$(partoffset ${src_img} 3) |
| 70 local rootfs_count=$(partsize ${src_img} 3) | 72 local rootfs_count=$(partsize ${src_img} 3) |
| 71 local oem_offset=$(partoffset ${src_img} 8) | 73 local oem_offset=$(partoffset ${src_img} 8) |
| 72 local oem_count=$(partsize ${src_img} 8) | 74 local oem_count=$(partsize ${src_img} 8) |
| 73 local esp_offset=$(partoffset ${src_img} 12) | 75 local esp_offset=$(partoffset ${src_img} 12) |
| 74 local esp_count=$(partsize ${src_img} 12) | 76 local esp_count=$(partsize ${src_img} 12) |
| 75 | 77 |
| 76 local temp_pmbr=$(mktemp "/tmp/pmbr.XXXXXX") | 78 local temp_pmbr=$(mktemp "/tmp/pmbr.XXXXXX") |
| 77 dd if="${src_img}" of="${temp_pmbr}" bs=512 count=1 &>/dev/null | 79 dd if="${src_img}" of="${temp_pmbr}" bs=512 count=1 &>/dev/null |
| 78 | 80 |
| 79 trap "rm -rf \"${temp_pmbr}\"" EXIT | 81 trap "rm -rf \"${temp_pmbr}\"" EXIT |
| 80 # Set up a new partition table | 82 # Set up a new partition table |
| 81 install_gpt "${temp_img}" "${rootfs_count}" "${resized_sectors}" \ | 83 install_gpt "${temp_img}" "${rootfs_count}" "${resized_sectors}" \ |
| 82 "${temp_pmbr}" "${esp_count}" false $(roundup ${rootfs_count}) | 84 "${temp_pmbr}" "${esp_count}" false \ |
| 85 $(((rootfs_count * 512)/(1024 * 1024))) |
| 83 | 86 |
| 84 # Copy into the partition parts of the file | 87 # Copy into the partition parts of the file |
| 85 dd if="${src_img}" of="${temp_img}" conv=notrunc bs=512 \ | 88 dd if="${src_img}" of="${temp_img}" conv=notrunc bs=512 \ |
| 86 seek="${START_ROOTFS_A}" skip=${rootfs_offset} count=${rootfs_count} | 89 seek="${START_ROOTFS_A}" skip=${rootfs_offset} count=${rootfs_count} |
| 87 dd if="${temp_state}" of="${temp_img}" conv=notrunc bs=512 \ | 90 dd if="${temp_state}" of="${temp_img}" conv=notrunc bs=512 \ |
| 88 seek="${START_STATEFUL}" | 91 seek="${START_STATEFUL}" |
| 89 # Copy the full kernel (i.e. with vboot sections) | 92 # Copy the full kernel (i.e. with vboot sections) |
| 90 dd if="${src_img}" of="${temp_img}" conv=notrunc bs=512 \ | 93 dd if="${src_img}" of="${temp_img}" conv=notrunc bs=512 \ |
| 91 seek="${START_KERN_A}" skip=${kernel_offset} count=${kernel_count} | 94 seek="${START_KERN_A}" skip=${kern_a_offset} count=${kern_a_count} |
| 95 dd if="${src_img}" of="${temp_img}" conv=notrunc bs=512 \ |
| 96 seek="${START_KERN_B}" skip=${kern_b_offset} count=${kern_b_count} |
| 92 dd if="${src_img}" of="${temp_img}" conv=notrunc bs=512 \ | 97 dd if="${src_img}" of="${temp_img}" conv=notrunc bs=512 \ |
| 93 seek="${START_OEM}" skip=${oem_offset} count=${oem_count} | 98 seek="${START_OEM}" skip=${oem_offset} count=${oem_count} |
| 94 dd if="${src_img}" of="${temp_img}" conv=notrunc bs=512 \ | 99 dd if="${src_img}" of="${temp_img}" conv=notrunc bs=512 \ |
| 95 seek="${START_ESP}" skip=${esp_offset} count=${esp_count} | 100 seek="${START_ESP}" skip=${esp_offset} count=${esp_count} |
| 96 } | 101 } |
| OLD | NEW |