Legacy PPC Installer

This commit is contained in:
Jeffrey Townsend
2015-12-11 22:32:34 +00:00
parent 4f75550cfe
commit ff24552def
7 changed files with 501 additions and 0 deletions

View File

@@ -0,0 +1 @@
include $(ONL)/make/pkg.mk

View File

@@ -0,0 +1,2 @@
!include $ONL/builds/any/installer/legacy/APKG.yml ARCH=powerpc

View File

@@ -0,0 +1 @@
*INSTALLER

View File

@@ -0,0 +1,35 @@
include $(ONL)/make/config.powerpc.mk
# Hardcoded to match ONL File naming conventions.
include $(ONL)/make/version-onl.mk
INSTALLER_NAME=$(FNAME_PRODUCT_VERSION)_ONL-OS_$(FNAME_BUILD_ID)_$(UARCH)_INSTALLER
FIT_IMAGE_ALL := $(shell $(ONLPM) --find-file onl-loader-fit:powerpc onl-loader-fit.itb)
# Fixme -- should come from the FIT manifest, not the initrd manifest
PLATFORMS := $(shell $(ONLPM) --platform-manifest onl-loader-initrd:powerpc)
MKSHAR = $(ONL)/tools/mkshar
MKSHAR_OPTS = --lazy --unzip-pad
MKSHAR_PERMS = autoperms.sh
__installer:
$(ONL_V_at)rm -rf *INSTALLER* *.md5sum
$(ONL_V_at)cp $(FIT_IMAGE_ALL) .
$(foreach p,$(PLATFORMS), $(ONLPM) --extract-dir onl-platform-config-$(p):powerpc .;)
# Fixme
$(ONLPM) --extract-dir onl-swi:powerpc .
mv ./usr/share/onl/packages/powerpc/onl-swi/*.swi .
rm -rf ./usr
$(ONL_V_at)cp /dev/null $(MKSHAR_PERMS)
$(ONL_V_at) cp $(ONL)/make/version-onl.sh .
$(ONL_V_at)echo "#!/bin/sh" >> $(MKSHAR_PERMS)
$(ONL_V_at)echo "set -e" >> $(MKSHAR_PERMS)
$(ONL_V_at)echo "set -x" >> $(MKSHAR_PERMS)
$(MKSHAR) $(MKSHAR_OPTS) "$(INSTALLER_NAME)" $(ONL)/tools/scripts/sfx.sh.in ppc-installer.sh ppc-install-lib *.itb lib *.swi version-onl.sh boot-config
$(ONL_V_at)rm -rf ./lib *.swi version-onl.sh autoperms.sh *.itb
md5sum "$(INSTALLER_NAME)" | awk '{ print $$1 }' > "$(INSTALLER_NAME).md5sum"
shar installer: __installer

View File

@@ -0,0 +1,4 @@
NETDEV=ma1
NETAUTO=dhcp
BOOTMODE=SWI
SWI=flash2::latest

View File

@@ -0,0 +1,357 @@
######################################################################
#
# lib.sh
#
# Common files for install/recovery
#
######################################################################
############################################################
#
# Installation Utility Functions
#
############################################################
case "`/usr/sbin/fw_setenv --help 2>&1`" in
*"-f"*"Force update"*)
fw_setenv_dash_f="-f"
;;
esac
fw_setenv_f_s() {
local f
f=$1; shift
/usr/sbin/fw_setenv ${fw_setenv_dash_f} -s "$f"
}
############################################################
#
# installer_create_device_file <blockdev> <partno>
# <blockdev> The block device name
# <partno> The partition number.
#
# Set the global variable 'installer_df' with the name of
# the created device file.
#
# We can't always rely on the existance of a partition's
# device file after the device has been formatted.
#
# This function creates the appropriate device file
# for a given block partition to avoid this problem.
#
#
installer_create_device_file() {
local blockdev=$1
local partno=$2
# Determine the device major number for the given block device:
local major=`ls -l /dev/${blockdev} | tr "," " " | awk '{print $5}'`
# Create a new device file matching the given partition
installer_df=$(mktemp)
rm ${installer_df}
mknod "${installer_df}" b "${major}" "${partno}"
}
############################################################
#
# installer_partition_cp <blockdev> <partno> <src> <dst>
#
# <blockdev> The block device name
# <partno> The partition number
# <src> The local source filename
# <dst> The destination filename
#
# Copy the source file to the given partition.
# The partition must be formatted/mountable.
#
############################################################
installer_partition_cp() {
local blockdev=$1
local partno=$2
local src=$3
local dst=$4
installer_create_device_file ${blockdev} ${partno}
mkdir -p "${installer_df}.mount"
mount "${installer_df}" "${installer_df}.mount"
cp "${src}" "${installer_df}.mount/${dst}"
umount "${installer_df}.mount"
rm "${installer_df}"
rmdir "${installer_df}.mount"
}
############################################################
#
# installer_partition_dd <blockdev> <partno> <src>
#
# <blockdev> The block device name
# <partno> The partition number.
# <src> The source file.
#
# 'dd' the contents of the src file directly to the given partition.
#
############################################################
installer_partition_dd() {
local blockdev=$1
local partno=$2
local src=$3
# installer_partition_dd <blockdev> <partno> <src>
installer_create_device_file ${blockdev} ${partno}
dd if=${src} of="${installer_df}" bs=1024
rm "${installer_df}"
}
############################################################
#
# installer_partition_format <blockdev> <partno> <mkfs>
#
# <blockdev> The block device name.
# <partno> The partition number.
# <mkfs> The formatting tool.
#
############################################################
installer_partition_format() {
local blockdev=$1
local partno=$2
local mkfs=$3
local partition="$1$2"
installer_say "Format ${partition}..."
installer_create_device_file ${blockdev} ${partno}
"${mkfs}" "${installer_df}"
installer_say "Format ${partition} complete."
rm "${installer_df}"
}
############################################################
#
# installer_umount_blockdev <blockdev>
#
# <blockdev> The block device name.
#
# Unmount all partitions of the given blockdevice.
#
# Required to avoid errors when repartitioning block
# devices that are currently mounted.
#
############################################################
installer_umount_blockdev() {
local blockdev=$1
local mounts=`cat /proc/mounts | grep ${blockdev} | awk '{print $2}'`
if [ "$mounts" ]; then
umount $mounts || :
fi
}
############################################################
#
# installer_blockdev_format <blockdev> <p1size> <p2size> <p3size>
#
# <blockdev> The block device name.
# <p1size> The size of the first partition.
# <p2size> The size of the second partition.
# <p3size> [Optional] The size of the third partition.
# If p3size is unset, the remainder of the device will be used
# for the third partition.
#
############################################################
installer_blockdev_format() {
local blockdev=$1
local partition1size=$2
local partition2size=$3
local partition3size=$4
installer_umount_blockdev ${blockdev}
installer_say "Formatting ${blockdev} as ${partition1size}:${partition2size}:${partition3size}."
echo -e "o\nn\np\n1\n\n+${partition1size}\nn\np\n2\n\n+${partition2size}\nn\np\n3\n\n${partition3size}\np\nw\n" | fdisk /dev/${blockdev}
installer_partition_format ${blockdev} 1 mkdosfs
installer_partition_format ${blockdev} 2 mkdosfs
installer_partition_format ${blockdev} 3 mkdosfs
}
############################################################
#
# installer_platform_loader <blockdev> <partno>
#
# <blockdev> The block device name.
# <partno> The partition number.
#
# Install the platform loader to the given partition.
#
# The default is to copy the loader to the partition's filesystem.
# If 'platform_loader_raw' is specified by the platform, the
# loader will be written directly to the partition instead.
#
############################################################
installer_platform_loader() {
local blockdev=$1
local partno=$2
if [ -f "${installer_dir}/${installer_platform}.itb" ]; then
# Platform-specfic FIT Image
local loader="${installer_dir}/${installer_platform}.itb"
elif [ -f "${installer_dir}/onl-loader-fit.itb" ]; then
# Common FIT Image
local loader="${installer_dir}/onl-loader-fit.itb";
elif [ "${platform_loader}" ]; then
# Platform specific override
local loader="${platform_loader}"
else
# Default platform loader
local loader="${installer_dir}/switchlight.${installer_platform}.loader"
fi
if [ "${platform_loader_dst_name}" ]; then
local loaderdst="${platform_loader_dst_name}"
else
local loaderdst="switchlight-loader"
fi
if [ -f "${loader}" ]; then
installer_say "Installing the Switchlight Loader..."
if [ "${platform_loader_raw}" ]; then
installer_partition_dd ${blockdev} ${partno} ${loader}
else
installer_partition_cp ${blockdev} ${partno} ${loader} ${loaderdst}
fi
else
installer_say "The platform loader file is missing. This is unexpected - ${loader}"
exit 1
fi
}
############################################################
#
# installer_platform_bootconfig <blockdev> <partno>
#
# <blockdev> The block device name.
# <partno> The partition number.
#
# Generate and write the platform boot-config file
# into the given partition.
#
############################################################
installer_platform_bootconfig() {
local blockdev=$1
local partno=$2
#
# Is there a static boot-config in the installer package?
#
if [ -f "${installer_dir}/boot-config" ]; then
installer_say "Writing boot-config."
installer_partition_cp ${blockdev} ${partno} "${installer_dir}/boot-config"
fi
#
# Unless the installer contains a boot-config
# file it will have to be generated by the first-boot
# script in the Loader.
#
}
############################################################
#
# installer_platform_swi <blockdev> <partno>
#
# <blockdev> The block device name.
# <partno> The partition number.
#
# Install the SWI to the given partition.
#
############################################################
installer_platform_swi() {
local blockdev=$1
local partno=$2
SWISRC=`ls ${installer_dir}/*.swi`
if [ -f "${SWISRC}" ]; then
if [ ! ${SWIDST} ]; then
SWIDST="$(basename ${SWISRC})"
fi
installer_say "Installing SwitchLight Software Image (${SWIDST})..."
installer_partition_cp ${blockdev} ${partno} ${SWISRC} ${SWIDST}
else
installer_say "No SwitchLight Software Image available for installation. Post-install ZTN installation will be required."
fi
}
############################################################
#
# installer_standard_blockdev_install <blockdev> <p1size> <p2size> <p3size>
#
# <blockdev> The block device name.
# <p1size> The size of the loader partition.
# <p2size> The size of the /mnt/flash partition.
# <p3size> The size of the /mnt/flash2 partition.
#
# Performs a standard installation for the platform.
# Most platform installers will just call this function with the appropriate arguments.
#
############################################################
installer_standard_blockdev_install () {
local blockdev=$1
local p1size=$2
local p2size=$3
local p3size=$4
# Standard 3-partition format for loader, /mnt/flash, and /mnt/flash2
installer_blockdev_format "${blockdev}" "${p1size}" "${p2size}" "${p3size}"
# Copy the platform loader to the first partition.
installer_platform_loader "${blockdev}" 1
# Set the boot-config file
installer_platform_bootconfig "${blockdev}" 2
# Copy the packaged SWI to the third partition.
installer_platform_swi "${blockdev}" 3
sync
installer_umount_blockdev "${blockdev}"
}
############################################################
#
# installer_standard_blockdev_install <blockdev> <p1size> <p2size> <p3size>
#
# <blockdev> The block device name.
#
# Performs a standard recovery for the platform.
#
############################################################
installer_standard_blockdev_recovery() {
local blockdev=$1
# Standard 3-partition format for loader, /mnt/flash, and /mnt/flash2
installer_umount_blockdev ${blockdev}
installer_say "Re-formatting ${blockdev}."
installer_partition_format ${blockdev} 2 mkdosfs
installer_partition_format ${blockdev} 3 mkdosfs
sync
installer_umount_blockdev "${blockdev}"
}
##############################
#
# End of lib.sh
#
##############################

View File

@@ -0,0 +1,101 @@
#!/bin/sh
IARCH="ppc"
ARCH=`uname -m`
if [ "$ARCH" != "$IARCH" ]; then
echo
echo "------------------------------------"
echo "Installer Architecture: $IARCH"
echo "Target Architecture: $ARCH"
echo
echo "This installer cannot be used on this"
echo "target."
echo
echo "------------------------------------"
sleep 5
exit 1
fi
set -e
cd $(dirname $0)
installer_script=${0##*/}
installer_zip=$1
if [ -f /etc/machine.conf ]; then
. /etc/machine.conf
# Running under ONIE, most likely in the background in installer mode.
# Our messages have to be sent to the console directly, not to stdout.
installer_say() {
echo "$@" > /dev/console
}
# Installation failure message.
trap 'installer_say "Install failed.; cat /var/log/onie.log > /dev/console; installer_say "Install failed. See log messages above for details"; sleep 3; reboot' EXIT
if [ -z "${installer_platform}" ]; then
# Our platform identifiers are equal to the ONIE platform identifiers without underscores:
installer_platform=`echo ${onie_platform} | tr "_" "-"`
installer_arch=${onie_arch}
fi
fi
#
# Remount tmpfs larger if possible.
# We will be doing all of our work out of /tmp
#
mount -o remount,size=1024M /tmp || true
# Unpack our distribution
installer_say "Unpacking SwitchLight installer files..."
installer_dir=`pwd`
if test "$SFX_PAD"; then
# ha ha, busybox cannot exclude multiple files
unzip $installer_zip -x $SFX_PAD
elif test "$SFX_UNZIP"; then
unzip $installer_zip -x $installer_script
else
dd if=$installer_zip bs=$SFX_BLOCKSIZE skip=$SFX_BLOCKS \
| unzip - -x $installer_script
fi
if [ -f "${installer_dir}/versions.sh" ]; then
. "${installer_dir}/versions.sh"
installer_say "${VERSION_STRING} Installer"
fi
installer_say "Detected platform: ${installer_platform}"
. "${installer_dir}/ppc-install-lib"
# Look for the platform installer directory.
installer_platform_dir="${installer_dir}/lib/platform-config/${installer_platform}"
if [ -d "${installer_platform_dir}" ]; then
# Source the installer scriptlet
. "${installer_platform_dir}/onl/install/${installer_platform}.sh"
else
installer_say "This installer does not support the ${installer_platform} platform."
installer_say "Available platforms are:"
list=`ls ${installer_dir}/lib/platform-config`
installer_say "${list}"
installer_say "Installation cannot continue."
exit 1
fi
# The platform script must provide this function. This performs the actual install for the platform.
platform_installer
installer_say "Setting ONIE nos_bootcmd to boot Switch Light"
envf=/tmp/.env
cp /dev/null "${envf}"
echo "nos_bootcmd ${platform_bootcmd}" >> "${envf}"
installer_say "Install finished. Rebooting to Switch Light."
sleep 3
reboot
exit
# Do not add any additional whitespace after this point.
PAYLOAD_FOLLOWS