Skip to content

Instantly share code, notes, and snippets.

@NeverBehave
Last active December 3, 2021 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NeverBehave/c18c421ca9671441cb9de60796d19716 to your computer and use it in GitHub Desktop.
Save NeverBehave/c18c421ca9671441cb9de60796d19716 to your computer and use it in GitHub Desktop.
Lenovo IX2 DL
###
# Search for and execute (if found) preimage script.
###
run_preimage_script()
{
preimage_script=/usb_drive/emctools/"$ENV_MODEL"_images/preimage.sh
echo -n "Checking for pre-image script... "
if [ -x $preimage_script ]
then
echo "found."
$preimage_script
return $?
else
echo "none."
return 0
fi
}
###
# Extract a platform imager upgrade file. Validate each invidual image
# via md5 checksum.
###
extract_validate_image()
{
IMAGES="apps config initrd zImage"
USB_IMAGER_IMAGE=/usb_drive/emctools/"$ENV_MODEL"_images/*.tgz
NoExtractionFile=/usb_drive/emctools/"$ENV_MODEL"_images/noextraction
tempFolder=/usb_drive/emctools/"$ENV_MODEL"_images/temp
if [ -f $USB_IMAGER_IMAGE ]
then
echo "Image tar file found: ${USB_IMAGER_IMAGE}"
else
echo "Image tar file not found: ${USB_IMAGER_IMAGE}"
return 1
fi
tmp=`pwd`
# extract
if [ -f $NoExtractionFile ] && [ -d $tempFolder ]
then
echo "No need to extract Image tar file."
cd $tempFolder
else
echo "Extract Image tar file."
mkdir -p $tempFolder
cd $tempFolder
tar -xzvf $USB_IMAGER_IMAGE
fi
# Validate the images
for IMAGE in $IMAGES; do
if [ -f $IMAGE ]
then
local_md5=`md5sum $IMAGE |awk -F ' ' '{print $1}'`
md5_from_tar=`cat $IMAGE".md5"`
if [ "$local_md5" == "$md5_from_tar" ]
then
echo "$IMAGE is valid"
else
if [ -f $IMAGE".md5" ]
then
echo "$IMAGE is not valid"
cd $tmp
rm -fr /usb_drive/emctools/"$ENV_MODEL"_images/temp/
return 3
else
echo "$IMAGE".md5" does not exist. Skip this part."
fi
fi
else
echo "$IMAGE Not found in $USB_IMAGER_IMAGE tar file"
cd $tmp
rm -fr /usb_drive/emctools/"$ENV_MODEL"_images/temp/
return 2
fi
done
cd $tmp
return 0
}
setup_rootfs_to_shutdown()
{
# set up the rootfs just enough to finish the boot
# and shutdown
mkdir /sysroot/bin
cp -r -d /bin/* /sysroot/bin/
mkdir /sysroot/sbin
cp -r -d /sbin/* /sysroot/sbin/
cp -r -d /imager_contents/etc /sysroot/
mkdir -p /sysroot/dev
cp -r -d /dev/* /sysroot/dev/
mkdir -p /sysroot/sys
mkdir -p /sysroot/proc
mkdir -p /sysroot/usr
mkdir -p /sysroot/usr/local
mkdir -p /sysroot/usr/local/cfg/
cp -r -d /imager_contents/initrd_bootstrap.sh /sysroot/usr/local/cfg/
# mount the boot filesystem
mkdir -p sysroot/boot
mkdir -p /sysroot/sysroot
sleep 5
}
enable_network()
{
echo "Enable Network" $1
ethno=$1
ifconfig $ethno up
if [ $? -eq 0 ]
then
sleep 5
udhcpc -t 10 -n -s /etc/network/udhcpc.script -p /var/run/udhcpc.$ethno.pid-i$ethno
sleep 2
fi
ifconfig $ethno
sleep 2
}
###
# Invoke the main USB imaging process.
###
do_usb_imaging()
{
# invoke the actual imager script
/imager_contents/emc_imager.sh usb_imaging $1 $2 $3 $4
setup_rootfs_to_shutdown
echo "Imaging Successful. Please remove the USB drive before the next power on"
}
###
# Normal, platform independent lifeline boot. Mount images
# and set up the rootfs.
###
do_normal_boot()
{
echo "Found Valid EMC Image in disk..."
MNTOPTS=loop
NFSDEBUGMOD=
NFS_SERVER=
NFS_ROOT=/home/soho/soho_root
echo "Mounting apps image..."
mkdir -p sysroot/mnt/apps
if [ "$NFSDEBUGMOD" = "" ]
then
mount -o loop,ro $APPS_IMAGE sysroot/mnt/apps
else
#for NFS debugging
enable_network eth0
echo "mount -t nfs -onolock $NFS_SERVER:$NFS_ROOT sysroot/mnt/apps"
mount -t nfs -onolock $NFS_SERVER:$NFS_ROOT sysroot/mnt/apps
sleep 2
fi
# mount config
echo "Mounting config image..."
losetup /dev/loop1 $CONFIG_IMAGE
# we temporarily symlink /lib and /usr/lib to the apps image, so we can run
# the dynamically linked fsck executable from that location in initrd context
echo "Check config filesystem"
ln -s /sysroot/mnt/apps/lib /lib
mkdir -p /usr
ln -s /sysroot/mnt/apps/usr/lib /usr/lib
e2fsck -y /dev/loop1 > etc/fsck
rm -rf /lib /usr/lib /usr
# mount the writeable image
mkdir -p sysroot/mnt/etc
mount /dev/loop1 sysroot/mnt/etc -o noatime,sync
# mount a unionfs of the RO content and RW image
mkdir -p sysroot/etc
mount -t unionfs none /sysroot/etc -o noatime,sync,dirs=/sysroot/mnt/etc=rw:/sysroot/mnt/apps/etc=ro
# remove old System.map files
rm /sysroot/boot/System.map-*
# copy the System.map file to /boot
echo "Copying System.map..."
SYSTEM_MAP_SRC_NAME="/sysroot/mnt/apps/var/System.map-*"
SYSTEM_MAP_DEST_NAME="/sysroot/boot/"
if [ -f $SYSTEM_MAP_SRC_NAME ]; then
cp -f $SYSTEM_MAP_SRC_NAME $SYSTEM_MAP_DEST_NAME
fi
# mount the branding image if it exists
if [ -f $OEM_IMAGE ]; then
mkdir -p sysroot/oem
mount -o $MNTOPTS sysroot/boot/images/oem sysroot/oem
fi
}
###
# Update an image in NAND flash. Locate the mtd partition by name,
# erase, and reflash.
###
update_flash_image()
{
# search for the image dev by name
mtdname=`grep $1 /proc/mtd | awk -F : '{ print $1 }'`
if [ ! $mtdname ];
then
echo "No Image"
return
fi
# get the major:minor for this mtd dev
major=`cat /sys/class/mtd/$mtdname/dev | awk -F : '{ print $1 }'`
minor=`cat /sys/class/mtd/$mtdname/dev | awk -F : '{ print $2 }'`
# create the dev node, update the image
mknod /dev/$mtdname c $major $minor
flash_eraseall /dev/$mtdname
nandwrite -p /dev/$mtdname $2
}
###
# Copy images from the USB drive to the image
# location on the device.
###
copy_image()
{
IMAGES_DIR=/sysroot/boot/images
SDKAPPS_DIR=/sysroot/boot/SDKApps
SDKAPPS_SOURCE=/usb_drive/emctools/"$ENV_MODEL"_images/SDKApps
SDK_ETC_DIR=/sysroot/etc
SDK_ETC_SOURCE=/usb_drive/emctools/"$ENV_MODEL"_images/etc
CONFIG_IMAGE=/sysroot/boot/images/config
mkdir $IMAGES_DIR
cp $APPS_UPGRADE_IMAGE $IMAGES_DIR
cp $CONFIG_UPGRADE_IMAGE $IMAGES_DIR
cp $OEM_UPGRADE_IMAGE $IMAGES_DIR
echo "Copied apps config and oem image"
if [ -f $KERNEL_IMAGE ]
then
cp $KERNEL_IMAGE $IMAGES_DIR
fi
if [ -f $RAMDISK_IMAGE ]
then
cp $RAMDISK_IMAGE $IMAGES_DIR
fi
if [ -d "$SDKAPPS_SOURCE" ]
then
#Copy the SDK Apps
mkdir -p $SDKAPPS_DIR
echo "Copying SDK Apps to $SDKAPPS_DIR"
cp -f $SDKAPPS_SOURCE/* $SDKAPPS_DIR
fi
if [ -d "$SDK_ETC_SOURCE" ]
then
#Copy the SDK ETC
losetup /dev/loop1 $CONFIG_IMAGE
mkdir -p $SDK_ETC_DIR
mount /dev/loop1 $SDK_ETC_DIR -o noatime,sync
echo "Copying SDK Etc to $SDK_ETC_DIR"
cp -f $SDK_ETC_SOURCE/* $SDK_ETC_DIR
sleep 4
umount $SDK_ETC_DIR
fi
}
#!/bin/sh
# mount proc & sys
mount -a
# need at most three loop devices
mknod /dev/loop0 b 7 0
mknod /dev/loop1 b 7 1
mknod /dev/loop2 b 7 2
# special device needed by DEPP
mknod /dev/zero c 1 5
# check for "shell" directive from kernel args
# drop to a shell for debugging if present
cmdline=`cat /proc/cmdline`
echo "Looking for shell in cmdline: $cmdline"
shl=`/bin/grep shell /proc/cmdline`
if [ -n "$shl" ];then
/bin/echo "'shell' found in /proc/cmdline"
/bin/sh
fi
# call platform specific script to mount apps / config images
/mount_images.sh
mount_result=$?
# create root directory structure
echo "Constructing root filesystem..."
# link main apps dirs
ln -s /mnt/apps/bin sysroot/bin
ln -s /mnt/apps/lib sysroot/lib
ln -s /mnt/apps/sbin sysroot/sbin
ln -s /mnt/apps/usr sysroot/usr
ln -s /lib sysroot/lib64
# populate ram area
if [ -d /sysroot/mnt/apps/ram ]; then
cp -R /sysroot/mnt/apps/ram /sysroot/
fi
# temp dirs
mkdir -p sysroot/tmp
if [ -d /sysroot/mnt/apps/var ]; then
cp -rf sysroot/mnt/apps/var sysroot/
fi
if [ -d /sysroot/mnt/apps/run ]; then
cp -rf sysroot/mnt/apps/run sysroot/
fi
mkdir -m 755 -p sysroot/var/empty
mkdir -m 755 -p sysroot/var/lib
mkdir -m 755 -p sysroot/var/run
mkdir -m 755 -p sysroot/var/lock
mkdir -m 755 -p sysroot/var/log
mkdir -m 755 -p sysroot/var/spool
mkdir -m 755 -p sysroot/var/tmp
# other misc. dirs
mkdir -p sysroot/proc
mkdir -p sysroot/sys
mkdir -p sysroot/mnt/system
mkdir -p sysroot/home
mkdir -p sysroot/selinux
ln -s /etc/debug sysroot/debug
# pivot to the new root
echo 0x0100 > /proc/sys/kernel/real-root-dev
umount /proc
umount /sys
mkdir sysroot/initrd
pivot_root sysroot sysroot/initrd
# call bootstrap script
echo "Bootstrapping ..."
ln -sf /proc/mounts /etc/mtab
/usr/local/cfg/initrd_bootstrap.sh
mount none / -o remount,size=50M
# If we are in DEPP mode, then we need to shutdown/reboot here
# X86 platforms will use "depp" in kernel cmdline argument
# ARM platforms will use "mount_result" = 3 return value from mount_images script
deppmode=`/bin/grep depp /proc/cmdline`
if [ -n "$deppmode" ] || [ "$mount_result" -eq "3" ];then
echo "DEPP process is complete"
# use this to power down unit
#poweroff -d3 -f
# use this to reboot unit
echo "Rebooting..."
reboot -d3 -f
fi
echo "Initialization complete."
if [ `uname -r` == "3.8.6" ];then
exec /sbin/init
echo "Kernel Panic"
fi
#!/bin/sh
. /common.sh
MD0=/dev/md0
BFDDEV=/dev/md0_vg/BFDlv
NUMDRIVES=0
USB_DEVICE=/dev/sda1
find_sata_drives()
{
DRIVES=
for x in a b c d e f g h i
do
z=`cat /sys/class/block/sd$x\/removable`
if [ "$z" == "0" ]
then
NEW=$x
DRIVES=$DRIVES$NEW
elif [ "$z" == "1" ]
then
USB_DEVICE=sd$x
echo "USB/DOM device is $USB_DEVICE"
else
echo "Drives are sd[$DRIVES]"
break;
fi
done
}
put_standby_mode()
{
# Flush write cache and put drives into standby mode.
# Otherwise there is a potential danger of damaging drives
# becasue the delay between drive down and system down is too short.
find_sata_drives
hdparm -F /dev/sd[$DRIVES]
sleep 3
hdparm -W 0 /dev/sd[$DRIVES]
sync
sleep 3
hdparm -y /dev/sd[$DRIVES]
sleep 5
}
create_fw_env_config()
{
FWENV_CONFIG=/etc/fw_env.config
if [ -f $FWENV_CONFIG ]
then
echo "No need to create fw_env.config"
else
echo "Create fw_env.config in /etc"
if [ "$NUMDRIVES" -eq "0" ]
then
echo "/dev/mtd1 0x0 0x20000 0x20000" > $FWENV_CONFIG
echo "/dev/mtd2 0x0 0x20000 0x20000" >> $FWENV_CONFIG
else
echo "/dev/mtd1 0x0 0x1000 0x1000" > $FWENV_CONFIG
echo "/dev/mtd2 0x0 0x1000 0x1000" >> $FWENV_CONFIG
fi
fi
if [ -d "sysroot/etc" ]
then
FWENV_CONFIG=/sysroot/etc/fw_env.config
if [ -f $FWENV_CONFIG ]
then
echo "No need to create fw_env.config"
else
echo "Create fw_env.config in /etc"
if [ "$NUMDRIVES" -eq "0" ]
then
echo "/dev/mtd1 0x0 0x20000 0x20000" > $FWENV_CONFIG
echo "/dev/mtd2 0x0 0x20000 0x20000" >> $FWENV_CONFIG
else
echo "/dev/mtd1 0x0 0x1000 0x1000" > $FWENV_CONFIG
echo "/dev/mtd2 0x0 0x1000 0x1000" >> $FWENV_CONFIG
fi
fi
fi
}
detect_drives()
{
a=`cat /sys/class/block/sda/removable`
if [ "$a" == "0" ]
then
echo "HDD /dev/sda detected"
DISK1=sda
DISK1_PART1=/dev/sda1
USB_DEVICE=/dev/sdb1
let NUMDRIVES=1
fi
b=`cat /sys/class/block/sdb/removable`
if [ "$b" == "0" ]
then
echo "HDD /dev/sdb detected"
DISK2=sdb
DISK2_PART1=/dev/sdb1
USB_DEVICE=/dev/sdc1
let NUMDRIVES=2
fi
FLASHROOT=`grep mtd5 /proc/mtd | awk -F : '{print $1}'`
if [ $FLASHROOT == "mtd5" ]
then
echo "FLASH based system detected"
let NUMDRIVES=0
fi
create_fw_env_config
fw_printenv mfgmodel | grep 'ix1' > /dev/null
if [ "$?" == "0" ]; then
ENV_MODEL=hm3
else
ENV_MODEL=ix2-ng
fi
echo "Model name is $ENV_MODEL"
}
extract_validate_image_DEPP()
{
IMAGES="apps config oem initrd zImage"
IMAGES_DIR=/sysroot/boot/images
tempFolder=/sysroot/boot/images/temp
DEPP_IMAGER_IMAGE=/sysroot/recovery/*.tgz
SPECIAL_APPS_FILE=/sysroot/boot/images/apps
mkdir -p $IMAGES_DIR
mkdir -p $tempFolder
if [ -f $DEPP_IMAGER_IMAGE ]
then
echo "Image tar file found: ${DEPP_IMAGER_IMAGE}"
else
echo "Image tar file not found: ${DEPP_IMAGER_IMAGE}"
return 1
fi
echo "Extract Image tar file."
cd $tempFolder
tar -xvzf $DEPP_IMAGER_IMAGE
if [ -f $SPECIAL_APPS_FILE ]; then
mv $SPECIAL_APPS_FILE $tempFolder
fi
# Validate the images
for IMAGE in $IMAGES; do
if [ -f $IMAGE ]
then
local_md5=`md5sum $IMAGE |awk -F ' ' '{print $1}'`
md5_from_tar=`cat $IMAGE".md5"`
if [ "$local_md5" == "$md5_from_tar" ]
then
echo "$IMAGE is valid"
else
if [ -f $IMAGE".md5" ]
then
echo "$IMAGE is not valid"
cd /
rm -fr $tempFolder
rm -rf $DEPP_IMAGER_IMAGE
return 3
else
echo "$IMAGE".md5" does not exist. Skip this part."
fi
fi
else
echo "$IMAGE Not found in $USB_IMAGER_IMAGE tar file"
cd /
rm -fr $tempFolder
rm -rf $DEPP_IMAGER_IMAGE
return 2
fi
done
cd /
return 0
}
move_images()
{
IMAGES_DIR=/sysroot/boot/images
APPS_DEPP_IMAGE=/sysroot/boot/images/temp/apps
CONFIG_DEPP_IMAGE=/sysroot/boot/images/temp/config
OEM_DEPP_IMAGE=/sysroot/boot/images/temp/oem
KERNEL_DEPP_IMAGE=/sysroot/boot/images/temp/zImage
RAMDISK_DEPP_IMAGE=/sysroot/boot/images/temp/initrd
RECOVERY_DIR=/sysroot/recovery
mv $APPS_DEPP_IMAGE $IMAGES_DIR
mv $CONFIG_DEPP_IMAGE $IMAGES_DIR
mv $OEM_DEPP_IMAGE $IMAGES_DIR
mv $KERNEL_DEPP_IMAGE $IMAGES_DIR
mv $RAMDISK_DEPP_IMAGE $IMAGES_DIR
echo "Copied apps config oem kernel and initrd image."
echo "Remove temp folder and imager file."
rm -rf $IMAGES_DIR/temp
rm -rf $RECOVERY_DIR/*.tgz
}
do_network_imaging()
{
echo "Going in to Network Imaging Mode"
umount /dev/md0
umount /usb_drive
umount /sysroot/boot
# If we need 75% of ram to fit DEPP images
#mount -t tmpfs -o remount,size=75% none /sysroot
enable_network eth0
mkdir -p /sysroot/boot
mknod /dev/zero c 1 5
# make ramdisk location for DEPP files
mkdir -p /sysroot/recovery
cd /sysroot/recovery
create_fw_env_config
serialNum=0
serialNum=`fw_printenv|grep serialno|awk -F "=" {'print $2'}`
# if serail number from uboot serialno does not exist, then return mac address
if [ "$serialNum" == "" ]
then
mac=`ifconfig|grep eth0|awk {'print $5'}`
echo "mac address is $mac"
serialNum=`echo $mac|awk -F : {'print $1$2$3$4$5$6'}`
fi
# parameter should be the same as in the firmware.xml
deppResult=0
if [ "$NUMDRIVES" -eq "0" ]
then
/usr/bin/recovery "$ENV_MODEL" "$serialNum" "nand_diskless"
else
/usr/bin/recovery "$ENV_MODEL" "$serialNum"
fi
deppResult=$?
cd /
if [ "$deppResult" == "0" ]
then
echo "The DEPP image copy was successful."
if [ "$NUMDRIVES" -eq "0" ]
then
extract_validate_image_DEPP
validate_image=$?
if [ "$validate_image" -eq "0" ]
then
move_images
KERNEL_IMAGE=/sysroot/boot/images/zImage
RAMDISK_IMAGE=/sysroot/boot/images/initrd
if [ -f $RAMDISK_IMAGE ]
then
echo "Updating ramdisk Image"
update_flash_image initrd $RAMDISK_IMAGE
else
echo "The initrd image update was not successful."
/usr/bin/status_led_DEEP.sh err
fi
if [ -f $KERNEL_IMAGE ]
then
echo "Updating kernel image"
x=`cat /proc/mtd | grep zImage | awk -F "\"" '{print $2}'`
if [ "$x" == "zImage" ]
then
echo "This MTD table has zImage."
kernelName=zImage
else
echo "This MTD table has uImage."
kernelName=uImage
fi
update_flash_image $kernelName $KERNEL_IMAGE
else
echo "The kernel image update was not successful."
/usr/bin/status_led_DEEP.sh err
fi
else
echo "DEPP images are not valid."
/usr/bin/status_led_DEEP.sh err
fi
umount /sysroot/boot
fi
else
echo "The DEPP image copy was not successful."
echo "Reboot the system."
/usr/bin/status_led_DEEP.sh err
fi
rm -fr /sysroot/boot/imaging_dir
sleep 5
mkdir /sysroot/bin
cp -r -d /bin/* /sysroot/bin/
mkdir /sysroot/sbin
cp -r -d /sbin/* /sysroot/sbin/
cp -r -d /imager_contents/etc /sysroot/
rm -f /sysroot/etc/init.d/S*
cp -r -d /imager_contents/nw/S* /sysroot/etc/init.d/
mkdir -p /sysroot/dev
cp -r -d /dev/* /sysroot/dev/
mkdir -p /sysroot/sys
mkdir -p /sysroot/proc
mkdir -p /sysroot/usr
mkdir -p /sysroot/usr/local
mkdir -p /sysroot/usr/local/cfg/
cp -r -d /imager_contents/initrd_bootstrap.sh /sysroot/usr/local/cfg/
mkdir -p /sysroot/sysroot
}
APPS_UPGRADE_IMAGE=/usb_drive/emctools/"$ENV_MODEL"_images/apps
CONFIG_UPGRADE_IMAGE=/usb_drive/emctools/"$ENV_MODEL"_images/config
APPS_IMAGE=sysroot/boot/images/apps
CONFIG_IMAGE=sysroot/boot/images/config
OEM_IMAGE=sysroot/boot/images/oem
APPS_IMAGE_TEMP_UPGRADE=sysroot/mnt/boot/images/apps.upgrade
mknod /dev/sda b 8 0
mknod /dev/sda1 b 8 1
mknod /dev/sdb b 8 16
mknod /dev/sdb1 b 8 17
mknod /dev/sdc b 8 32
mknod /dev/sdc1 b 8 33
mknod /dev/md0 b 9 0
mknod /dev/md1 b 9 1
echo "Make node for mtd devices"
mknod /dev/mtd0 c 90 0
mknod /dev/mtd1 c 90 2
mknod /dev/mtd2 c 90 4
mknod /dev/mtd3 c 90 6
mknod /dev/mtd4 c 90 8
mknod /dev/mtd5 c 90 10
detect_drives
if [ "$NUMDRIVES" -eq "0" ]; then
ubictl_major=`cat /proc/devices | grep "misc" | awk '{ print $1 }'`
ubictl_minor=`cat /proc/misc | grep "ubi_ctrl"| awk '{ print $1 }'`
mknod /dev/ubi_ctrl c $ubictl_major $ubictl_minor
mknod /dev/ubi0 c 252 0
ubiattach /dev/ubi_ctrl -m 5
fi
VALID_DISK1=
VALID_DISK2=
UUID_1=`mdadm -E --brief $DISK1_PART1 | awk -F "UUID" '{print $2}' | awk -F "=" '{print $2}' | awk -F " " '{print $1}'`
PART1=`echo $DISK1_PART1 | awk -F "/" '{print $3}'`
SDA1_SIZE=`cat /sys/class/block/$DISK1/$PART1/size`
if [ -n "$UUID_1" ]
then
if [ "$SDA1_SIZE" -gt "41800000" -a "$SDA1_SIZE" -lt "42000000" ]; then
echo "UUID_1 = $UUID_1, size = $SDA1_SIZE"
VALID_DISK1=$DISK1_PART1
fi
fi
UUID_2=`mdadm -E --brief $DISK2_PART1 | awk -F "UUID" '{print $2}' | awk -F "=" '{print $2}' | awk -F " " '{print $1}'`
PART2=`echo $DISK2_PART1 | awk -F "/" '{print $3}'`
SDB1_SIZE=`cat /sys/class/block/$DISK2/$PART2/size`
if [ -n "$UUID_2" ]
then
if [ "$SDB1_SIZE" -gt "41800000" -a "$SDB1_SIZE" -lt "42000000" ]; then
echo "UUID_2 = $UUID_2, size = $SDB1_SIZE"
VALID_DISK2=$DISK2_PART1
fi
fi
echo "Valid Disk 1 in md0: $VALID_DISK1"
echo "Valid Disk 2 in md0: $VALID_DISK2"
echo "USB Device node is $USB_DEVICE"
echo "Checking to see the if the reset button is pressed or not"
RESET_BUTTON_FILE=/usr/bin/resetbuttonpressed
/usr/bin/resetbuttonmon
cat /proc/cmdline | grep bootmode
USB_RECOVERY_MODE=$?
# if reset button is pressed do usb imaging if no usb do network imaging
# else if reset button is not pressed then look for valid image in harddrive and
# if not do usb imaging and if no usb drive do network imaging
if [ -f $RESET_BUTTON_FILE ] || [ $USB_RECOVERY_MODE == "0" ]
then
# reset button was pressed
rm -f $RESET_BUTTON_FILE
echo "Checking if there is an attached EMC Imager"
sleep 10
mkdir -p /usb_drive
mount $USB_DEVICE /usb_drive -t vfat -o async,rw,fmask=0000,dmask=0000,iocharset=utf8
mount_ret=$?
scriptret=0
if [ $mount_ret -eq 0 ]
then
# Flash the system status LED to indicate USB imaging.
echo 2 > /sys/class/nasled/pwr_white_led
run_preimage_script
scriptret=$?
extract_validate_image
validate_image=$?
fi
if [ "$scriptret" -eq "0" ]
then
if [ "$validate_image" -eq "0" ] && [ "$mount_ret" -eq "0" ]
then
echo "Found EMC Imager with apps and config image..."
do_usb_imaging $ENV_MODEL $NUMDRIVES $VALID_DISK1 $VALID_DISK2
umount $USB_DEVICE
put_standby_mode
poweroff -f
else
# Do network DEPP imaging.
do_network_imaging
exit 3
fi
else
echo "Setting rootfs to go to shutdown mode"
setup_rootfs_to_shutdown
fi
else
# reset button was not pressed
echo "Checking for valid image on system"
mkdir -p sysroot/boot
if [ "$NUMDRIVES" -eq "0" ]
then
# mount NAND ubifs on /boot
mount -t ubifs ubi0:boot sysroot/boot -o noatime
# Assemble BFDlv and mount it /mnt/boot/images for UI upgrade.
mdadm --stop /dev/md0
mdadm --assemble /dev/md0 --force $VALID_DISK1 $VALID_DISK2 --run
vgchange -ay
mkdir -p sysroot/mnt/boot
echo "Mount BFDlv to /mnt/boot on ix2-ng NAND"
e2fsck -yv $BFDDEV
mount $BFDDEV sysroot/mnt/boot -o noatime
# If apps.upgrade exists, try to mount it to see if this apps image is good.
# If it is good, replace the current apps with apps.upgrade
# If it is bad, just use the current apps in NAND.
if [ $? -eq 0 ] && [ -f $APPS_IMAGE_TEMP_UPGRADE ]
then
mkdir -p sysroot/mnt/boot/apps
mount -o loop,ro $APPS_IMAGE_TEMP_UPGRADE sysroot/mnt/boot/apps
if [ $? -eq 0 ]
then
umount sysroot/mnt/boot/apps
# apps.upgrade will be deleted by Lifeline executord later.
cp -f $APPS_IMAGE_TEMP_UPGRADE $APPS_IMAGE
sync
sleep 3
fi
else
mkdir -p sysroot/mnt/boot/images
fi
mount sysroot/boot -o remount,noatime,sync
else
mdadm --assemble /dev/md0 --force $VALID_DISK1 $VALID_DISK2 --run
linear=`mdadm --detail /dev/md0 | grep linear`
if [ "$linear" == "" ] || [ "$ENV_MODEL" == "hm3" ]
then
mdadm --stop /dev/md0
mdadm --assemble /dev/md0 --force $VALID_DISK1 $VALID_DISK2 --run
vgchange -ay
e2fsck -yv $BFDDEV
mount $BFDDEV sysroot/boot -o noatime,sync
else
echo "Found linear md0"
if [ "$VALID_DISK2" -eq "" ]
then
SECOND_DISK="missing"
else
SECOND_DISK="$VALID_DISK2"
fi
vgchange -an
mdadm --stop /dev/md0
mdadm --create --force --run --metadata=0.90 --level=raid1 --raid-devices=2 /dev/md0 $VALID_DISK1 $SECOND_DISK
ret=$?
if [ "$ret" == "0" ]
then
sleep 2
SYS_UUID=`mdadm -E --brief $DISK1_PART1 | awk -F "=" '{print $2}'`
vgchange -ay
e2fsck -yv $BFDDEV
mount $BFDDEV sysroot/boot -o noatime,sync
echo "Writing convertedmd0"
echo "$SYS_UUID" > /sysroot/boot/convertedmd0
else
echo "Create of raid1 md0 failed" " $ret"
mdadm --assemble /dev/md0 --force $VALID_DISK1 $VALID_DISK2 --run
vgchange -ay
e2fsck -yv $BFDDEV
mount $BFDDEV sysroot/boot -o noatime,sync
fi
fi
fi
if [ -f $APPS_IMAGE ] && [ -f $CONFIG_IMAGE ]
then
echo "Copy dev node to /sysroot/dev"
mkdir -p /sysroot/dev
cp -r -d /dev/* /sysroot/dev/
# normal boot
do_normal_boot
create_fw_env_config
if [ -f $APPS_IMAGE_TEMP_UPGRADE ]
then
echo "Clean up the memory for ix2-ng NAND after UI upgrade."
sync
sleep 1
echo 3 > /proc/sys/vm/drop_caches
fi
else
umount /sysroot/boot
echo "Checking if there is an attached EMC Imager"
sleep 10
mkdir -p /usb_drive
mount $USB_DEVICE /usb_drive -t vfat -o async,rw,fmask=0000,dmask=0000,iocharset=utf8
mount_ret=$?
if [ $mount_ret -eq 0 ]
then
# Flash the system status LED to indicate USB imaging.
echo 2 > /sys/class/nasled/pwr_white_led
run_preimage_script
extract_validate_image
validate_image=$?
fi
if [ "$validate_image" -eq "0" ] && [ "$mount_ret" -eq "0" ]
then
echo "Found EMC Imager with apps and config image..."
do_usb_imaging $ENV_MODEL $NUMDRIVES $VALID_DISK1 $VALID_DISK2
umount $USB_DEVICE
put_standby_mode
poweroff -f
else
echo "No USB Imager and No valid image on system"
do_network_imaging
exit 3
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment