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

Side by Side Diff: scripts/image_signing/tag_image.sh

Issue 3604001: New utility to tag/stamp image (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git
Patch Set: fix parentheses consisntency Created 10 years, 2 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 | « scripts/image_signing/sign_official_build.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
(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 manipulate the tag files in the output of build_image
8
9 # Load common constants. This should be the first executable line.
10 # The path to common.sh should be relative to your script's location.
11 . "$(dirname "$0")/common.sh"
12
13 DEFINE_string from "chromiumos_image.bin" \
14 "Input file name of Chrome OS image to tag/stamp."
15 DEFINE_string update_firmware "" \
16 "Tag to force updating firmware (1 to enable, 0 to disable)"
17 DEFINE_string dev_mode "" \
18 "Tag for developer mode (1 to enable, 0 to disable)"
19
20 # Parse command line
21 FLAGS "$@" || exit 1
22 eval set -- "${FLAGS_ARGV}"
23
24 # Abort on error
25 set -e
26
27 if [ -z ${FLAGS_from} ] || [ ! -f ${FLAGS_from} ] ; then
28 echo "Error: invalid flag --from"
29 exit 1
30 fi
31
32 # Global variable to track if image is modified.
33 g_modified=${FLAGS_FALSE}
34
35 # Processes (enable, disable, or simply report) a tag file.
36 # Args: DO_MODIFICATION NAME ROOT TAG_FILE ACTION
37 #
38 # When DO_MODIFICATION=${FLAGS_TRUE},
39 # Creates (ACTION=1) the TAG_FILE in ROOT, or
40 # removes (ACTION=0) the TAG_FILE in ROOT, then
41 # reports the status (and change) to the tag file.
42 # When DO_MODIFICATION=${FLAGS_FALSE},
43 # make a dry-run and only change ${g_modified}
44 function process_tag() {
45 local tag_status_text=""
46 local do_modification="$1"
47 local name="$2"
48 local root="$3"
49 local tag_file_path="$3/$4"
50 local action="$5"
51 local do_enable=${FLAGS_FALSE}
52 local do_disable=${FLAGS_FALSE}
53
54 # only 1, 0, and "" are valid params to action.
55 case "${action}" in
56 "1" )
57 do_enable=${FLAGS_TRUE}
58 ;;
59 "0" )
60 do_disable=${FLAGS_TRUE}
61 ;;
62 "" )
63 ;;
64 * )
65 echo "Error: invalid param to ${name}: ${action} (must be 1 or 0)."
66 exit 1
67 ;;
68 esac
69
70 if [ -f "${tag_file_path}" ]; then
71 tag_status_text="ENABLED"
72 if [ "${do_disable}" = ${FLAGS_TRUE} ]; then
73 # disable the tag
74 if [ "${do_modification}" = ${FLAGS_TRUE} ]; then
75 sudo rm "${tag_file_path}"
76 fi
77 g_modified=${FLAGS_TRUE}
78 tag_status_text="${tag_status_text} => disabled"
79 elif [ "${do_disable}" != ${FLAGS_FALSE} ]; then
80 # internal error
81 echo "Internal error for tag ${name}: need disable param." 1>&2
82 exit 1
83 fi
84 else
85 tag_status_text="disabled"
86 if [ "${do_enable}" = ${FLAGS_TRUE} ]; then
87 # enable the tag
88 if [ "${do_modification}" = ${FLAGS_TRUE} ]; then
89 sudo touch "${tag_file_path}"
90 fi
91 g_modified=${FLAGS_TRUE}
92 tag_status_text="${tag_status_text} => ENABLED"
93 elif [ "${do_enable}" != ${FLAGS_FALSE} ]; then
94 # internal error
95 echo "Internal error for tag ${name}: need enable param." 1>&2
96 exit 1
97 fi
98 fi
99
100 # report tag status
101 if [ "${do_modification}" != ${FLAGS_TRUE} ]; then
102 echo "${name}: ${tag_status_text}"
103 fi
104 }
105
106 # Iterates all tags to a given partition root.
107 # Args: ROOTFS DO_MODIFICATION
108 #
109 # Check process_tag for the meaning of parameters.
110 process_all_tags() {
111 local rootfs="$1"
112 local do_modification="$2"
113
114 process_tag "${do_modification}" \
115 "Update Firmware" \
116 "${rootfs}" \
117 /root/.force_update_firmware \
118 "${FLAGS_update_firmware}"
119
120 process_tag "${do_modification}" \
121 "Developer Mode" \
122 "${rootfs}" \
123 /root/.dev_mode \
124 "${FLAGS_dev_mode}"
125 }
126
127 IMAGE=$(readlink -f "${FLAGS_from}")
128 if [[ -z "${IMAGE}" || ! -f "${IMAGE}" ]]; then
129 echo "Missing required argument: --from (image to update)"
130 usage
131 exit 1
132 fi
133
134 # First round, mount as read-only and check if we read any modification.
135 rootfs=$(make_temp_dir)
136 mount_image_partition_ro "${IMAGE}" 3 "${rootfs}"
137
138 # we don't have tags in stateful partition yet...
139 # stateful_dir=$(make_temp_dir)
140 # mount_image_partition ${IMAGE} 1 ${stateful_dir}
141
142 process_all_tags "${rootfs}" ${FLAGS_FALSE}
143
144 if [ ${g_modified} = ${FLAGS_TRUE} ]; then
145 # remount as RW (we can't use mount -o rw,remount because of loop device)
146 sudo umount -d "${rootfs}"
147 mount_image_partition "${IMAGE}" 3 "${rootfs}"
148
149 # Second round, apply the modification to image.
150 process_all_tags "${rootfs}" ${FLAGS_TRUE}
151
152 # this is supposed to be automatically done in mount_image_partition,
153 # but it's no harm to explicitly make it again here.
154 tag_as_needs_to_be_resigned "${rootfs}"
155 echo "IMAGE IS MODIFIED. PLEASE REMEMBER TO RESIGN YOUR IMAGE."
156 else
157 echo "Image is not modified."
158 fi
OLDNEW
« no previous file with comments | « scripts/image_signing/sign_official_build.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698