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
/sbin
/pivot_root
/usr
/bin
/wget
/sbin
/reboot
/bin
/sync
/bin
/dd /bin
/grep /bin
/cp /bin
/mv /bin
/tar /usr
/bin
/md5sum "/usr/bin/[" /bin
/vi
/bin
/ls /bin
/cat /usr
/bin
/awk /usr
/bin
/hexdump /bin
/sleep /bin
/zcat
/usr
/bin
/bzcat
53 for file in $RAMFS_COPY_BIN; do
56 install_file
/etc
/resolv.conf
/etc
/functions.sh
/lib
/upgrade
/*.sh
$RAMFS_COPY_DATA
58 pivot
$RAM_ROOT /mnt ||
{
59 echo "Failed to switch over to ramfs. Please reboot."
63 mount
-o remount
,ro
/mnt
66 grep /overlay
/proc
/mounts
> /dev
/null
&& {
67 mount
-o remount
,ro
/overlay
71 # spawn a new shell from ramdisk to reduce the probability of cache issues
72 exec /bin
/busybox ash
-c "$*"
83 local default
="$1"; shift;
84 local answer
="$default"
86 [ "$INTERACTIVE" -eq 1 ] && {
88 0) echo -n "$* (y/N): ";;
89 *) echo -n "$* (Y/n): ";;
95 *) answer
="$default";;
102 [ "$VERBOSE" -ge 1 ] && echo "$@"
106 mount |
awk '($3 ~ /^\/$/) && ($5 !~ /rootfs/) { print $5 }'
109 get_image
() { # <source> [ <command> ]
115 http
://*|
ftp://*) cmd
="wget -O- -q";;
118 if [ -z "$conc" ]; then
119 local magic
="$(eval $cmd $from | dd bs=2 count=1 2>/dev/null | hexdump -n 2 -e '1/1 "%02x
"')"
126 eval "$cmd $from ${conc:+| $conc}"
130 get_image
"$@" |
dd bs
=2 count
=1 2>/dev
/null |
hexdump -v -n 2 -e '1/1 "%02x"'
133 refresh_mtd_partitions
() {
137 jffs2_copy_config
() {
138 if grep rootfs_data
/proc
/mtd
>/dev
/null
; then
140 mtd
-e rootfs_data jffs2write
"$CONF_TAR" rootfs_data
143 mtd jffs2write
"$CONF_TAR" rootfs
147 default_do_upgrade
() {
149 if [ "$SAVE_CONFIG" -eq 1 -a -z "$USE_REFRESH" ]; then
150 get_image
"$1" | mtd
-j "$CONF_TAR" write - "${PART_NAME:-image}"
152 get_image
"$1" | mtd
write - "${PART_NAME:-image}"
157 v
"Performing system upgrade..."
158 if type 'platform_do_upgrade' >/dev
/null
2>/dev
/null
; then
159 platform_do_upgrade
"$ARGV"
161 default_do_upgrade
"$ARGV"
164 [ "$SAVE_CONFIG" -eq 1 -a -n "$USE_REFRESH" ] && {
165 v
"Refreshing partitions"
166 if type 'platform_refresh_partitions' >/dev
/null
2>/dev
/null
; then
167 platform_refresh_partitions
169 refresh_mtd_partitions
171 if type 'platform_copy_config' >/dev
/null
2>/dev
/null
; then
177 v
"Upgrade completed"
178 [ -n "$DELAY" ] && sleep "$DELAY"
179 ask_bool
1 "Reboot" && {
180 v
"Rebooting system..."
183 echo b
2>/dev
/null
>/proc
/sysrq-trigger