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 # Script to generate a Chromium OS update for use by the update engine. | 7 # Script to generate a Chromium OS update for use by the update engine. |
8 # If a source .bin is specified, the update is assumed to be a delta update. | 8 # If a source .bin is specified, the update is assumed to be a delta update. |
9 | 9 |
10 # Load common constants. This should be the first executable line. | 10 # Load common constants. This should be the first executable line. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 rm -f "$SRC_KERNEL" | 49 rm -f "$SRC_KERNEL" |
50 rm -f "$SRC_ROOT" | 50 rm -f "$SRC_ROOT" |
51 rm -f "$DST_KERNEL" | 51 rm -f "$DST_KERNEL" |
52 rm -f "$DST_ROOT" | 52 rm -f "$DST_ROOT" |
53 [ -n "$1" ] || exit 1 | 53 [ -n "$1" ] || exit 1 |
54 } | 54 } |
55 | 55 |
56 extract_partition_to_temp_file() { | 56 extract_partition_to_temp_file() { |
57 local filename="$1" | 57 local filename="$1" |
58 local partition="$2" | 58 local partition="$2" |
59 local temp_file=$(mktemp /tmp/generate_update_payload.XXXXXX) | 59 local temp_file="$3" |
60 | 60 if [ -z "$temp_file" ]; then |
| 61 temp_file=$(mktemp /tmp/cros_generate_update_payload.XXXXXX) |
| 62 echo "$temp_file" |
| 63 fi |
| 64 |
61 local offset=$(partoffset "${filename}" ${partition}) # 512-byte sectors | 65 local offset=$(partoffset "${filename}" ${partition}) # 512-byte sectors |
62 local length=$(partsize "${filename}" ${partition}) # 512-byte sectors | 66 local length=$(partsize "${filename}" ${partition}) # 512-byte sectors |
63 local bs=512 | 67 local bs=512 |
64 local sectors_per_two_mib=$((2 * 1024 * 1024 / 512)) | 68 local sectors_per_two_mib=$((2 * 1024 * 1024 / 512)) |
65 if [ $(( $offset % $sectors_per_two_mib )) -eq 0 -a \ | 69 if [ $(( $offset % $sectors_per_two_mib )) -eq 0 -a \ |
66 $(( $length % $sectors_per_two_mib )) -eq 0 ]; then | 70 $(( $length % $sectors_per_two_mib )) -eq 0 ]; then |
67 bs=$((2 * 1024 * 1024)) | 71 bs=$((2 * 1024 * 1024)) |
68 offset=$(($offset / $sectors_per_two_mib)) | 72 offset=$(($offset / $sectors_per_two_mib)) |
69 length=$(($length / $sectors_per_two_mib)) | 73 length=$(($length / $sectors_per_two_mib)) |
70 else | 74 else |
71 warn "partition offset or length not at 2MiB boundary" | 75 warn "partition offset or length not at 2MiB boundary" |
72 fi | 76 fi |
73 dd if="$filename" of="$temp_file" bs=$bs count="$length" skip="$offset" | 77 dd if="$filename" of="$temp_file" bs=$bs count="$length" skip="$offset" |
74 echo "$temp_file" | |
75 } | 78 } |
76 | 79 |
77 patch_kernel() { | 80 patch_kernel() { |
78 local IMAGE="$1" | 81 local IMAGE="$1" |
79 local KERN_FILE="$2" | 82 local KERN_FILE="$2" |
80 | 83 |
81 STATE_LOOP_DEV=$(sudo losetup -f) | 84 STATE_LOOP_DEV=$(sudo losetup -f) |
82 [ -n "$STATE_LOOP_DEV" ] || die "no free loop device" | 85 [ -n "$STATE_LOOP_DEV" ] || die "no free loop device" |
83 local offset=$(partoffset "${IMAGE}" 1) | 86 local offset=$(partoffset "${IMAGE}" 1) |
84 offset=$(($offset * 512)) | 87 offset=$(($offset * 512)) |
85 sudo losetup -o "$offset" "$STATE_LOOP_DEV" "$IMAGE" | 88 sudo losetup -o "$offset" "$STATE_LOOP_DEV" "$IMAGE" |
86 STATE_MNT=$(mktemp -d /tmp/state.XXXXXX) | 89 STATE_MNT=$(mktemp -d /tmp/state.XXXXXX) |
87 sudo mount "$STATE_LOOP_DEV" "$STATE_MNT" | 90 sudo mount "$STATE_LOOP_DEV" "$STATE_MNT" |
88 dd if="$STATE_MNT"/vmlinuz_hd.vblock of="$KERN_FILE" conv=notrunc | 91 dd if="$STATE_MNT"/vmlinuz_hd.vblock of="$KERN_FILE" conv=notrunc |
89 sudo umount "$STATE_MNT" | 92 sudo umount "$STATE_MNT" |
90 STATE_MNT="" | 93 STATE_MNT="" |
91 sudo losetup -d "$STATE_LOOP_DEV" | 94 sudo losetup -d "$STATE_LOOP_DEV" |
92 STATE_LOOP_DEV="" | 95 STATE_LOOP_DEV="" |
93 } | 96 } |
94 | 97 |
| 98 extract_kern_root() { |
| 99 local bin_file="$1" |
| 100 local kern_out="$2" |
| 101 local root_out="$3" |
| 102 |
| 103 if [ -z "$kern_out" ]; then |
| 104 die "missing kernel output filename" |
| 105 fi |
| 106 if [ -z "$root_out" ]; then |
| 107 die "missing root output filename" |
| 108 fi |
| 109 |
| 110 extract_partition_to_temp_file "$bin_file" 2 "$kern_out" |
| 111 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then |
| 112 patch_kernel "$bin_file" "$kern_out" |
| 113 fi |
| 114 extract_partition_to_temp_file "$bin_file" 3 "$root_out" |
| 115 } |
| 116 |
95 DEFINE_string image "" "The image that should be sent to clients." | 117 DEFINE_string image "" "The image that should be sent to clients." |
96 DEFINE_string src_image "" "Optional: a source image. If specified, this makes\ | 118 DEFINE_string src_image "" "Optional: a source image. If specified, this makes\ |
97 a delta update." | 119 a delta update." |
98 DEFINE_boolean old_style "$FLAGS_TRUE" "Generate an old-style .gz full update." | 120 DEFINE_boolean old_style "$FLAGS_TRUE" "Generate an old-style .gz full update." |
99 DEFINE_string output "" "Output file" | 121 DEFINE_string output "" "Output file" |
100 DEFINE_boolean patch_kernel "$FLAGS_FALSE" "Whether or not to patch the kernel \ | 122 DEFINE_boolean patch_kernel "$FLAGS_FALSE" "Whether or not to patch the kernel \ |
101 with the patch from the stateful partition (default: false)" | 123 with the patch from the stateful partition (default: false)" |
102 DEFINE_string private_key "" "Path to private key in .pem format." | 124 DEFINE_string private_key "" "Path to private key in .pem format." |
| 125 DEFINE_boolean extract "$FLAGS_FALSE" "If set, extract old/new kernel/rootfs \ |
| 126 to [old|new]_[kern|root].dat. Useful for debugging (default: false)" |
103 | 127 |
104 # Parse command line | 128 # Parse command line |
105 FLAGS "$@" || exit 1 | 129 FLAGS "$@" || exit 1 |
106 eval set -- "${FLAGS_ARGV}" | 130 eval set -- "${FLAGS_ARGV}" |
107 | 131 |
108 set -e | 132 set -e |
109 | 133 |
110 if [ -n "$FLAGS_src_image" ]; then | 134 if [ -n "$FLAGS_src_image" ]; then |
111 # We need to be in the chroot for generating delta images | 135 # We need to be in the chroot for generating delta images |
112 assert_inside_chroot | 136 assert_inside_chroot |
113 fi | 137 fi |
114 | 138 |
115 locate_gpt | 139 locate_gpt |
116 | 140 |
| 141 if [ "$FLAGS_extract" -eq "$FLAGS_TRUE" ]; then |
| 142 if [ -n "$FLAGS_src_image" ]; then |
| 143 extract_kern_root "$FLAGS_src_image" old_kern.dat old_root.dat |
| 144 fi |
| 145 if [ -n "$FLAGS_image" ]; then |
| 146 extract_kern_root "$FLAGS_image" new_kern.dat new_root.dat |
| 147 fi |
| 148 echo Done extracting kernel/root |
| 149 exit 0 |
| 150 fi |
| 151 |
117 DELTA=$FLAGS_TRUE | 152 DELTA=$FLAGS_TRUE |
118 [ -n "$FLAGS_output" ] || die \ | 153 [ -n "$FLAGS_output" ] || die \ |
119 "Error: you must specify an output filename with --output FILENAME" | 154 "Error: you must specify an output filename with --output FILENAME" |
120 | 155 |
121 if [ -z "$FLAGS_src_image" ]; then | 156 if [ -z "$FLAGS_src_image" ]; then |
122 DELTA=$FLAGS_FALSE | 157 DELTA=$FLAGS_FALSE |
123 if [ "$FLAGS_old_style" = "$FLAGS_TRUE" ]; then | 158 if [ "$FLAGS_old_style" = "$FLAGS_TRUE" ]; then |
124 echo "Generating an old-style full update" | 159 echo "Generating an old-style full update" |
125 else | 160 else |
126 die "Generating a new-style full update not yet supported" | 161 die "Generating a new-style full update not yet supported" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 213 |
179 GENERATOR="$(dirname "$0")/mk_memento_images.sh" | 214 GENERATOR="$(dirname "$0")/mk_memento_images.sh" |
180 | 215 |
181 CROS_GENERATE_UPDATE_PAYLOAD_CALLED=1 "$GENERATOR" "$DST_KERNEL" "$DST_ROOT" | 216 CROS_GENERATE_UPDATE_PAYLOAD_CALLED=1 "$GENERATOR" "$DST_KERNEL" "$DST_ROOT" |
182 mv "$(dirname "$DST_KERNEL")/update.gz" "$FLAGS_output" | 217 mv "$(dirname "$DST_KERNEL")/update.gz" "$FLAGS_output" |
183 | 218 |
184 trap - INT TERM EXIT | 219 trap - INT TERM EXIT |
185 cleanup noexit | 220 cleanup noexit |
186 echo "Done generating full update." | 221 echo "Done generating full update." |
187 fi | 222 fi |
OLD | NEW |