5 ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }
6 libs() { ldd $* | awk '{print $3}'; }
8 install_file() { # <file> [ <file> ... ]
10 dest="$RAM_ROOT/$file"
11 [ -f $file -a ! -f $dest ] && {
12 dir="$(dirname $dest)"
19 install_bin() { # <file> [ <symlink> ... ]
22 [ -x "$src" ] && files="$src $(libs $src)"
24 [ -e /lib/ld-linux.so.3 ] && {
25 install_file /lib/ld-linux.so.3
28 for link in "$@"; do {
29 dest="$RAM_ROOT/$link"
30 dir="$(dirname $dest)"
32 [ -f "$dest" ] || ln -s $src $dest
36 pivot() { # <new_root> <old_root>
37 mount | grep "on $1 type" 2>&- 1>&- || mount -o bind $1 $1
38 mkdir -p $1$2 $1/proc $1/dev $1/tmp $1/overlay && \
39 mount -o move /proc $1/proc && \
40 pivot_root $1 $1$2 || {
44 mount -o move $2/dev /dev
45 mount -o move $2/tmp /tmp
46 mount -o move $2/overlay /overlay 2>&-
50 run_ramfs() { # <command> [...]
51 install_bin /bin/busybox /bin/ash /bin/sh /bin/mount /bin/umount \
52 /sbin/pivot_root /usr/bin/wget /sbin/reboot /bin/sync /bin/dd \
53 /bin/grep /bin/cp /bin/mv /bin/tar /usr/bin/md5sum "/usr/bin/[" \
54 /bin/vi /bin/ls /bin/cat /usr/bin/awk /usr/bin/hexdump \
55 /bin/sleep /bin/zcat /usr/bin/bzcat /usr/bin/printf /usr/bin/wc
58 for file in $RAMFS_COPY_BIN; do
61 install_file /etc/resolv.conf /etc/functions.sh /lib/upgrade/*.sh $RAMFS_COPY_DATA
63 pivot $RAM_ROOT /mnt || {
64 echo "Failed to switch over to ramfs. Please reboot."
68 mount -o remount,ro /mnt
71 grep /overlay /proc/mounts > /dev/null && {
72 mount -o remount,ro /overlay
76 # spawn a new shell from ramdisk to reduce the probability of cache issues
77 exec /bin/busybox ash -c "$*"
88 local default="$1"; shift;
89 local answer="$default"
91 [ "$INTERACTIVE" -eq 1 ] && {
93 0) echo -n "$* (y/N): ";;
94 *) echo -n "$* (Y/n): ";;
100 *) answer="$default";;
107 [ "$VERBOSE" -ge 1 ] && echo "$@"
111 mount | awk '($3 ~ /^\/$/) && ($5 !~ /rootfs/) { print $5 }'
114 get_image() { # <source> [ <command> ]
120 http://*|ftp://*) cmd="wget -O- -q";;
123 if [ -z "$conc" ]; then
124 local magic="$(eval $cmd $from | dd bs=2 count=1 2>/dev/null | hexdump -n 2 -e '1/1 "%02x"')"
131 eval "$cmd $from ${conc:+| $conc}"
135 get_image "$@" | dd bs=2 count=1 2>/dev/null | hexdump -v -n 2 -e '1/1 "%02x"'
139 get_image "$@" | dd bs=4 count=1 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
142 refresh_mtd_partitions() {
146 jffs2_copy_config() {
147 if grep rootfs_data /proc/mtd >/dev/null; then
149 mtd -e rootfs_data jffs2write "$CONF_TAR" rootfs_data
152 mtd jffs2write "$CONF_TAR" rootfs
156 default_do_upgrade() {
158 if [ "$SAVE_CONFIG" -eq 1 -a -z "$USE_REFRESH" ]; then
159 get_image "$1" | mtd -j "$CONF_TAR" write - "${PART_NAME:-image}"
161 get_image "$1" | mtd write - "${PART_NAME:-image}"
166 v "Performing system upgrade..."
167 if type 'platform_do_upgrade' >/dev/null 2>/dev/null; then
168 platform_do_upgrade "$ARGV"
170 default_do_upgrade "$ARGV"
173 [ "$SAVE_CONFIG" -eq 1 -a -n "$USE_REFRESH" ] && {
174 v "Refreshing partitions"
175 if type 'platform_refresh_partitions' >/dev/null 2>/dev/null; then
176 platform_refresh_partitions
178 refresh_mtd_partitions
180 if type 'platform_copy_config' >/dev/null 2>/dev/null; then
186 v "Upgrade completed"
187 [ -n "$DELAY" ] && sleep "$DELAY"
188 ask_bool 1 "Reboot" && {
189 v "Rebooting system..."
192 echo b 2>/dev/null >/proc/sysrq-trigger