| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 # | 4 # |
| 5 # This contains common constants and functions for installer scripts. This must | 5 # This contains common constants and functions for installer scripts. This must |
| 6 # evaluate properly for both /bin/bash and /bin/sh, since it's used both to | 6 # evaluate properly for both /bin/bash and /bin/sh, since it's used both to |
| 7 # create the initial image at compile time and to install or upgrade a running | 7 # create the initial image at compile time and to install or upgrade a running |
| 8 # image. | 8 # image. |
| 9 | 9 |
| 10 # Here are the GUIDs we'll be using to identify various partitions. NOTE: The | 10 # Here are the GUIDs we'll be using to identify various partitions. NOTE: The |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 local num=$1 | 74 local num=$1 |
| 75 local div=${2:-4096} | 75 local div=${2:-4096} |
| 76 local rem=$(( $num % $div )) | 76 local rem=$(( $num % $div )) |
| 77 | 77 |
| 78 if [ $rem -ne 0 ]; then | 78 if [ $rem -ne 0 ]; then |
| 79 num=$(($num - $rem)) | 79 num=$(($num - $rem)) |
| 80 fi | 80 fi |
| 81 echo $num | 81 echo $num |
| 82 } | 82 } |
| 83 | 83 |
| 84 | 84 # Locate the gpt tool. It should already be installed in the build chroot, |
| 85 # We need to locate the gpt tool. It should already be installed in the build | 85 # but some of these functions may be invoked outside the chroot (by |
| 86 # chroot, but some of these functions may be invoked outside the chroot (by | |
| 87 # image_to_usb or similar), so we need to find it. | 86 # image_to_usb or similar), so we need to find it. |
| 88 GPT=$(which gpt 2>/dev/null) || /bin/true | 87 locate_gpt() { |
| 89 if [ -z "$GPT" ]; then | 88 if [ -z "$GPT" ]; then |
| 90 if [ -x "${DEFAULT_CHROOT_DIR:-}/usr/bin/gpt" ]; then | 89 GPT=$(which gpt 2>/dev/null) || /bin/true |
| 91 GPT="${DEFAULT_CHROOT_DIR:-}/usr/bin/gpt" | 90 if [ -z "$GPT" ]; then |
| 92 else | 91 if [ -x "${DEFAULT_CHROOT_DIR:-}/usr/bin/gpt" ]; then |
| 93 echo "can't find gpt tool" 1>&2 | 92 GPT="${DEFAULT_CHROOT_DIR:-}/usr/bin/gpt" |
| 94 exit 1 | 93 else |
| 94 echo "can't find gpt tool" 1>&2 |
| 95 exit 1 |
| 96 fi |
| 97 fi |
| 95 fi | 98 fi |
| 96 fi | 99 } |
| 97 | |
| 98 | 100 |
| 99 # This installs a GPT into the specified device or file, using the given | 101 # This installs a GPT into the specified device or file, using the given |
| 100 # components. If the target is a block device or the FORCE_FULL arg is "true" | 102 # components. If the target is a block device or the FORCE_FULL arg is "true" |
| 101 # we'll do a full install. Otherwise, it'll be just enough to boot. | 103 # we'll do a full install. Otherwise, it'll be just enough to boot. |
| 102 # Invoke as: command (not subshell) | 104 # Invoke as: command (not subshell) |
| 103 # Args: TARGET ROOTFS_IMG KERNEL_IMG STATEFUL_IMG PMBRCODE ESP_IMG FORCE_FULL | 105 # Args: TARGET ROOTFS_IMG KERNEL_IMG STATEFUL_IMG PMBRCODE ESP_IMG FORCE_FULL |
| 104 # Return: nothing | 106 # Return: nothing |
| 105 # Side effects: Sets these global variables describing the GPT partitions | 107 # Side effects: Sets these global variables describing the GPT partitions |
| 106 # (all units are 512-byte sectors): | 108 # (all units are 512-byte sectors): |
| 107 # NUM_ESP_SECTORS | 109 # NUM_ESP_SECTORS |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 local num_kern_c_sectors=1 | 186 local num_kern_c_sectors=1 |
| 185 local start_rootfs_c=$(($start_kern_c + 1)) | 187 local start_rootfs_c=$(($start_kern_c + 1)) |
| 186 local num_rootfs_c_sectors=1 | 188 local num_rootfs_c_sectors=1 |
| 187 local start_future_9=$(($start_rootfs_c + 1)) | 189 local start_future_9=$(($start_rootfs_c + 1)) |
| 188 local num_future_sectors=1 | 190 local num_future_sectors=1 |
| 189 local start_future_10=$(($start_future_9 + 1)) | 191 local start_future_10=$(($start_future_9 + 1)) |
| 190 local start_future_11=$(($start_future_10 + 1)) | 192 local start_future_11=$(($start_future_10 + 1)) |
| 191 | 193 |
| 192 local start_useful=$(roundup $(($start_future_11 + 1))) | 194 local start_useful=$(roundup $(($start_future_11 + 1))) |
| 193 | 195 |
| 196 locate_gpt |
| 197 |
| 194 # What are we doing? | 198 # What are we doing? |
| 195 if [ -b "$outdev" -o "$force_full" = "true" ]; then | 199 if [ -b "$outdev" -o "$force_full" = "true" ]; then |
| 196 # Block device, need to be root. | 200 # Block device, need to be root. |
| 197 if [ -b "$outdev" ]; then | 201 if [ -b "$outdev" ]; then |
| 198 local sudo=sudo | 202 local sudo=sudo |
| 199 else | 203 else |
| 200 local sudo="" | 204 local sudo="" |
| 201 fi | 205 fi |
| 202 | 206 |
| 203 # Full install, use max sizes and create both A & B images. | 207 # Full install, use max sizes and create both A & B images. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 278 |
| 275 # Zap any old partitions (otherwise gpt complains). | 279 # Zap any old partitions (otherwise gpt complains). |
| 276 $sudo dd if=/dev/zero of=${outdev} conv=notrunc bs=512 \ | 280 $sudo dd if=/dev/zero of=${outdev} conv=notrunc bs=512 \ |
| 277 count=$num_header_sectors | 281 count=$num_header_sectors |
| 278 $sudo dd if=/dev/zero of=${outdev} conv=notrunc bs=512 \ | 282 $sudo dd if=/dev/zero of=${outdev} conv=notrunc bs=512 \ |
| 279 seek=${start_gpt_footer} count=$num_footer_sectors | 283 seek=${start_gpt_footer} count=$num_footer_sectors |
| 280 | 284 |
| 281 # Create the new GPT partitions. The order determines the partition number. | 285 # Create the new GPT partitions. The order determines the partition number. |
| 282 # Note that the partition label is in the GPT only. The filesystem label is | 286 # Note that the partition label is in the GPT only. The filesystem label is |
| 283 # what's used to populate /dev/disk/by-label/, and this is not that. | 287 # what's used to populate /dev/disk/by-label/, and this is not that. |
| 288 |
| 284 $sudo $GPT create ${outdev} | 289 $sudo $GPT create ${outdev} |
| 285 | 290 |
| 286 $sudo $GPT add -b ${START_STATEFUL} -s ${NUM_STATEFUL_SECTORS} \ | 291 $sudo $GPT add -b ${START_STATEFUL} -s ${NUM_STATEFUL_SECTORS} \ |
| 287 -t ${DATA_GUID} ${outdev} | 292 -t ${DATA_GUID} ${outdev} |
| 288 $sudo $GPT label -i 1 -l "STATE" ${outdev} | 293 $sudo $GPT label -i 1 -l "STATE" ${outdev} |
| 289 | 294 |
| 290 $sudo $GPT add -b ${START_KERN_A} -s ${num_kern_a_sectors} \ | 295 $sudo $GPT add -b ${START_KERN_A} -s ${num_kern_a_sectors} \ |
| 291 -t ${KERN_GUID} ${outdev} | 296 -t ${KERN_GUID} ${outdev} |
| 292 $sudo $GPT label -i 2 -l "KERN-A" ${outdev} | 297 $sudo $GPT label -i 2 -l "KERN-A" ${outdev} |
| 293 | 298 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 344 |
| 340 sync | 345 sync |
| 341 } | 346 } |
| 342 | 347 |
| 343 | 348 |
| 344 # Helper function, please ignore and look below. | 349 # Helper function, please ignore and look below. |
| 345 _partinfo() { | 350 _partinfo() { |
| 346 local device=$1 | 351 local device=$1 |
| 347 local partnum=$2 | 352 local partnum=$2 |
| 348 local start size part x n | 353 local start size part x n |
| 354 |
| 355 locate_gpt |
| 356 |
| 349 sudo $GPT -r -S show $device \ | 357 sudo $GPT -r -S show $device \ |
| 350 | grep 'GPT part -' \ | 358 | grep 'GPT part -' \ |
| 351 | while read start size part x x x n x; do \ | 359 | while read start size part x x x n x; do \ |
| 352 if [ "${part}" -eq "${partnum}" ]; then \ | 360 if [ "${part}" -eq "${partnum}" ]; then \ |
| 353 echo $start $size; \ | 361 echo $start $size; \ |
| 354 fi; \ | 362 fi; \ |
| 355 done | 363 done |
| 356 # The 'while' is a subshell, so there's no way to indicate success. | 364 # The 'while' is a subshell, so there's no way to indicate success. |
| 357 } | 365 } |
| 358 | 366 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 if [ -x "$MKIMAGE" ]; then | 475 if [ -x "$MKIMAGE" ]; then |
| 468 MBR_SCRIPT_UIMG="${MBR_SCRIPT}.uimg" | 476 MBR_SCRIPT_UIMG="${MBR_SCRIPT}.uimg" |
| 469 "$MKIMAGE" -A "arm" -O linux -T script -a 0 -e 0 -n "COS boot" \ | 477 "$MKIMAGE" -A "arm" -O linux -T script -a 0 -e 0 -n "COS boot" \ |
| 470 -d ${MBR_SCRIPT} ${MBR_SCRIPT_UIMG} >&2 | 478 -d ${MBR_SCRIPT} ${MBR_SCRIPT_UIMG} >&2 |
| 471 else | 479 else |
| 472 echo "Error: u-boot mkimage not found or not executable." >&2 | 480 echo "Error: u-boot mkimage not found or not executable." >&2 |
| 473 exit 1 | 481 exit 1 |
| 474 fi | 482 fi |
| 475 echo ${MBR_SCRIPT_UIMG} | 483 echo ${MBR_SCRIPT_UIMG} |
| 476 } | 484 } |
| OLD | NEW |