Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/bin/bash | |
| 2 | |
| 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 | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 # This script modifies a base image to act as a recovery installer. | |
| 8 # If a developer payload is supplied, it will be used. | |
| 9 # It is very straight forward, top to bottom to show clearly what is | |
| 10 # little is needed to create a developer shim to run a signed script. | |
| 11 | |
| 12 # Load common constants. This should be the first executable line. | |
| 13 # The path to common.sh should be relative to your script's location. | |
| 14 . "$(dirname "$0")/common.sh" | |
| 15 | |
| 16 # Load functions and constants for chromeos-install | |
| 17 . "$(dirname "$0")/chromeos-common.sh" | |
| 18 | |
| 19 DEFINE_integer statefulfs_size 2 \ | |
| 20 "Number of mebibytes to use for the stateful filesystem" | |
|
anush
2010/11/01 22:29:48
Nit: mebibyte - does it come after the yottabyte :
| |
| 21 DEFINE_string developer_private_key \ | |
| 22 "/usr/share/vboot/devkeys/kernel_data_key.vbprivk" \ | |
| 23 "Path to the developer's private key" | |
| 24 DEFINE_string developer_keyblock \ | |
| 25 "/usr/share/vboot/devkeys/kernel.keyblock" \ | |
| 26 "Path to the developer's keyblock" | |
| 27 DEFINE_string developer_script "" \ | |
| 28 "Path to the developer script if desired." | |
| 29 # TODO(wad) wire up support for just swapping a pre-made kernel | |
| 30 # Skips the build steps and just does the kernel swap. | |
| 31 DEFINE_string kernel_image "" \ | |
| 32 "Path to a pre-built recovery kernel" | |
| 33 DEFINE_boolean verbose $FLAGS_FALSE \ | |
| 34 "Emits stderr too" v | |
| 35 DEFINE_string image "dev_runner_image.bin" \ | |
| 36 "Path to output image to" | |
| 37 | |
| 38 # Parse command line | |
| 39 FLAGS "$@" || exit 1 | |
| 40 eval set -- "${FLAGS_ARGV}" | |
| 41 | |
| 42 if [ $FLAGS_verbose -eq $FLAGS_FALSE ]; then | |
| 43 exec 2>/dev/null | |
| 44 fi | |
| 45 set -x # Make debugging with -v easy. | |
| 46 | |
| 47 if [ -z "$FLAGS_kernel_image" ]; then | |
| 48 die "--kernel_image with a recovery kernel is needed" | |
| 49 fi | |
| 50 | |
| 51 if [ -z "$FLAGS_developer_script" ]; then | |
| 52 die "--developer_script must be supplied." | |
| 53 fi | |
| 54 | |
| 55 locate_gpt | |
| 56 | |
| 57 set -eu | |
| 58 | |
| 59 header_offset=34 | |
| 60 stateful_sectors=$(((FLAGS_statefulfs_size * 1024 * 1024) / 512)) | |
| 61 stateful_sectors=$(roundup $stateful_sectors) | |
| 62 | |
| 63 if [ -b "$FLAGS_image" ]; then | |
| 64 sudo=sudo | |
| 65 else | |
| 66 max_kern_size=32768 | |
| 67 dd if=/dev/zero of="${FLAGS_image}" bs=512 count=0 \ | |
| 68 seek=$((1 + max_kern_size + header_offset + stateful_sectors)) | |
| 69 sudo="" | |
| 70 fi | |
| 71 | |
| 72 ## STATEFUL | |
| 73 | |
| 74 stateful_image=$(mktemp) | |
| 75 trap "rm $stateful_image" EXIT | |
| 76 | |
| 77 dd if=/dev/zero of="$stateful_image" bs=512 \ | |
| 78 seek=$stateful_sectors count=0 | |
| 79 /sbin/mkfs.ext3 -F -b 4096 $stateful_image 1>&2 | |
| 80 | |
| 81 stateful_mnt=$(mktemp -d) | |
| 82 sudo mount -o loop $stateful_image "$stateful_mnt" || exit 1 | |
| 83 userdir="$stateful_mnt/userdir" | |
| 84 userfile="$userdir/runme" | |
| 85 sudo mkdir -p "$userdir" | |
| 86 sudo cp "$FLAGS_developer_script" "$userfile" | |
| 87 sudo chmod +x "$userfile" | |
| 88 sudo dev_sign_file --sign "$userfile" \ | |
| 89 --keyblock "$FLAGS_developer_keyblock" \ | |
| 90 --signprivate "$FLAGS_developer_private_key" \ | |
| 91 --vblock "${userfile}.vblock" | |
| 92 sudo umount -d "$stateful_mnt" | |
| 93 rmdir "$stateful_mnt" | |
| 94 | |
| 95 ## GPT | |
| 96 | |
| 97 kernel_bytes=$(stat -c '%s' $FLAGS_kernel_image) | |
| 98 kernel_sectors=$((kernel_bytes / 512)) | |
| 99 kernel_sectors=$(roundup $kernel_sectors) | |
| 100 | |
| 101 $sudo $GPT create $FLAGS_image | |
| 102 trap "rm $FLAGS_image" ERR | |
| 103 | |
| 104 offset=$header_offset | |
| 105 $sudo $GPT add -b $offset -s $stateful_sectors \ | |
| 106 -t data -l "STATE" $FLAGS_image | |
| 107 $sudo dd if=$stateful_image of=$FLAGS_image bs=512 conv=notrunc \ | |
| 108 seek=$offset count=$stateful_sectors | |
| 109 | |
| 110 offset=$((offset + stateful_sectors)) | |
| 111 $sudo $GPT add -b $offset -s $kernel_sectors \ | |
| 112 -t kernel -l "KERN-A" -S 0 -T 15 -P 15 $FLAGS_image | |
| 113 $sudo dd if=$FLAGS_kernel_image of=$FLAGS_image bs=512 conv=notrunc \ | |
| 114 seek=$offset count=$kernel_sectors | |
| 115 # The kernel will ignore GPT without a legacymbr. | |
| 116 PMBRCODE=$(readlink -f /usr/share/syslinux/gptmbr.bin) | |
| 117 # Have it legacy boot off of stateful, not that it should matter. | |
| 118 $sudo $GPT boot -p -b "$PMBRCODE" -i 1 $FLAGS_image 1>&2 | |
| 119 | |
| 120 $sudo $GPT show $FLAGS_image | |
| 121 | |
| 122 echo "Done." | |
| OLD | NEW |