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

Side by Side Diff: mk_memento_images.sh

Issue 5168001: cros_utils: refine factory and imaging related scripts (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: merge with latest changes Created 10 years, 1 month 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 | « make_factory_package.sh ('k') | mod_for_factory_scripts/400configAutotest » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 2
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. 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 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 # This script takes a path to a rootfs.ext2 which was generated by 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 8 # build_image.sh and generates an image that can be used for auto
9 # update. 9 # update.
10 10
(...skipping 10 matching lines...) Expand all
21 echo " or $0 path/to/chromiumos_img kern_part_no rootfs_part_no" 21 echo " or $0 path/to/chromiumos_img kern_part_no rootfs_part_no"
22 exit 1 22 exit 1
23 fi 23 fi
24 24
25 if [ "$CROS_GENERATE_UPDATE_PAYLOAD_CALLED" != "1" ]; then 25 if [ "$CROS_GENERATE_UPDATE_PAYLOAD_CALLED" != "1" ]; then
26 echo "WARNING:" 26 echo "WARNING:"
27 echo " This script should only be called from cros_generate_update_payload" 27 echo " This script should only be called from cros_generate_update_payload"
28 echo " Please run that script with --help to see how to use it." 28 echo " Please run that script with --help to see how to use it."
29 fi 29 fi
30 30
31 if ! has_command pigz; then 31 if ! image_has_command pigz; then
32 (echo "WARNING:" 32 (echo "WARNING:"
33 echo " Your system does not have pigz (parallel gzip) installed." 33 echo " Your system does not have pigz (parallel gzip) installed."
34 echo " COMPRESSING WILL BE VERY SLOW. It is recommended to install pigz" 34 echo " COMPRESSING WILL BE VERY SLOW. It is recommended to install pigz"
35 if has_command apt-get; then 35 if image_has_command apt-get; then
36 echo " by 'sudo apt-get install pigz'." 36 echo " by 'sudo apt-get install pigz'."
37 elif has_command emerge; then 37 elif image_has_command emerge; then
38 echo " by 'sudo emerge pigz'." 38 echo " by 'sudo emerge pigz'."
39 fi) >&2 39 fi) >&2
40 fi 40 fi
41 41
42 if [ $(whoami) = "root" ]; then 42 if [ $(whoami) = "root" ]; then
43 echo "running $0 as root which is unneccessary" 43 echo "running $0 as root which is unneccessary"
44 fi 44 fi
45 45
46 # Determine the offset size, and file name of parameters 46 # Determine the offset size, and file name of parameters
47 if [ -z "$3" ]; then 47 if [ -z "$3" ]; then
48 # kernnel_img rootfs_img 48 # kernnel_img rootfs_img
49 KPART="$1" 49 KPART="$1"
50 ROOT_PART="$2" 50 ROOT_PART="$2"
51 KPART_SIZE=$(stat -c%s "$KPART") 51 KPART_SIZE=$(stat -c%s "$KPART")
52 ROOT_PART_SIZE=$(stat -c%s "$ROOT_PART") 52 ROOT_PART_SIZE=$(stat -c%s "$ROOT_PART")
53 KPART_OFFSET=0 53 KPART_OFFSET=0
54 KPART_SECTORS=$((KPART_SIZE / 512)) 54 KPART_SECTORS=$((KPART_SIZE / 512))
55 ROOT_OFFSET=0 55 ROOT_OFFSET=0
56 ROOT_SECTORS=$((ROOT_PART_SIZE / 512)) 56 ROOT_SECTORS=$((ROOT_PART_SIZE / 512))
57 else 57 else
58 # chromiumos_img kern_part_no rootfs_part_no 58 # chromiumos_img kern_part_no rootfs_part_no
59 KPART="$1" 59 KPART="$1"
60 ROOT_PART="$1" 60 ROOT_PART="$1"
61 KPART_OFFSET="$(part_offset "$KPART" "$2")" || 61 KPART_OFFSET="$(image_part_offset "$KPART" "$2")" ||
62 err_die "cannot retieve kernel partition offset" 62 image_die "cannot retieve kernel partition offset"
63 KPART_SECTORS="$(part_size "$KPART" "$2")" || 63 KPART_SECTORS="$(image_part_size "$KPART" "$2")" ||
64 err_die "cannot retieve kernel partition size" 64 image_die "cannot retieve kernel partition size"
65 ROOT_OFFSET="$(part_offset "$ROOT_PART" "$3")" || 65 ROOT_OFFSET="$(image_part_offset "$ROOT_PART" "$3")" ||
66 err_die "cannot retieve root partition offset" 66 image_die "cannot retieve root partition offset"
67 ROOT_SECTORS="$(part_size "$ROOT_PART" "$3")" || 67 ROOT_SECTORS="$(image_part_size "$ROOT_PART" "$3")" ||
68 err_die "cannot retieve root partition size" 68 image_die "cannot retieve root partition size"
69 KPART_SIZE=$((KPART_SECTORS * 512)) 69 KPART_SIZE=$((KPART_SECTORS * 512))
70 fi 70 fi
71 71
72 # Sanity check size. 72 # Sanity check size.
73 if [ "$KPART_SIZE" -gt $((16 * 1024 * 1024)) ]; then 73 if [ "$KPART_SIZE" -gt $((16 * 1024 * 1024)) ]; then
74 echo "Kernel partition size ($KPART_SIZE bytes) greater than 16 MiB." 74 echo "Kernel partition size ($KPART_SIZE bytes) greater than 16 MiB."
75 echo "That's too big." 75 echo "That's too big."
76 exit 1 76 exit 1
77 fi 77 fi
78 78
79 FINAL_OUT_FILE=$(dirname "$1")/update.gz 79 FINAL_OUT_FILE=$(dirname "$1")/update.gz
80 80
81 # Update payload format: 81 # Update payload format:
82 # [kernel_size: big-endian uint64][kernel_blob][rootfs_blob] 82 # [kernel_size: big-endian uint64][kernel_blob][rootfs_blob]
83 83
84 # Prepare kernel_size by using printf as a number like 00000000003d0900, then 84 # Prepare kernel_size by using printf as a number like 00000000003d0900, then
85 # sed to convert as: \x00\x00\x00\x00\x00\x3d\x09\x00, finally echo -e to 85 # sed to convert as: \x00\x00\x00\x00\x00\x3d\x09\x00, finally echo -e to
86 # convert into binary. 86 # convert into binary.
87 KPART_SIZE_SIGNATURE="$(printf "%016x" "$KPART_SIZE" | 87 KPART_SIZE_SIGNATURE="$(printf "%016x" "$KPART_SIZE" |
88 sed 's/\([0-9a-f][0-9a-f]\)/\\x\1/g')" 88 sed 's/\([0-9a-f][0-9a-f]\)/\\x\1/g')"
89 89
90 # Build the blob! 90 # Build the blob!
91 CS_AND_RET_CODES="$( 91 CS_AND_RET_CODES="$(
92 (echo -en "$KPART_SIZE_SIGNATURE" 92 (echo -en "$KPART_SIZE_SIGNATURE"
93 echo "Compressing kernel..." >&2 93 echo "Compressing kernel..." >&2
94 dump_partial_file "$KPART" "$KPART_OFFSET" "$KPART_SECTORS" 94 image_dump_partial_file "$KPART" "$KPART_OFFSET" "$KPART_SECTORS"
95 echo "Compressing rootfs..." >&2 95 echo "Compressing rootfs..." >&2
96 dump_partial_file "$ROOT_PART" "$ROOT_OFFSET" "$ROOT_SECTORS") | 96 image_dump_partial_file "$ROOT_PART" "$ROOT_OFFSET" "$ROOT_SECTORS") |
97 gzip_compress -9 -c | 97 image_gzip_compress -c -9 |
98 tee "$FINAL_OUT_FILE" | 98 tee "$FINAL_OUT_FILE" |
99 openssl sha1 -binary | 99 openssl sha1 -binary |
100 openssl base64 | 100 openssl base64 |
101 tr '\n' ' ' 101 tr '\n' ' '
102 echo ${PIPESTATUS[*]})" 102 echo ${PIPESTATUS[*]})"
103 103
104 EXPECTED_RET_CODES="0 0 0 0 0 0" 104 EXPECTED_RET_CODES="0 0 0 0 0 0"
105 set -- $CS_AND_RET_CODES 105 set -- $CS_AND_RET_CODES
106 CALC_CS="$1" 106 CALC_CS="$1"
107 shift 107 shift
108 RET_CODES="$@" 108 RET_CODES="$@"
109 if [ "$RET_CODES" != "$EXPECTED_RET_CODES" ]; then 109 if [ "$RET_CODES" != "$EXPECTED_RET_CODES" ]; then
110 echo compression/hash failed. $RET_CODES 110 echo compression/hash failed. $RET_CODES
111 exit 1 111 exit 1
112 fi 112 fi
113 113
114 echo Success. hash is "$CALC_CS" 114 echo Success. hash is "$CALC_CS"
OLDNEW
« no previous file with comments | « make_factory_package.sh ('k') | mod_for_factory_scripts/400configAutotest » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698