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

Side by Side Diff: mk_memento_images.sh

Issue 4824003: crosutils: refine memento image / factory package creation (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: should not compress twice 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') | no next file » | 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
11 set -e 11 set -e
12 12
13 LIB_IMAGE_COMMON="$(dirname "$0")/image_common.sh"
14 if ! . "$LIB_IMAGE_COMMON"; then
15 echo "Missing required library: $LIB_IMAGE_COMMON. Cannot continue."
16 exit 1
17 fi
18
13 if [ -z "$2" -o -z "$1" ]; then 19 if [ -z "$2" -o -z "$1" ]; then
14 echo "usage: $0 path/to/kernel_partition_img path/to/rootfs_partition_img" 20 echo "usage: $0 path/to/kernel_partition_img path/to/rootfs_partition_img"
21 echo " or $0 path/to/chromiumos_img kern_part_no rootfs_part_no"
15 exit 1 22 exit 1
16 fi 23 fi
17 24
18 if [ "$CROS_GENERATE_UPDATE_PAYLOAD_CALLED" != "1" ]; then 25 if [ "$CROS_GENERATE_UPDATE_PAYLOAD_CALLED" != "1" ]; then
19 echo "WARNING:" 26 echo "WARNING:"
20 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"
21 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
30
31 if ! has_command pigz; then
32 (echo "WARNING:"
33 echo " Your system does not have pigz (parallel gzip) installed."
34 echo " COMPRESSING WILL BE VERY SLOW. It is recommended to install pigz"
35 if has_command apt-get; then
36 echo " by 'sudo apt-get install pigz'."
37 elif has_command emerge; then
38 echo " by 'sudo emerge pigz'."
39 fi) >&2
22 fi 40 fi
23 41
24 if [ $(whoami) = "root" ]; then 42 if [ $(whoami) = "root" ]; then
25 echo "running $0 as root which is unneccessary" 43 echo "running $0 as root which is unneccessary"
26 fi 44 fi
27 45
28 KPART="$1" 46 # Determine the offset size, and file name of parameters
29 ROOT_PART="$2" 47 if [ -z "$3" ]; then
30 48 # kernnel_img rootfs_img
31 KPART_SIZE=$(stat -c%s "$KPART") 49 KPART="$1"
50 ROOT_PART="$2"
51 KPART_SIZE=$(stat -c%s "$KPART")
52 ROOT_PART_SIZE=$(stat -c%s "$ROOT_PART")
53 KPART_OFFSET=0
54 KPART_SECTORS=$((KPART_SIZE / 512))
55 ROOT_OFFSET=0
56 ROOT_SECTORS=$((ROOT_PART_SIZE / 512))
57 else
58 # chromiumos_img kern_part_no rootfs_part_no
59 KPART="$1"
60 ROOT_PART="$1"
61 KPART_OFFSET="$(part_offset "$KPART" "$2")" ||
62 err_die "cannot retieve kernel partition offset"
63 KPART_SECTORS="$(part_size "$KPART" "$2")" ||
64 err_die "cannot retieve kernel partition size"
65 ROOT_OFFSET="$(part_offset "$ROOT_PART" "$3")" ||
66 err_die "cannot retieve root partition offset"
67 ROOT_SECTORS="$(part_size "$ROOT_PART" "$3")" ||
68 err_die "cannot retieve root partition size"
69 KPART_SIZE=$((KPART_SECTORS * 512))
70 fi
32 71
33 # Sanity check size. 72 # Sanity check size.
34 if [ "$KPART_SIZE" -gt $((16 * 1024 * 1024)) ]; then 73 if [ "$KPART_SIZE" -gt $((16 * 1024 * 1024)) ]; then
35 echo "Kernel partition size ($KPART_SIZE bytes) greater than 16 MiB." 74 echo "Kernel partition size ($KPART_SIZE bytes) greater than 16 MiB."
36 echo "That's too big." 75 echo "That's too big."
37 exit 1 76 exit 1
38 fi 77 fi
39 78
40 FINAL_OUT_FILE=$(dirname "$1")/update.gz 79 FINAL_OUT_FILE=$(dirname "$1")/update.gz
41 UNCOMPRESSED_OUT_FILE="$FINAL_OUT_FILE.uncompressed"
42 80
43 # First, write size of kernel partition in big endian as uint64 to out file 81 # Update payload format:
44 # printf converts it to a number like 00000000003d0900. sed converts it to: 82 # [kernel_size: big-endian uint64][kernel_blob][rootfs_blob]
45 # \\x00\\x00\\x00\\x00\\x00\\x3d\\x09\\x00, then xargs converts it to binary
46 # with echo.
47 printf %016x "$KPART_SIZE" | \
48 sed 's/\([0-9a-f][0-9a-f]\)/\\\\x\1/g' | \
49 xargs echo -ne > "$UNCOMPRESSED_OUT_FILE"
50 83
51 # Next, write kernel partition to the out file 84 # Prepare kernel_size by using printf as a number like 00000000003d0900, then
52 cat "$KPART" >> "$UNCOMPRESSED_OUT_FILE" 85 # sed to convert as: \x00\x00\x00\x00\x00\x3d\x09\x00, finally echo -e to
86 # convert into binary.
87 KPART_SIZE_SIGNATURE="$(printf "%016x" "$KPART_SIZE" |
88 sed 's/\([0-9a-f][0-9a-f]\)/\\x\1/g')"
53 89
54 # Sanity check size of output file now 90 # Build the blob!
55 if [ $(stat -c%s "$UNCOMPRESSED_OUT_FILE") -ne $((8 + $KPART_SIZE)) ]; then 91 CS_AND_RET_CODES="$(
56 echo "Kernel partition changed size during image generation. Aborting." 92 (echo -en "$KPART_SIZE_SIGNATURE"
57 exit 1 93 echo "Compressing kernel..." >&2
58 fi 94 dump_partial_file "$KPART" "$KPART_OFFSET" "$KPART_SECTORS"
95 echo "Compressing rootfs..." >&2
96 dump_partial_file "$ROOT_PART" "$ROOT_OFFSET" "$ROOT_SECTORS") |
97 gzip_compress -9 -c |
98 tee "$FINAL_OUT_FILE" |
99 openssl sha1 -binary |
100 openssl base64 |
101 tr '\n' ' '
102 echo ${PIPESTATUS[*]})"
59 103
60 # Put rootfs into the out file 104 EXPECTED_RET_CODES="0 0 0 0 0 0"
61 cat "$ROOT_PART" >> "$UNCOMPRESSED_OUT_FILE"
62
63 # compress and hash
64 CS_AND_RET_CODES=$(gzip -c "$UNCOMPRESSED_OUT_FILE" | \
65 tee "$FINAL_OUT_FILE" | openssl sha1 -binary | \
66 openssl base64 | tr '\n' ' '; \
67 echo ${PIPESTATUS[*]})
68 EXPECTED_RET_CODES="0 0 0 0 0"
69 set -- $CS_AND_RET_CODES 105 set -- $CS_AND_RET_CODES
70 CALC_CS="$1" 106 CALC_CS="$1"
71 shift 107 shift
72 RET_CODES="$@" 108 RET_CODES="$@"
73 if [ "$RET_CODES" != "$EXPECTED_RET_CODES" ]; then 109 if [ "$RET_CODES" != "$EXPECTED_RET_CODES" ]; then
74 echo compression/hash failed. $RET_CODES 110 echo compression/hash failed. $RET_CODES
75 exit 1 111 exit 1
76 fi 112 fi
77 113
78 rm "$UNCOMPRESSED_OUT_FILE"
79
80 echo Success. hash is "$CALC_CS" 114 echo Success. hash is "$CALC_CS"
OLDNEW
« no previous file with comments | « make_factory_package.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698