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 INITRD_ROOT="/mnt/initrd-recovery"
35 HAL_LIST="${INITRD_ROOT}/hal/.hal_list"
37 OBJECTS_SPECIFY_DIR="@INITRD_RECOVERY_INSTALL_DROPIN_DIR@"
67 /opt:run/upgrade-sysroot/opt
72 #-----------------------------------------------------------------------------
74 #-----------------------------------------------------------------------------
77 echo "usage: `basename $0` [OPTION]"
78 echo "make initrd image"
80 echo " -h, --help show help"
81 echo " -p, --post find initrd partition and format and make"
82 echo " initrd image to there"
86 #-----------------------------------------------------------------------------
87 # find initrd-recovery partition
88 #-----------------------------------------------------------------------------
89 find_initrd_recovery_partition() {
90 EMMC_DEVICE="/dev/mmcblk0"
91 RET_PARTX=$("$PARTX" -s ${EMMC_DEVICE})
92 TEST=$(echo "$RET_PARTX" | "$TR" -s ' ' | "$SED" -e '1d' -e 's/^ //' | "$CUT" -d ' ' -f 6)
93 if [ "z$TEST" == "z" ]; then
94 PART_INITRD=$("$BLKID" -L "ramdisk-recovery" -o device)
95 if [ "z$PART_INITRD" == "z" ]; then
96 PART_INITRD=$("$BLKID" -L "ramdisk" -o device)
99 PART_INITRD=${EMMC_DEVICE}p$(
101 "$TR" -s ' ' | "$TR" '[:upper:]' '[:lower:]' |
102 "$GREP" "ramdisk2" | "$SED" 's/^ //' | "$CUT" -d ' ' -f 1)
103 if [ "z$PART_INITRD" == "z/dev/mmcblk0p" ]; then
104 PART_INITRD=${EMMC_DEVICE}p$(
106 "$TR" -s ' ' | "$TR" '[:upper:]' '[:lower:]' |
107 "$GREP" "ramdisk" | "$SED" 's/^ //' | "$CUT" -d ' ' -f 1)
112 #-----------------------------------------------------------------------------
113 # Prepare parent directory
114 #-----------------------------------------------------------------------------
116 dst_dir=`"$DIRNAME" "$1"`
117 if [ ! -d "$dst_dir" -a ! -L "$dst_dir" ]; then
118 "$MKDIR" -p "$dst_dir"
122 #-----------------------------------------------------------------------------
123 # Copy content to root of mounted image
124 #-----------------------------------------------------------------------------
127 dst="$INITRD_ROOT/$src"
129 path_prefix=$(echo $src | "$CUT" -d '/' -f 2)
131 if [ "$path_prefix" == "hal" ]; then
132 remain=$(echo $src | "$SED" 's/\/hal\///')
133 echo "$remain" >> $HAL_LIST
136 if [ ! -e "$src" -o -e "$dst" ]; then
142 "$CP" -f "$src" "$dst"
145 #-----------------------------------------------------------------------------
146 # Get dependency libraries
147 #-----------------------------------------------------------------------------
149 "$LD_LINUX" --list $1 | "$SED" -r 's|^[^/]+([^ \(]+).*$|\1|'
152 #-----------------------------------------------------------------------------
153 # Gather initrd objects
154 #-----------------------------------------------------------------------------
155 get_initrd_objects() {
156 for f in $(ls ${OBJECTS_SPECIFY_DIR}); do
164 source "${OBJECTS_SPECIFY_DIR}"/$f
165 OBJECTS_DIRECTORY="$OBJECTS_DIRECTORY $DIRECTORIES"
166 OBJECTS_DIR_SYMLINK="$OBJECTS_DIR_SYMLINK $DIR_SYMLINKS"
167 OBJECTS_VERBATIM="$OBJECTS_VERBATIM $VERBATIMS"
168 OBJECTS_WITHLIB="$OBJECTS_WITHLIB $WITHLIBS"
169 OBJECTS_LIBONLY="$OBJECTS_LIBONLY $LIBONLYS"
170 OBJECTS_SYMLINK="$OBJECTS_SYMLINK $SYMLINKS"
171 OBJECTS_MVWITHLIB="$OBJECTS_MVWITHLIB $MVWITHLIBS"
174 OBJECTS_DIRECTORY=$(echo "$OBJECTS_DIRECTORY" | sort | uniq)
175 OBJECTS_DIR_SYMLINK=$(echo "$OBJECTS_DIR_SYMLINK" | sort | uniq)
176 OBJECTS_VERBATIM=$(echo "$OBJECTS_VERBATIM" | sort | uniq)
177 OBJECTS_WITHLIB=$(echo "$OBJECTS_WITHLIB" | sort | uniq)
178 OBJECTS_LIBONLY=$(echo "$OBJECTS_LIBONLY" | sort | uniq)
179 OBJECTS_SYMLINK=$(echo "$OBJECTS_SYMLINK" | sort | uniq)
180 OBJECTS_MVWITHLIB=$(echo "$OBJECTS_MVWITHLIB" | sort | uniq)
183 #-----------------------------------------------------------------------------
184 # Prepare directory objects
185 #-----------------------------------------------------------------------------
186 prepare_directory_objects() {
188 "$MKDIR" -p "$INITRD_ROOT$dir"
192 #-----------------------------------------------------------------------------
193 # Copy verbatim objects
194 #-----------------------------------------------------------------------------
201 #-----------------------------------------------------------------------------
202 # Copy withlib objects
203 #-----------------------------------------------------------------------------
205 for content in $@; do
208 DEP_LIBS=$(get_dep_libs $content)
209 for lib in $DEP_LIBS; do
215 mvwithlib_objects() {
216 for content in $@; do
220 "$LD_LINUX" --verify $content
221 if [ $? -eq 0 ]; then
222 DEP_LIBS=$(get_dep_libs $content)
223 for lib in $DEP_LIBS; do
232 #-----------------------------------------------------------------------------
233 # Copy libonly objects
234 #-----------------------------------------------------------------------------
236 for content in $@; do
237 DEP_LIBS=$(get_dep_libs $content)
238 for lib in $DEP_LIBS; do
244 #-----------------------------------------------------------------------------
245 # Copy symlink objects
246 #-----------------------------------------------------------------------------
249 if [ "z$i" == "z" ]; then
255 mkdir_p_parent "$INITRD_ROOT$link"
256 "$LN" -s "$target" "$INITRD_ROOT$link"
260 #-----------------------------------------------------------------------------
262 #-----------------------------------------------------------------------------
263 make_initrd_recovery() {
264 echo "copy initrd objects to $INITRD_ROOT"
267 prepare_directory_objects $BASE_DIRECTORIES
268 symlink_objects $BASE_DIR_SYMLINKS
269 prepare_directory_objects $OBJECTS_DIRECTORY
270 symlink_objects $OBJECTS_DIR_SYMLINK
271 verbatim_objects $OBJECTS_VERBATIM
272 withlib_objects $OBJECTS_WITHLIB
273 libonly_objects $OBJECTS_LIBONLY
274 symlink_objects $OBJECTS_SYMLINK
275 mvwithlib_objects $OBJECTS_MVWITHLIB
276 /usr/sbin/ldconfig -r $INITRD_ROOT
279 #-----------------------------------------------------------------------------
280 # Check given parameter is mount point
281 #-----------------------------------------------------------------------------
282 check_mount_point() {
283 grep " $1 " /etc/mtab > /dev/null
284 if [ $? -ne 0 ]; then
285 echo "$1 is not mount point"
290 #-----------------------------------------------------------------------------
292 #-----------------------------------------------------------------------------
293 ARGS=$(getopt -o hp -l "help,post" -n "$0" -- "$@");
314 if [ $# -gt 1 ]; then
315 echo "Error: too many argument was given."
322 find_initrd_recovery_partition
323 if [ "z$PART_INITRD" == "z/dev/mmcblk0p" ]; then
324 echo "Error: failed to find initrd partition"
327 echo "Info: initrd partition: $PART_INITRD"
331 mount $PART_INITRD $INITRD_ROOT
336 check_mount_point $INITRD_ROOT