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" == "zriscv64" ]; then
26 LD_LINUX="/lib/ld-linux-riscv64-lp64d.so.1"
27 elif [ "z$ARCH" == "zi686" ]; then
28 LD_LINUX="/lib/ld-linux.so.2"
29 elif [ "z$ARCH" == "zx86-64" ]; then
30 LD_LINUX="/lib64/ld-linux-x86-64.so.2"
32 # set as armv7l, need to assign properly
33 LD_LINUX="/lib/ld-linux.so.3"
36 DMVERITY_ROOTFS_VERIFY_HASH="/initrd/usr/bin/dmverity-rootfs-verify-hash.sh"
37 SECURE_BOOT_PUBLIC_KEY="/initrd/etc/secure-boot-public-key.pem"
39 INITRD_ROOT="/mnt/initrd-recovery"
40 HAL_LIST="${INITRD_ROOT}/hal/.hal_list"
42 OBJECTS_SPECIFY_DIR="@INITRD_RECOVERY_INSTALL_DROPIN_DIR@"
72 /opt:run/upgrade-sysroot/opt
77 #-----------------------------------------------------------------------------
79 #-----------------------------------------------------------------------------
82 echo "usage: `basename $0` [OPTION]"
83 echo "make initrd image"
85 echo " -h, --help show help"
86 echo " -p, --post find initrd partition and format and make"
87 echo " initrd image to there"
91 #-----------------------------------------------------------------------------
92 # find initrd-recovery partition
93 #-----------------------------------------------------------------------------
94 find_initrd_recovery_partition() {
95 EMMC_DEVICE="/dev/mmcblk0"
96 RET_PARTX=$("$PARTX" -s ${EMMC_DEVICE})
97 TEST=$(echo "$RET_PARTX" | "$TR" -s ' ' | "$SED" -e '1d' -e 's/^ //' | "$CUT" -d ' ' -f 6)
98 if [ "z$TEST" == "z" ]; then
99 PART_INITRD=$("$BLKID" -L "ramdisk-recovery" -o device)
100 if [ "z$PART_INITRD" == "z" ]; then
101 PART_INITRD=$("$BLKID" -L "ramdisk" -o device)
104 PART_INITRD=${EMMC_DEVICE}p$(
106 "$TR" -s ' ' | "$TR" '[:upper:]' '[:lower:]' |
107 "$GREP" "ramdisk2" | "$SED" 's/^ //' | "$CUT" -d ' ' -f 1)
108 if [ "z$PART_INITRD" == "z/dev/mmcblk0p" ]; then
109 PART_INITRD=${EMMC_DEVICE}p$(
111 "$TR" -s ' ' | "$TR" '[:upper:]' '[:lower:]' |
112 "$GREP" "ramdisk" | "$SED" 's/^ //' | "$CUT" -d ' ' -f 1)
117 #-----------------------------------------------------------------------------
118 # Prepare parent directory
119 #-----------------------------------------------------------------------------
121 dst_dir=`"$DIRNAME" "$1"`
122 if [ ! -d "$dst_dir" -a ! -L "$dst_dir" ]; then
123 "$MKDIR" -p "$dst_dir"
127 #-----------------------------------------------------------------------------
128 # Copy content to root of mounted image
129 #-----------------------------------------------------------------------------
132 dst="$INITRD_ROOT/$src"
134 path_prefix=$(echo $src | "$CUT" -d '/' -f 2)
136 if [ "$path_prefix" == "hal" ]; then
137 remain=$(echo $src | "$SED" 's/\/hal\///')
138 echo "$remain" >> $HAL_LIST
141 if [ ! -e "$src" -o -e "$dst" ]; then
147 "$CP" -f "$src" "$dst"
150 #-----------------------------------------------------------------------------
151 # Get dependency libraries
152 #-----------------------------------------------------------------------------
154 "$LD_LINUX" --list $1 | "$SED" -r 's|^[^/]+([^ \(]+).*$|\1|'
157 #-----------------------------------------------------------------------------
158 # Gather initrd objects
159 #-----------------------------------------------------------------------------
160 get_initrd_objects() {
161 for f in $(ls ${OBJECTS_SPECIFY_DIR}); do
169 source "${OBJECTS_SPECIFY_DIR}"/$f
170 OBJECTS_DIRECTORY="$OBJECTS_DIRECTORY $DIRECTORIES"
171 OBJECTS_DIR_SYMLINK="$OBJECTS_DIR_SYMLINK $DIR_SYMLINKS"
172 OBJECTS_VERBATIM="$OBJECTS_VERBATIM $VERBATIMS"
173 OBJECTS_WITHLIB="$OBJECTS_WITHLIB $WITHLIBS"
174 OBJECTS_LIBONLY="$OBJECTS_LIBONLY $LIBONLYS"
175 OBJECTS_SYMLINK="$OBJECTS_SYMLINK $SYMLINKS"
176 OBJECTS_MVWITHLIB="$OBJECTS_MVWITHLIB $MVWITHLIBS"
179 OBJECTS_DIRECTORY=$(echo "$OBJECTS_DIRECTORY" | sort | uniq)
180 OBJECTS_DIR_SYMLINK=$(echo "$OBJECTS_DIR_SYMLINK" | sort | uniq)
181 OBJECTS_VERBATIM=$(echo "$OBJECTS_VERBATIM" | sort | uniq)
182 OBJECTS_WITHLIB=$(echo "$OBJECTS_WITHLIB" | sort | uniq)
183 OBJECTS_LIBONLY=$(echo "$OBJECTS_LIBONLY" | sort | uniq)
184 OBJECTS_SYMLINK=$(echo "$OBJECTS_SYMLINK" | sort | uniq)
185 OBJECTS_MVWITHLIB=$(echo "$OBJECTS_MVWITHLIB" | sort | uniq)
188 #-----------------------------------------------------------------------------
189 # Prepare directory objects
190 #-----------------------------------------------------------------------------
191 prepare_directory_objects() {
193 "$MKDIR" -p "$INITRD_ROOT$dir"
197 #-----------------------------------------------------------------------------
198 # Copy verbatim objects
199 #-----------------------------------------------------------------------------
206 #-----------------------------------------------------------------------------
207 # Copy withlib objects
208 #-----------------------------------------------------------------------------
210 for content in $@; do
213 "$LD_LINUX" --verify $content
214 if [ $? -eq 0 ]; then
215 DEP_LIBS=$(get_dep_libs $content)
216 for lib in $DEP_LIBS; do
223 mvwithlib_objects() {
224 for content in $@; do
228 "$LD_LINUX" --verify $content
229 if [ $? -eq 0 ]; then
230 DEP_LIBS=$(get_dep_libs $content)
231 for lib in $DEP_LIBS; do
240 #-----------------------------------------------------------------------------
241 # Copy libonly objects
242 #-----------------------------------------------------------------------------
244 for content in $@; do
245 "$LD_LINUX" --verify $content
246 if [ $? -eq 0 ]; then
247 DEP_LIBS=$(get_dep_libs $content)
248 for lib in $DEP_LIBS; do
255 #-----------------------------------------------------------------------------
256 # Copy symlink objects
257 #-----------------------------------------------------------------------------
260 if [ "z$i" == "z" ]; then
266 mkdir_p_parent "$INITRD_ROOT$link"
267 "$LN" -s "$target" "$INITRD_ROOT$link"
271 #-----------------------------------------------------------------------------
273 #-----------------------------------------------------------------------------
274 make_initrd_recovery() {
275 echo "copy initrd objects to $INITRD_ROOT"
278 prepare_directory_objects $BASE_DIRECTORIES
279 symlink_objects $BASE_DIR_SYMLINKS
280 prepare_directory_objects $OBJECTS_DIRECTORY
281 symlink_objects $OBJECTS_DIR_SYMLINK
282 verbatim_objects $OBJECTS_VERBATIM
283 withlib_objects $OBJECTS_WITHLIB
284 libonly_objects $OBJECTS_LIBONLY
285 symlink_objects $OBJECTS_SYMLINK
286 mvwithlib_objects $OBJECTS_MVWITHLIB
288 if [ -x "$DMVERITY_ROOTFS_VERIFY_HASH" ]; then
289 "$CP" "$DMVERITY_ROOTFS_VERIFY_HASH" "$INITRD_ROOT/usr/bin/dmverity-rootfs-verify-hash.sh"
291 if [ -e "$SECURE_BOOT_PUBLIC_KEY" ]; then
292 "$CP" "$SECURE_BOOT_PUBLIC_KEY" "$INITRD_ROOT/etc/secure-boot-public-key.pem"
295 /usr/sbin/ldconfig -r $INITRD_ROOT
298 #-----------------------------------------------------------------------------
299 # Check given parameter is mount point
300 #-----------------------------------------------------------------------------
301 check_mount_point() {
302 grep " $1 " /etc/mtab > /dev/null
303 if [ $? -ne 0 ]; then
304 echo "$1 is not mount point"
309 #-----------------------------------------------------------------------------
311 #-----------------------------------------------------------------------------
312 ARGS=$(getopt -o hp -l "help,post" -n "$0" -- "$@");
333 if [ $# -gt 1 ]; then
334 echo "Error: too many argument was given."
341 find_initrd_recovery_partition
342 if [ "z$PART_INITRD" == "z/dev/mmcblk0p" ]; then
343 echo "Error: failed to find initrd partition"
346 echo "Info: initrd partition: $PART_INITRD"
350 mount $PART_INITRD $INITRD_ROOT
355 check_mount_point $INITRD_ROOT