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

Side by Side Diff: mk_memento_images.sh

Issue 6368069: factory-utils: add factory scripts from crosutils (copy only) (Closed) Base URL: ssh://git.chromium.org/factory-utils@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
« no previous file with comments | « make_factory_package.sh ('k') | serve_factory_packages.py » ('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) 2009 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 takes a path to a rootfs.ext2 which was generated by
8 # build_image.sh and generates an image that can be used for auto
9 # update.
10
11 set -e
12
13 # --- BEGIN COMMON.SH BOILERPLATE ---
14 # Load common CrOS utilities. Inside the chroot this file is installed in
15 # /usr/lib/crosutils. Outside the chroot we find it relative to the script's
16 # location.
17 find_common_sh() {
18 local common_paths=(/usr/lib/crosutils $(dirname "$(readlink -f "$0")"))
19 local path
20
21 SCRIPT_ROOT=
22 for path in "${common_paths[@]}"; do
23 if [ -r "${path}/common.sh" ]; then
24 SCRIPT_ROOT=${path}
25 break
26 fi
27 done
28 }
29
30 find_common_sh
31 . "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1)
32 # --- END COMMON.SH BOILERPLATE ---
33
34 . "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1)
Nick Sanders 2011/02/04 19:55:13 Why is it here twice?
35
36 # Load functions designed for image processing
37 if ! . "${SCRIPT_ROOT}/lib/cros_image_common.sh"; then
38 echo "ERROR: Cannot load required library: lib/cros_image_common.sh; Abort."
39 exit 1
40 fi
41
42 if [ -z "$2" -o -z "$1" ] || [ "${#@}" -ne 2 -a "${#@}" -ne 3 ]; then
43 echo "usage: $0 path/to/kernel_partition_img path/to/rootfs_partition_img"
44 echo " or $0 path/to/chromiumos_img kern_part_no rootfs_part_no"
45 exit 1
46 fi
47
48 if [ "$CROS_GENERATE_UPDATE_PAYLOAD_CALLED" != "1" ]; then
49 echo "WARNING:"
50 echo " This script should only be called from cros_generate_update_payload"
51 echo " Please run that script with --help to see how to use it."
52 fi
53
54 if ! image_has_command pigz; then
55 (echo "WARNING:"
56 echo " Your system does not have pigz (parallel gzip) installed."
57 echo " COMPRESSING WILL BE VERY SLOW. It is recommended to install pigz"
58 if image_has_command apt-get; then
59 echo " by 'sudo apt-get install pigz'."
60 elif image_has_command emerge; then
61 echo " by 'sudo emerge pigz'."
62 fi) >&2
63 fi
64
65 if [ $(whoami) = "root" ]; then
66 echo "running $0 as root which is unneccessary"
67 fi
68
69 # Determine the offset size, and file name of parameters
70 if [ -z "$3" ]; then
71 # kernnel_img rootfs_img
72 KPART="$1"
73 ROOT_PART="$2"
74 KPART_SIZE=$(stat -c%s "$KPART")
75 ROOT_PART_SIZE=$(stat -c%s "$ROOT_PART")
76 KPART_OFFSET=0
77 KPART_SECTORS=$((KPART_SIZE / 512))
78 ROOT_OFFSET=0
79 ROOT_SECTORS=$((ROOT_PART_SIZE / 512))
80 else
81 # chromiumos_img kern_part_no rootfs_part_no
82 KPART="$1"
83 ROOT_PART="$1"
84 KPART_OFFSET="$(image_part_offset "$KPART" "$2")" ||
85 image_die "cannot retieve kernel partition offset"
86 KPART_SECTORS="$(image_part_size "$KPART" "$2")" ||
87 image_die "cannot retieve kernel partition size"
88 ROOT_OFFSET="$(image_part_offset "$ROOT_PART" "$3")" ||
89 image_die "cannot retieve root partition offset"
90 ROOT_SECTORS="$(image_part_size "$ROOT_PART" "$3")" ||
91 image_die "cannot retieve root partition size"
92 KPART_SIZE=$((KPART_SECTORS * 512))
93 fi
94
95 # Sanity check size.
96 if [ "$KPART_SIZE" -gt $((16 * 1024 * 1024)) ]; then
97 echo "Kernel partition size ($KPART_SIZE bytes) greater than 16 MiB."
98 echo "That's too big."
99 exit 1
100 fi
101
102 FINAL_OUT_FILE=$(dirname "$1")/update.gz
103
104 # Update payload format:
105 # [kernel_size: big-endian uint64][kernel_blob][rootfs_blob]
106
107 # Prepare kernel_size by using printf as a number like 00000000003d0900, then
108 # sed to convert as: \x00\x00\x00\x00\x00\x3d\x09\x00, finally echo -e to
109 # convert into binary.
110 KPART_SIZE_SIGNATURE="$(printf "%016x" "$KPART_SIZE" |
111 sed 's/\([0-9a-f][0-9a-f]\)/\\x\1/g')"
112
113 # Build the blob!
114 CS_AND_RET_CODES="$(
115 (echo -en "$KPART_SIZE_SIGNATURE"
116 echo "Compressing kernel..." >&2
117 image_dump_partial_file "$KPART" "$KPART_OFFSET" "$KPART_SECTORS"
118 echo "Compressing rootfs..." >&2
119 image_dump_partial_file "$ROOT_PART" "$ROOT_OFFSET" "$ROOT_SECTORS") |
120 image_gzip_compress -c -9 |
121 tee "$FINAL_OUT_FILE" |
122 openssl sha1 -binary |
123 openssl base64 |
124 tr '\n' ' '
125 echo ${PIPESTATUS[*]})"
126
127 EXPECTED_RET_CODES="0 0 0 0 0 0"
128 set -- $CS_AND_RET_CODES
129 CALC_CS="$1"
130 shift
131 RET_CODES="$@"
132 if [ "$RET_CODES" != "$EXPECTED_RET_CODES" ]; then
133 echo compression/hash failed. $RET_CODES
134 exit 1
135 fi
136
137 echo Success. hash is "$CALC_CS"
OLDNEW
« no previous file with comments | « make_factory_package.sh ('k') | serve_factory_packages.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698