OLD | NEW |
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 # Script to modify a keyfob-based chromeos system image for testability. | 7 # Script to modify a keyfob-based chromeos system image for testability. |
8 | 8 |
9 # Load common constants. This should be the first executable line. | 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. | 10 # The path to common.sh should be relative to your script's location. |
11 . "$(dirname "$0")/common.sh" | 11 . "$(dirname "$0")/common.sh" |
12 | 12 |
| 13 # Load functions and constants for chromeos-install |
| 14 . "$(dirname "$0")/chromeos-common.sh" |
| 15 |
13 get_default_board | 16 get_default_board |
14 | 17 |
15 DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" | 18 DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" |
16 DEFINE_string qualdb "/tmp/run_remote_tests.*" \ | 19 DEFINE_string qualdb "/tmp/run_remote_tests.*" \ |
17 "Location of qualified component file" | 20 "Location of qualified component file" |
18 DEFINE_string image "" "Location of the rootfs raw image file" | 21 DEFINE_string image "" "Location of the rootfs raw image file" |
19 DEFINE_boolean manuf $FLAGS_FALSE "Modify the image for manufacturing testing" | 22 DEFINE_boolean manuf $FLAGS_FALSE "Modify the image for manufacturing testing" |
20 DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" "y" | 23 DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" "y" |
21 | 24 |
22 # Parse command line | 25 # Parse command line |
23 FLAGS "$@" || exit 1 | 26 FLAGS "$@" || exit 1 |
24 eval set -- "${FLAGS_ARGV}" | 27 eval set -- "${FLAGS_ARGV}" |
25 | 28 |
26 # No board, no default and no image set then we can't find the image | 29 # No board, no default and no image set then we can't find the image |
27 if [ -z $FLAGS_IMAGE ] && [ -z $FLAGS_board ] ; then | 30 if [ -z $FLAGS_image ] && [ -z $FLAGS_board ] ; then |
28 setup_board_warning | 31 setup_board_warning |
29 echo "*** mod_image_for_test failed. No board set and no image set" | 32 echo "*** mod_image_for_test failed. No board set and no image set" |
30 exit 1 | 33 exit 1 |
31 fi | 34 fi |
32 | 35 |
33 # We have a board name but no image set. Use image at default location | 36 # We have a board name but no image set. Use image at default location |
34 if [ -z $FLAGS_image ] ; then | 37 if [ -z $FLAGS_image ] ; then |
35 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" | 38 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" |
36 FLAGS_image="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/rootfs.image" | 39 FILENAME="chromiumos_test_image.bin" |
| 40 FLAGS_image="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/${FILENAME}" |
37 fi | 41 fi |
38 | 42 |
39 # Abort early if we can't find the image | 43 # Abort early if we can't find the image |
40 if [ ! -f $FLAGS_image ] ; then | 44 if [ ! -f $FLAGS_image ] ; then |
41 echo "No image found at $FLAGS_image" | 45 echo "No image found at $FLAGS_image" |
42 exit 1 | 46 exit 1 |
43 fi | 47 fi |
44 | 48 |
45 # Make sure anything mounted in the rootfs is cleaned up ok on exit. | 49 # Make sure anything mounted in the rootfs is cleaned up ok on exit. |
46 cleanup_rootfs_mounts() { | 50 cleanup_rootfs_mounts() { |
47 # Occasionally there are some daemons left hanging around that have our | 51 # Occasionally there are some daemons left hanging around that have our |
48 # root image file system open. We do a best effort attempt to kill them. | 52 # root image file system open. We do a best effort attempt to kill them. |
49 PIDS=`sudo lsof -t "${ROOT_FS_DIR}" | sort | uniq` | 53 PIDS=`sudo lsof -t "${ROOT_FS_DIR}" | sort | uniq` |
50 for pid in ${PIDS} | 54 for pid in ${PIDS} |
51 do | 55 do |
52 local cmdline=`cat /proc/$pid/cmdline` | 56 local cmdline=`cat /proc/$pid/cmdline` |
53 echo "Killing process that has open file on our rootfs: $cmdline" | 57 echo "Killing process that has open file on our rootfs: $cmdline" |
54 ! sudo kill $pid # Preceded by ! to disable ERR trap. | 58 sudo kill $pid || /bin/true |
55 done | 59 done |
56 } | 60 } |
57 | 61 |
58 cleanup_rootfs_loop() { | 62 cleanup_rootfs_loop() { |
59 sudo umount "${LOOP_DEV}" | 63 sudo umount "${LOOP_DEV}" |
60 sleep 1 # in case $LOOP_DEV is in use | 64 sleep 1 # in case $LOOP_DEV is in use |
61 sudo losetup -d "${LOOP_DEV}" | 65 sudo losetup -d "${LOOP_DEV}" |
62 } | 66 } |
63 | 67 |
64 cleanup() { | 68 cleanup() { |
65 # Disable die on error. | 69 # Disable die on error. |
66 set +e | 70 set +e |
67 | 71 |
68 cleanup_rootfs_mounts | 72 cleanup_rootfs_mounts |
69 if [ -n "${LOOP_DEV}" ] | 73 if [ -n "${LOOP_DEV}" ] |
70 then | 74 then |
71 cleanup_rootfs_loop | 75 cleanup_rootfs_loop |
72 fi | 76 fi |
73 | 77 |
74 # Turn die on error back on. | 78 # Turn die on error back on. |
75 set -e | 79 set -e |
76 } | 80 } |
77 | 81 |
78 # main process begins here. | 82 # main process begins here. |
79 set -e | |
80 trap cleanup EXIT | |
81 | |
82 ROOT_FS_DIR="`dirname ${FLAGS_image}`/rootfs" | |
83 mkdir -p "${ROOT_FS_DIR}" | |
84 | |
85 LOOP_DEV=`sudo losetup -f` | |
86 sudo losetup "${LOOP_DEV}" "${FLAGS_image}" | |
87 sudo mount "${LOOP_DEV}" "${ROOT_FS_DIR}" | |
88 | 83 |
89 # Make sure this is really what the user wants, before nuking the device | 84 # Make sure this is really what the user wants, before nuking the device |
90 if [ $FLAGS_yes -ne $FLAGS_TRUE ]; then | 85 if [ $FLAGS_yes -ne $FLAGS_TRUE ]; then |
91 read -p "Modifying image ${FLAGS_image} for test; are you sure (y/N)? " SURE | 86 read -p "Modifying image ${FLAGS_image} for test; are you sure (y/N)? " SURE |
92 SURE="${SURE:0:1}" # Get just the first character | 87 SURE="${SURE:0:1}" # Get just the first character |
93 if [ "$SURE" != "y" ]; then | 88 if [ "$SURE" != "y" ]; then |
94 echo "Ok, better safe than sorry." | 89 echo "Ok, better safe than sorry." |
95 exit 1 | 90 exit 1 |
96 fi | 91 fi |
97 else | 92 else |
98 echo "Modifying image ${FLAGS_image} for test..." | 93 echo "Modifying image ${FLAGS_image} for test..." |
99 fi | 94 fi |
100 | 95 |
| 96 set -e |
| 97 trap cleanup EXIT |
| 98 |
| 99 ROOT_FS_DIR=$(dirname "${FLAGS_image}")/rootfs |
| 100 mkdir -p "${ROOT_FS_DIR}" |
| 101 |
| 102 # Figure out how to loop mount the rootfs partition. It should be partition 3 |
| 103 # on the disk image. |
| 104 offset=$(partoffset "${FLAGS_image}" 3) |
| 105 |
| 106 LOOP_DEV=$(sudo losetup -f) |
| 107 if [ -z "$LOOP_DEV" ]; then |
| 108 echo "No free loop device" |
| 109 exit 1 |
| 110 fi |
| 111 sudo losetup -o $(( $offset * 512 )) "${LOOP_DEV}" "${FLAGS_image}" |
| 112 sudo mount "${LOOP_DEV}" "${ROOT_FS_DIR}" |
| 113 |
101 MOD_SCRIPTS_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts" | 114 MOD_SCRIPTS_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts" |
102 # Run test setup script inside chroot jail to modify the image | 115 # Run test setup script inside chroot jail to modify the image |
103 sudo GCLIENT_ROOT=${GCLIENT_ROOT} ROOT_FS_DIR=${ROOT_FS_DIR} \ | 116 sudo GCLIENT_ROOT="${GCLIENT_ROOT}" ROOT_FS_DIR="${ROOT_FS_DIR}" \ |
104 "${MOD_SCRIPTS_ROOT}/test_setup.sh" | 117 "${MOD_SCRIPTS_ROOT}/test_setup.sh" |
105 | 118 |
106 # Run manufacturing test setup | 119 # Run manufacturing test setup |
107 if [ ${FLAGS_manuf} -eq ${FLAGS_TRUE} ]; then | 120 if [ ${FLAGS_manuf} -eq ${FLAGS_TRUE} ]; then |
108 echo "Modifying image ${FLAGS_image} for manufacturing test..." | 121 echo "Modifying image ${FLAGS_image} for manufacturing test..." |
109 | 122 |
110 # Try to use the sytem component file in the most recent autotest result | 123 # Try to use the sytem component file in the most recent autotest result |
111 FLAGS_qualdb=$(ls -dt ${FLAGS_qualdb} 2>&-| head -1) | 124 FLAGS_qualdb=$(ls -dt ${FLAGS_qualdb} 2>&-| head -1) |
112 | 125 |
113 # Try to append the full path to the file if FLAGS_qualdb is a directory | 126 # Try to append the full path to the file if FLAGS_qualdb is a directory |
(...skipping 12 matching lines...) Expand all Loading... |
126 ${ROOT_FS_DIR}/usr/local/manufacturing/qualified_components | 139 ${ROOT_FS_DIR}/usr/local/manufacturing/qualified_components |
127 else | 140 else |
128 echo "No qualified component file found at: ${FLAGS_qualdb}" | 141 echo "No qualified component file found at: ${FLAGS_qualdb}" |
129 exit 1 | 142 exit 1 |
130 fi | 143 fi |
131 fi | 144 fi |
132 | 145 |
133 cleanup | 146 cleanup |
134 trap - EXIT | 147 trap - EXIT |
135 | 148 |
OLD | NEW |