Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(686)

Side by Side Diff: bin/cros_generate_update_payload

Issue 6413012: chromeos-installer: delete unused files (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/installer.git@master
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « bin/cros_emit_gpt_scripts.sh ('k') | bin/cros_image_to_usb.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 # 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.
9
10 # Load common constants. This should be the first executable line.
11 # The path to common.sh should be relative to your script's location.
12 . "/usr/lib/crosutils/common.sh"
13
14 # Load functions and constants for chromeos-install
15 . "/usr/lib/installer/chromeos-common.sh"
16
17 SRC_MNT=""
18 DST_MNT=""
19 SRC_KERNEL=""
20 SRC_ROOT=""
21 DST_KERNEL=""
22 DST_ROOT=""
23 STATE_MNT=""
24 STATE_LOOP_DEV=""
25
26 # Pass an arg to not exit 1 at the end
27 cleanup() {
28 set +e
29 echo "Cleaning up"
30 if [ -n "$SRC_MNT" ]; then
31 sudo umount -d "$SRC_MNT"
32 [ -d "$SRC_MNT" ] && rmdir "$SRC_MNT"
33 SRC_MNT=""
34 fi
35 if [ -n "$DST_MNT" ]; then
36 sudo umount -d "$DST_MNT"
37 [ -d "$DST_MNT" ] && rmdir "$DST_MNT"
38 DST_MNT=""
39 fi
40 if [ -n "$STATE_MNT" ]; then
41 sudo umount "$STATE_MNT"
42 [ -d "$STATE_MNT" ] && rmdir "$STATE_MNT"
43 STATE_MNT=""
44 fi
45 if [ -n "$STATE_LOOP_DEV" ]; then
46 sudo losetup -d "$STATE_LOOP_DEV"
47 STATE_LOOP_DEV=""
48 fi
49 rm -f "$SRC_KERNEL"
50 rm -f "$SRC_ROOT"
51 rm -f "$DST_KERNEL"
52 rm -f "$DST_ROOT"
53 [ -n "$1" ] || exit 1
54 }
55
56 extract_partition_to_temp_file() {
57 local filename="$1"
58 local partition="$2"
59 local temp_file=$(mktemp /tmp/generate_update_payload.XXXXXX)
60
61 local offset=$(partoffset "${filename}" ${partition}) # 512-byte sectors
62 local length=$(partsize "${filename}" ${partition}) # 512-byte sectors
63 local bs=512
64 local sectors_per_two_mib=$((2 * 1024 * 1024 / 512))
65 if [ $(( $offset % $sectors_per_two_mib )) -eq 0 -a \
66 $(( $length % $sectors_per_two_mib )) -eq 0 ]; then
67 bs=$((2 * 1024 * 1024))
68 offset=$(($offset / $sectors_per_two_mib))
69 length=$(($length / $sectors_per_two_mib))
70 else
71 warn "partition offset or length not at 2MiB boundary"
72 fi
73 dd if="$filename" of="$temp_file" bs=$bs count="$length" skip="$offset"
74 echo "$temp_file"
75 }
76
77 patch_kernel() {
78 local IMAGE="$1"
79 local KERN_FILE="$2"
80
81 STATE_LOOP_DEV=$(sudo losetup -f)
82 [ -n "$STATE_LOOP_DEV" ] || die "no free loop device"
83 local offset=$(partoffset "${IMAGE}" 1)
84 offset=$(($offset * 512))
85 sudo losetup -o "$offset" "$STATE_LOOP_DEV" "$IMAGE"
86 STATE_MNT=$(mktemp -d /tmp/state.XXXXXX)
87 sudo mount "$STATE_LOOP_DEV" "$STATE_MNT"
88 dd if="$STATE_MNT"/vmlinuz_hd.vblock of="$KERN_FILE" conv=notrunc
89 sudo umount "$STATE_MNT"
90 STATE_MNT=""
91 sudo losetup -d "$STATE_LOOP_DEV"
92 STATE_LOOP_DEV=""
93 }
94
95 # We should be in the chroot.
96 assert_inside_chroot
97
98 DEFINE_string image "" "The image that should be sent to clients."
99 DEFINE_string src_image "" "Optional: a source image. If specified, this makes\
100 a delta update."
101 DEFINE_boolean old_style "$FLAGS_TRUE" "Generate an old-style .gz full update."
102 DEFINE_string output "" "Output file"
103 DEFINE_boolean patch_kernel "$FLAGS_FALSE" "Whether or not to patch the kernel \
104 with the patch from the stateful partition (default: false)"
105
106 # Parse command line
107 FLAGS "$@" || exit 1
108 eval set -- "${FLAGS_ARGV}"
109
110 set -e
111
112 locate_gpt
113
114 DELTA=$FLAGS_TRUE
115 [ -n "$FLAGS_output" ] || die \
116 "Error: you must specify an output filename with --output FILENAME"
117
118 if [ -z "$FLAGS_src_image" ]; then
119 DELTA=$FLAGS_FALSE
120 if [ "$FLAGS_old_style" = "$FLAGS_TRUE" ]; then
121 echo "Generating an old-style full update"
122 else
123 die "Generating a new-style full update not yet supported"
124 fi
125 fi
126
127 if [ "$DELTA" -eq "$FLAGS_TRUE" ]; then
128 echo "Generating a delta update"
129
130 # Sanity check that the real generator exists:
131 GENERATOR="$(dirname "$0")/../platform/update_engine/delta_generator"
132 [ -x "$GENERATOR" ] || die "$GENERATOR doesn't exist, or isn't executable"
133
134 trap cleanup INT TERM EXIT
135 SRC_KERNEL=$(extract_partition_to_temp_file "$FLAGS_src_image" 2)
136 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then
137 patch_kernel "$FLAGS_src_image" "$SRC_KERNEL"
138 fi
139 SRC_ROOT=$(extract_partition_to_temp_file "$FLAGS_src_image" 3)
140
141 echo md5sum of src kernel:
142 md5sum "$SRC_KERNEL"
143 echo md5sum of src root:
144 md5sum "$SRC_ROOT"
145
146 DST_KERNEL=$(extract_partition_to_temp_file "$FLAGS_image" 2)
147 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then
148 patch_kernel "$FLAGS_image" "$DST_KERNEL"
149 fi
150 DST_ROOT=$(extract_partition_to_temp_file "$FLAGS_image" 3)
151
152 SRC_MNT=$(mktemp -d /tmp/src_root.XXXXXX)
153 sudo mount -o loop,ro "$SRC_ROOT" "$SRC_MNT"
154
155 DST_MNT=$(mktemp -d /tmp/src_root.XXXXXX)
156 sudo mount -o loop,ro "$DST_ROOT" "$DST_MNT"
157
158 sudo "$GENERATOR" \
159 -new_dir "$DST_MNT" -new_image "$DST_ROOT" -new_kernel "$DST_KERNEL" \
160 -old_dir "$SRC_MNT" -old_image "$SRC_ROOT" -old_kernel "$SRC_KERNEL" \
161 -out_file "$FLAGS_output"
162
163 trap - INT TERM EXIT
164 cleanup noexit
165 echo "Done generating delta."
166 else
167 echo "Generating full update"
168
169 trap cleanup INT TERM EXIT
170 DST_KERNEL=$(extract_partition_to_temp_file "$FLAGS_image" 2)
171 if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then
172 patch_kernel "$FLAGS_image" "$DST_KERNEL"
173 fi
174 DST_ROOT=$(extract_partition_to_temp_file "$FLAGS_image" 3)
175
176 GENERATOR="/usr/bin/cros_mk_memento_images.sh"
177
178 CROS_GENERATE_UPDATE_PAYLOAD_CALLED=1 "$GENERATOR" "$DST_KERNEL" "$DST_ROOT"
179 mv "$(dirname "$DST_KERNEL")/update.gz" "$FLAGS_output"
180
181 trap - INT TERM EXIT
182 cleanup noexit
183 echo "Done generating full update."
184 fi
OLDNEW
« no previous file with comments | « bin/cros_emit_gpt_scripts.sh ('k') | bin/cros_image_to_usb.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698