3 PATH=/bin:/usr/bin:/sbin:/usr/sbin
9 PARTX="/usr/sbin/partx"
10 BLKID="/usr/sbin/blkid"
11 DIRNAME="/usr/bin/dirname"
21 if [ "z$ARCH" == "zarmv7l" ]; then
22 LD_LINUX="/lib/ld-linux.so.3"
23 elif [ "z$ARCH" == "zaarch64" ]; then
24 LD_LINUX="/lib64/ld-linux-aarch64.so.1"
25 elif [ "z$ARCH" == "zi686" ]; then
26 LD_LINUX="/lib/ld-linux.so.2"
27 elif [ "z$ARCH" == "zx86-64" ]; then
28 LD_LINUX="/lib64/ld-linux-x86-64.so.2"
30 # set as armv7l, need to assign properly
31 LD_LINUX="/lib/ld-linux.so.3"
34 DMVERITY_ROOTFS_VERIFY_HASH="/usr/lib/initrd/bin/dmverity-rootfs-verify-hash.sh"
36 INITRD_ROOT="/mnt/initrd-recovery"
37 HAL_LIST="${INITRD_ROOT}/hal/.hal_list"
39 OBJECTS_SPECIFY_DIR="@INITRD_RECOVERY_INSTALL_DROPIN_DIR@"
69 /opt:run/upgrade-sysroot/opt
74 #-----------------------------------------------------------------------------
76 #-----------------------------------------------------------------------------
79 echo "usage: `basename $0` [OPTION]"
80 echo "make initrd image"
82 echo " -h, --help show help"
83 echo " -p, --post find initrd partition and format and make"
84 echo " initrd image to there"
88 #-----------------------------------------------------------------------------
89 # find initrd-recovery partition
90 #-----------------------------------------------------------------------------
91 find_initrd_recovery_partition() {
92 EMMC_DEVICE="/dev/mmcblk0"
93 RET_PARTX=$("$PARTX" -s ${EMMC_DEVICE})
94 TEST=$(echo "$RET_PARTX" | "$TR" -s ' ' | "$SED" -e '1d' -e 's/^ //' | "$CUT" -d ' ' -f 6)
95 if [ "z$TEST" == "z" ]; then
96 PART_INITRD=$("$BLKID" -L "ramdisk-recovery" -o device)
97 if [ "z$PART_INITRD" == "z" ]; then
98 PART_INITRD=$("$BLKID" -L "ramdisk" -o device)
101 PART_INITRD=${EMMC_DEVICE}p$(
103 "$TR" -s ' ' | "$TR" '[:upper:]' '[:lower:]' |
104 "$GREP" "ramdisk2" | "$SED" 's/^ //' | "$CUT" -d ' ' -f 1)
105 if [ "z$PART_INITRD" == "z/dev/mmcblk0p" ]; then
106 PART_INITRD=${EMMC_DEVICE}p$(
108 "$TR" -s ' ' | "$TR" '[:upper:]' '[:lower:]' |
109 "$GREP" "ramdisk" | "$SED" 's/^ //' | "$CUT" -d ' ' -f 1)
114 #-----------------------------------------------------------------------------
115 # Prepare parent directory
116 #-----------------------------------------------------------------------------
118 dst_dir=`"$DIRNAME" "$1"`
119 if [ ! -d "$dst_dir" -a ! -L "$dst_dir" ]; then
120 "$MKDIR" -p "$dst_dir"
124 #-----------------------------------------------------------------------------
125 # Copy content to root of mounted image
126 #-----------------------------------------------------------------------------
129 dst="$INITRD_ROOT/$src"
131 path_prefix=$(echo $src | "$CUT" -d '/' -f 2)
133 if [ "$path_prefix" == "hal" ]; then
134 remain=$(echo $src | "$SED" 's/\/hal\///')
135 echo "$remain" >> $HAL_LIST
138 if [ ! -e "$src" -o -e "$dst" ]; then
144 "$CP" -f "$src" "$dst"
147 #-----------------------------------------------------------------------------
148 # Get dependency libraries
149 #-----------------------------------------------------------------------------
151 "$LD_LINUX" --list $1 | "$SED" -r 's|^[^/]+([^ \(]+).*$|\1|'
154 #-----------------------------------------------------------------------------
155 # Gather initrd objects
156 #-----------------------------------------------------------------------------
157 get_initrd_objects() {
158 for f in $(ls ${OBJECTS_SPECIFY_DIR}); do
166 source "${OBJECTS_SPECIFY_DIR}"/$f
167 OBJECTS_DIRECTORY="$OBJECTS_DIRECTORY $DIRECTORIES"
168 OBJECTS_DIR_SYMLINK="$OBJECTS_DIR_SYMLINK $DIR_SYMLINKS"
169 OBJECTS_VERBATIM="$OBJECTS_VERBATIM $VERBATIMS"
170 OBJECTS_WITHLIB="$OBJECTS_WITHLIB $WITHLIBS"
171 OBJECTS_LIBONLY="$OBJECTS_LIBONLY $LIBONLYS"
172 OBJECTS_SYMLINK="$OBJECTS_SYMLINK $SYMLINKS"
173 OBJECTS_MVWITHLIB="$OBJECTS_MVWITHLIB $MVWITHLIBS"
176 OBJECTS_DIRECTORY=$(echo "$OBJECTS_DIRECTORY" | sort | uniq)
177 OBJECTS_DIR_SYMLINK=$(echo "$OBJECTS_DIR_SYMLINK" | sort | uniq)
178 OBJECTS_VERBATIM=$(echo "$OBJECTS_VERBATIM" | sort | uniq)
179 OBJECTS_WITHLIB=$(echo "$OBJECTS_WITHLIB" | sort | uniq)
180 OBJECTS_LIBONLY=$(echo "$OBJECTS_LIBONLY" | sort | uniq)
181 OBJECTS_SYMLINK=$(echo "$OBJECTS_SYMLINK" | sort | uniq)
182 OBJECTS_MVWITHLIB=$(echo "$OBJECTS_MVWITHLIB" | sort | uniq)
185 #-----------------------------------------------------------------------------
186 # Prepare directory objects
187 #-----------------------------------------------------------------------------
188 prepare_directory_objects() {
190 "$MKDIR" -p "$INITRD_ROOT$dir"
194 #-----------------------------------------------------------------------------
195 # Copy verbatim objects
196 #-----------------------------------------------------------------------------
203 #-----------------------------------------------------------------------------
204 # Copy withlib objects
205 #-----------------------------------------------------------------------------
207 for content in $@; do
210 DEP_LIBS=$(get_dep_libs $content)
211 for lib in $DEP_LIBS; do
217 mvwithlib_objects() {
218 for content in $@; do
222 "$LD_LINUX" --verify $content
223 if [ $? -eq 0 ]; then
224 DEP_LIBS=$(get_dep_libs $content)
225 for lib in $DEP_LIBS; do
234 #-----------------------------------------------------------------------------
235 # Copy libonly objects
236 #-----------------------------------------------------------------------------
238 for content in $@; do
239 DEP_LIBS=$(get_dep_libs $content)
240 for lib in $DEP_LIBS; do
246 #-----------------------------------------------------------------------------
247 # Copy symlink objects
248 #-----------------------------------------------------------------------------
251 if [ "z$i" == "z" ]; then
257 mkdir_p_parent "$INITRD_ROOT$link"
258 "$LN" -s "$target" "$INITRD_ROOT$link"
262 #-----------------------------------------------------------------------------
264 #-----------------------------------------------------------------------------
265 make_initrd_recovery() {
266 echo "copy initrd objects to $INITRD_ROOT"
269 prepare_directory_objects $BASE_DIRECTORIES
270 symlink_objects $BASE_DIR_SYMLINKS
271 prepare_directory_objects $OBJECTS_DIRECTORY
272 symlink_objects $OBJECTS_DIR_SYMLINK
273 verbatim_objects $OBJECTS_VERBATIM
274 withlib_objects $OBJECTS_WITHLIB
275 libonly_objects $OBJECTS_LIBONLY
276 symlink_objects $OBJECTS_SYMLINK
277 mvwithlib_objects $OBJECTS_MVWITHLIB
279 "$CP" "$DMVERITY_ROOTFS_VERIFY_HASH" "$INITRD_ROOT/usr/bin/dmverity-rootfs-verify-hash.sh"
281 /usr/sbin/ldconfig -r $INITRD_ROOT
284 #-----------------------------------------------------------------------------
285 # Check given parameter is mount point
286 #-----------------------------------------------------------------------------
287 check_mount_point() {
288 grep " $1 " /etc/mtab > /dev/null
289 if [ $? -ne 0 ]; then
290 echo "$1 is not mount point"
295 #-----------------------------------------------------------------------------
297 #-----------------------------------------------------------------------------
298 ARGS=$(getopt -o hp -l "help,post" -n "$0" -- "$@");
319 if [ $# -gt 1 ]; then
320 echo "Error: too many argument was given."
327 find_initrd_recovery_partition
328 if [ "z$PART_INITRD" == "z/dev/mmcblk0p" ]; then
329 echo "Error: failed to find initrd partition"
332 echo "Info: initrd partition: $PART_INITRD"
336 mount $PART_INITRD $INITRD_ROOT
341 check_mount_point $INITRD_ROOT