Commit 199ca469 authored by Alessandro Rubini's avatar Alessandro Rubini

userspace: new boot/install procedure for V4 partitions

This brings everything into /etc/init.d/wrs-boot-procedure that is
executed as a "sysinit" task, before anything else.  The procedure
runs from the initrd/initramfs and is concerned with the complete
update of the device, if an update is pending.

See documentation (next commit) for details about partitions and boot
procedure.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 6566a942
......@@ -100,6 +100,10 @@ sed -i '/^default/ d' $TMPFS/etc/passwd
# move /wr and /var to /usr/wr and /usr/var
mv $TMPFS/wr $TMPFS/usr; ln -s usr/wr $TMPFS
mv $TMPFS/var $TMPFS/usr; ln -s usr/var $TMPFS
#
mv ubi commands to /sbin: they are needed for boot time
mv $TMPFS/usr/sbin/ubi* $TMPFS/sbin
# copy /etc to /usr/etc, where it can be edited (boot sequence copies back)
cp -a $TMPFS/etc $TMPFS/usr/etc
......@@ -113,6 +117,10 @@ EOF
fakeroot bash $WRS_SH_OPTIONS $TMPSCRIPT
# finally, create the overall tarball for installation
(cd "$WRS_OUTPUT_DIR/images"; \
tar cf wrs-firmware.tar zImage wrs-initramfs.gz wrs-usr.tar.gz)
if [ -z "$CONFIG_KEEP_ROOTFS" ]; then
rm -rf $TMPFS
rm -rf $TMPSCRIPT
......
#!/bin/sh
#for ttyGS0 console
insmod /lib/modules/2.6.39/kernel/g_serial.ko
rmmod g_serial
insmod /lib/modules/2.6.39/kernel/g_serial.ko
#!/bin/sh
#
# This is the installation script for wr-switch. It is activated by
# a special kernel argument, that reaches user-space environment variables
if [ "x$WRS_IMAGE" = "x" ]; then exit 0; fi
echo 1 > /proc/sys/kernel/printk
# keep /dev/ttyGS0 open, to prevent EOF being seen from the PC
sleep 99999 > /dev/ttyGS0 &
echo "Installation procedure starts" | tee /dev/ttyGS0
sleep 2
echo -n "Flashing kernel to /dev/mtd0 ..." | tee /dev/ttyGS0
nandwrite -m -p -a /dev/mtd0 /flashing/zImage
echo " done" | tee /dev/ttyGS0
# Eth0 is already up, thanks to ip= passed by bootloader
cd /flashing
echo -n "Getting tftp://$SERVERIP/$WRS_IMAGE ..." | tee /dev/ttyGS0
tftp -g -r $WRS_IMAGE -l $WRS_IMAGE $SERVERIP
echo " done" | tee /dev/ttyGS0
echo -n "Mounting target filesystem..." | tee /dev/ttyGS0
mount -t jffs2 /dev/mtdblock1 /mnt
echo " done" | tee /dev/ttyGS0
echo -n "Uncompressing image..." | tee /dev/ttyGS0
cd /mnt; zcat /flashing/wrs-image.tar.gz | tar xf -
echo " done" | tee /dev/ttyGS0
#/bin/sh
reboot
#!/bin/sh
# This is executed as "sysinit" level, before all /etc/init.d/rcS* scripts.
# Warning: this file (and only this one) is executed in initramfs
# *before* /etc is copied from flash, so you can't edit this on
# flash, as it won't work. This can only be modified at build time.
echo "$0: Running"
# This allows me to pass WRS_VERBOSE=y on the command line...
if [ -n "$WRS_VERBOSE" ]; then
set -x
fi
# This used to be S01modules
insmod /lib/modules/2.6.39/kernel/g_serial.ko
rmmod g_serial
insmod /lib/modules/2.6.39/kernel/g_serial.ko
/bin/mkdir -p /dev/pts
/bin/mkdir -p /dev/shm
# See fstab: /dev/pts, /tmp, /sys
/bin/mount -a;
# Allow me to have a shell at this point in time,
# by passing WRS_INTERACTIVE=y in the command line.
#echo "WRS_INTERACTIVE: \"$WRS_INTERACTIVE\""
if [ -n "$WRS_INTERACTIVE" ]; then sh; fi
# At installation time, we have WRS_INSTALLING=y
if [ -n "$WRS_INSTALLING" ]; then install=true; else install=false; fi
# A name that is used several times in this file
WRS_FW="wrs-firmware.tar"
OLD_FW="wrs-firmware-old.tar"
# This helps create the devices that we need over time (and are dynamic)
mkdev_sh () {
f="$1/dev"
name=$(busybox basename $1)
maj=$(busybox awk -F: '{print $1}' $f)
min=$(busybox awk -F: '{print $2}' $f)
rm -f /dev/$name
mknod /dev/$name c $maj $min
}
# Create ubi_ctrl in any case
mkdev_sh "/sys/devices/virtual/misc/ubi_ctrl"
# Installing is like updating, but there are more steps to do initially
if $install; then
# keep /dev/ttyGS0 open, to prevent EOF being seen from the PC
sleep 99999 > /dev/ttyGS0 &
sleep 1; # extra delay, so sleep above opens device before echo below
# format the ubi device and create volumes
echo -n "Formatting UBI device..." | busybox tee /dev/ttyGS0
busybox yes yes | ubiformat /dev/mtd1; # takes 40s
echo " done" | busybox tee /dev/ttyGS0
ubiattach -p /dev/mtd1
mkdev_sh "/sys/devices/virtual/ubi/ubi0"
ubimkvol /dev/ubi0 -s 32MiB -N boot
ubimkvol /dev/ubi0 -s 150MiB -N usr
ubimkvol /dev/ubi0 -s 150MiB -N update
# be able to access them in /dev
mkdev_sh "/sys/devices/virtual/ubi/ubi0/ubi0_0"
mkdev_sh "/sys/devices/virtual/ubi/ubi0/ubi0_1"
mkdev_sh "/sys/devices/virtual/ubi/ubi0/ubi0_2"
# mount the "update" directory, and download stuff in there
mkdir -p /update
mount -t ubifs ubi0:update /update
# Eth0 is already up, thanks to ip= passed by bootloader
cd /update
echo -n "Getting tftp://$SERVERIP/$WRS_FW ..." | busybox tee /dev/ttyGS0
busybox tftp -g -r $WRS_FW -l $WRS_FW $SERVERIP
cd /; umount /update
echo " done" | busybox tee /dev/ttyGS0
fi
# We have volumes, so create their devices
ubiattach -p /dev/mtd1
mkdev_sh "/sys/devices/virtual/ubi/ubi0"
mkdev_sh "/sys/devices/virtual/ubi/ubi0/ubi0_0"
mkdev_sh "/sys/devices/virtual/ubi/ubi0/ubi0_1"
mkdev_sh "/sys/devices/virtual/ubi/ubi0/ubi0_2"
# Now, whether installing or not, mount /update and check what is there
mkdir -p /update
mount -t ubifs ubi0:update /update
if [ -f /update/$WRS_FW ]; then
# FIXME: save configuration somewhere, and recover it later
echo "Extracting filesystem" | busybox tee /dev/ttyGS0
# since we are upgrading, we'd better remove and recreate the volume
ubirmvol /dev/ubi0 --name=usr
ubimkvol /dev/ubi0 -s 150MiB -N usr
# So, it's new: mount and untar
mount -t ubifs ubi0:usr /usr
cd /usr
tar -xOf /update/$WRS_FW wrs-usr.tar.gz | zcat | tar xf -
sync; cd /; umount /usr
echo " done" | busybox tee /dev/ttyGS0
# check if we have an initramfs and/or kernel too
mkdir -p /boot
mount -t ubifs ubi0:boot /boot
# FIXME: should rather check first and save a backup
cd /boot
reboot=false
tar -xf /update/$WRS_FW zImage && reboot=true
tar -xf /update/$WRS_FW wrs-initramfs.gz && reboot=true
# done: rename the firmware file
mv /update/$WRS_FW /update/$OLD_FW; sync
# if this changed kernel or iniramfs, we reboot. Otherwise just proceed.
if $reboot; then
umount /update
reboot
# Init has been notified, but it takes time. Dont proceed this script
sleep 9999
fi
fi
# Here we are: boot normally: /update is muonted: mount /usr, and copy /etc
mount -t ubifs ubi0:usr /usr
rm /etc/init.d/wrs-boot-procedure; # This is us: avoid overwriting an open file
cp -a /usr/etc/* /etc
......@@ -16,9 +16,10 @@
# Startup the system
::sysinit:/bin/mount -t proc proc /proc
#::sysinit:/bin/mount -o remount,rw / # REMOUNT_ROOTFS_RW
::sysinit:/bin/mkdir -p /dev/pts
::sysinit:/bin/mkdir -p /dev/shm
::sysinit:/bin/mount -a
# He re had several "mount" as sysinit actions; coalesce in one command only
::sysinit:/etc/init.d/wrs-boot-procedure
# now run any rc scripts
::sysinit:/etc/init.d/rcS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment