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