2016-07-26 14:01:58 -05:00
|
|
|
#!/bin/sh
|
2016-03-16 01:38:26 -05:00
|
|
|
# Copyright (C) 2016 Arista Networks, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# Aboot stage 0 boot
|
|
|
|
|
|
|
|
set -x
|
|
|
|
|
2017-02-01 15:02:29 -06:00
|
|
|
kernel=boot/vmlinuz-3.16.0-4-amd64
|
|
|
|
initrd=boot/initrd.img-3.16.0-4-amd64
|
|
|
|
kernel_params=kernel-params
|
|
|
|
|
|
|
|
aboot_machine="arista_unknown"
|
|
|
|
|
2017-05-01 17:16:33 -05:00
|
|
|
[ -z "$target_path" ] && target_path=/mnt/flash
|
2017-04-21 19:23:36 -05:00
|
|
|
image_path="$target_path/image-%%IMAGE_VERSION%%"
|
2017-02-01 15:02:29 -06:00
|
|
|
|
|
|
|
# expect the swi to be a non empty file
|
|
|
|
[ -s "$swipath" ] || exit 1
|
|
|
|
|
2016-03-16 01:38:26 -05:00
|
|
|
bootconfigvars="SWI SWI_COPY POST_LEVEL CONSOLESPEED PASSWORD NETDEV NETAUTO NETIP NETMASK NETGW NETDOMAIN NETDNS NETHW memtest"
|
|
|
|
|
2017-02-01 15:02:29 -06:00
|
|
|
parse_environment_config() {
|
2016-03-16 01:38:26 -05:00
|
|
|
for n in ${bootconfigvars}; do
|
|
|
|
eval v="\$$n"
|
|
|
|
if [ "$v" ]; then
|
|
|
|
echo "$n=$v"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-05-01 17:16:33 -05:00
|
|
|
clean_flash() {
|
2017-04-01 01:51:59 -05:00
|
|
|
## Remove all the other unnecssary files except swi file, boot-config
|
|
|
|
for f in $(ls -A $target_path); do
|
2017-06-02 03:31:53 -05:00
|
|
|
if [ $f != "${swipath##*/}" ] &&
|
|
|
|
[ $f != "boot-config" ] &&
|
|
|
|
[ $f != "minigraph.xml" ]
|
|
|
|
then
|
2017-04-01 01:51:59 -05:00
|
|
|
rm -rf "$target_path/$f"
|
|
|
|
fi
|
|
|
|
done
|
2017-05-01 17:16:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
extract_image() {
|
2017-02-05 17:59:59 -06:00
|
|
|
|
2017-05-01 17:16:33 -05:00
|
|
|
mkdir -p "$image_path"
|
2017-04-21 19:23:36 -05:00
|
|
|
|
2017-06-06 12:41:06 -05:00
|
|
|
## Unzip the image except boot0 and dockerfs archive
|
|
|
|
unzip -oq "$swipath" -x boot0 {{ FILESYSTEM_DOCKERFS }} -d "$image_path"
|
2017-02-05 00:32:45 -06:00
|
|
|
|
2017-02-06 00:11:52 -06:00
|
|
|
## detect rootfs type
|
2017-05-01 17:16:33 -05:00
|
|
|
rootfs_type=`grep " $target_path " /proc/mounts | cut -d' ' -f3`
|
2017-02-06 00:11:52 -06:00
|
|
|
|
|
|
|
## vfat does not support symbol link
|
2017-05-01 17:16:33 -05:00
|
|
|
if [ -n "$sonic_upgrade" ] || [ "$rootfs_type" != "vfat" ]; then
|
2017-04-21 19:23:36 -05:00
|
|
|
mkdir -p "$image_path/{{ DOCKERFS_DIR }}"
|
2017-02-06 10:17:16 -06:00
|
|
|
|
2017-05-31 21:27:47 -05:00
|
|
|
if [ -n "$sonic_upgrade" ]; then
|
|
|
|
TAR_EXTRA_OPTION="--numeric-owner"
|
|
|
|
fi
|
|
|
|
|
2017-02-06 10:17:16 -06:00
|
|
|
## extract docker archive
|
2017-06-06 12:41:06 -05:00
|
|
|
unzip -oqp "$swipath" {{ FILESYSTEM_DOCKERFS }} | tar xzf - -C "$image_path/{{ DOCKERFS_DIR }}" $TAR_EXTRA_OPTION
|
2017-02-06 00:11:52 -06:00
|
|
|
else
|
2017-06-06 12:41:06 -05:00
|
|
|
## save dockerfs archive in the image directory
|
|
|
|
unzip -oq "$swipath" {{ FILESYSTEM_DOCKERFS }} -d "$image_path"
|
2017-05-01 17:16:33 -05:00
|
|
|
echo "$target_path is $rootfs_type, extract {{ FILESYSTEM_DOCKERFS }} in later stage"
|
2017-02-06 00:11:52 -06:00
|
|
|
fi
|
2017-02-05 17:59:59 -06:00
|
|
|
|
2017-04-21 19:23:36 -05:00
|
|
|
## use new reduced-size boot swi
|
|
|
|
echo "SWI=flash:image-%%IMAGE_VERSION%%/{{ ABOOT_BOOT_IMAGE }}" > "$target_path/boot-config"
|
|
|
|
|
2017-06-06 12:41:06 -05:00
|
|
|
## Remove installer swi as it has lots of redundunt contents
|
|
|
|
rm -f "$swipath"
|
|
|
|
|
2017-02-17 00:10:29 -06:00
|
|
|
## sync disk operations
|
|
|
|
sync
|
2017-02-01 15:02:29 -06:00
|
|
|
}
|
2016-07-26 14:01:58 -05:00
|
|
|
|
2017-02-01 15:02:29 -06:00
|
|
|
write_machine_config() {
|
2016-07-26 14:01:58 -05:00
|
|
|
## Detect SKU and create a hardware description file
|
2017-02-01 15:02:29 -06:00
|
|
|
aboot_version=$(grep ^Aboot /etc/cmdline | sed 's/^.*norcal.-//')
|
|
|
|
aboot_build_date=$(stat -c %y /bin/sysinit | sed 's/ /T/')
|
|
|
|
cat <<EOF > ${target_path}/machine.conf
|
2016-07-26 14:01:58 -05:00
|
|
|
aboot_version=$aboot_version
|
|
|
|
aboot_vendor=arista
|
|
|
|
aboot_platform=x86_64-$aboot_machine
|
|
|
|
aboot_machine=$aboot_machine
|
|
|
|
aboot_arch=x86_64
|
|
|
|
aboot_build_date=$aboot_build_date
|
|
|
|
EOF
|
2017-02-01 15:02:29 -06:00
|
|
|
}
|
2016-07-26 14:01:58 -05:00
|
|
|
|
2017-02-01 15:02:29 -06:00
|
|
|
platform_specific() {
|
|
|
|
local platform="$(grep -Eo 'platform=[^ ]+' /etc/cmdline | cut -f2 -d=)"
|
2017-02-03 18:32:42 -06:00
|
|
|
local sid="$(grep -Eo 'sid=[^ ]+' /etc/cmdline | cut -f2 -d=)"
|
2017-06-02 03:31:53 -05:00
|
|
|
|
|
|
|
# set varlog size to 100MB
|
2017-08-05 22:56:32 -05:00
|
|
|
local varlog_size=100
|
2017-06-02 03:31:53 -05:00
|
|
|
|
2017-11-22 04:58:20 -06:00
|
|
|
local flash_size=$(($(df | grep flash | tr -s ' ' | cut -f2 -d' ') / 1000))
|
|
|
|
|
2017-02-01 15:02:29 -06:00
|
|
|
if [ "$platform" = "raven" ]; then
|
|
|
|
aboot_machine=arista_7050_qx32
|
2017-11-22 04:58:20 -06:00
|
|
|
flash_size=2000
|
2017-02-01 15:02:29 -06:00
|
|
|
echo "modprobe.blacklist=radeon" >>/tmp/append
|
|
|
|
fi
|
|
|
|
if [ "$platform" = "crow" ]; then
|
|
|
|
aboot_machine=arista_7050_qx32s
|
2017-11-22 04:58:20 -06:00
|
|
|
flash_size=3700
|
2017-02-03 18:32:42 -06:00
|
|
|
echo "modprobe.blacklist=radeon" >>/tmp/append
|
|
|
|
fi
|
2017-08-05 22:56:32 -05:00
|
|
|
if [ "$sid" = "Upperlake" ] || [ "$sid" = "UpperlakeES" ]; then
|
2017-02-03 18:32:42 -06:00
|
|
|
aboot_machine=arista_7060_cx32s
|
2017-11-22 04:58:20 -06:00
|
|
|
flash_size=3700
|
2017-02-03 18:32:42 -06:00
|
|
|
echo "amd_iommu=off" >> /tmp/append
|
2017-02-01 15:02:29 -06:00
|
|
|
fi
|
2017-08-05 22:56:32 -05:00
|
|
|
if [ "$sid" = "Gardena" ] || [ "$sid" = "GardenaSsd" ]; then
|
|
|
|
aboot_machine=arista_7260cx3_64
|
2017-11-22 04:58:20 -06:00
|
|
|
flash_size=28000
|
2017-08-05 22:56:32 -05:00
|
|
|
fi
|
|
|
|
if [ "$platform" = "rook" ]; then
|
|
|
|
readprefdl -f /tmp/.system-prefdl -d > /mnt/flash/.system-prefdl
|
|
|
|
fi
|
|
|
|
|
2017-12-06 17:13:18 -06:00
|
|
|
if [ $flash_size -ge 28000 ]; then
|
|
|
|
varlog_size=4096
|
|
|
|
elif [ $flash_size -ge 3700 ]; then
|
|
|
|
varlog_size=400
|
|
|
|
fi
|
|
|
|
|
2017-08-05 22:56:32 -05:00
|
|
|
echo "varlog_size=$varlog_size" >>/tmp/append
|
2017-02-01 15:02:29 -06:00
|
|
|
}
|
2016-03-16 01:38:26 -05:00
|
|
|
|
2017-05-01 17:16:33 -05:00
|
|
|
# check the hash file in the image, and determine to install or just skip
|
|
|
|
GIT_REVISION=$(unzip -p "$swipath" .imagehash)
|
|
|
|
LOCAL_IMAGEHASH=$(cat $image_path/.imagehash 2>/dev/null || true)
|
|
|
|
if [ "$GIT_REVISION" != "$LOCAL_IMAGEHASH" ]; then
|
|
|
|
[ -z "$sonic_upgrade" ] && clean_flash
|
|
|
|
extract_image
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -z "$sonic_upgrade" ] || exit 0
|
|
|
|
|
|
|
|
# build the new cmdline
|
2017-02-01 15:02:29 -06:00
|
|
|
echo "$append" >/tmp/append
|
|
|
|
parse_environment_config >>/tmp/append
|
2016-03-16 01:38:26 -05:00
|
|
|
cat /etc/cmdline | sed "/^\(${bootconfigvars// /\|}\|crashkernel\|loglevel\|ignore_loglevel\)\(\$\|=\)/d;/^\$/d" >>/tmp/append
|
|
|
|
|
2017-04-21 19:23:36 -05:00
|
|
|
echo "rw loop=image-%%IMAGE_VERSION%%/fs.squashfs loopfstype=squashfs apparmor=1 security=apparmor quiet" >>/tmp/append
|
2017-02-01 15:02:29 -06:00
|
|
|
|
|
|
|
# process platform specific operations
|
|
|
|
platform_specific
|
|
|
|
|
2017-05-01 17:16:33 -05:00
|
|
|
[ -e ${taget_path}/machine.conf ] || write_machine_config
|
|
|
|
|
2017-02-01 15:02:29 -06:00
|
|
|
# use extra parameters from kernel-params hook if the file exists
|
2017-04-21 19:23:36 -05:00
|
|
|
if [ -f "$image_path/$kernel_params" ]; then
|
|
|
|
cat "$image_path/$kernel_params" >>/tmp/append
|
2017-02-01 15:02:29 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
# setting root partition if not overridden by kernel-params
|
|
|
|
if ! grep -q "root=" /tmp/append; then
|
|
|
|
rootdev=$(mount | grep '/mnt/flash' | cut -f1 -d' ')
|
|
|
|
rootfstype=$(mount | grep '/mnt/flash' | cut -f5 -d' ')
|
|
|
|
echo "root=$rootdev" >>/tmp/append
|
|
|
|
fi
|
|
|
|
|
|
|
|
# chainloading using kexec
|
2017-04-21 19:23:36 -05:00
|
|
|
initrd_path="$image_path/$initrd"
|
|
|
|
kernel_path="$image_path/$kernel"
|
2017-02-01 15:02:29 -06:00
|
|
|
cmdline="$(tr '\n' ' ' </tmp/append)"
|
2016-03-16 01:38:26 -05:00
|
|
|
|
2017-02-01 15:02:29 -06:00
|
|
|
kexec --load --initrd="$initrd_path" --append="$cmdline" "$kernel_path"
|
|
|
|
[ -z "$testonly" ] || exit 0
|
2016-03-16 01:38:26 -05:00
|
|
|
kexec --exec
|