Skip to content

Commit

Permalink
Add SWI_DEFAULT support in boot0 (#2056)
Browse files Browse the repository at this point in the history
Currently setting the next boot image is the same as setting a default
image.
With this change SWI_DEFAULT= will be considered the default image and
SWI= the next image.
When executing the boot0 SWI= will be overriden by SWI_DEFAULT= if it
exists and create in with the value of SWI= otherwise.
  • Loading branch information
Staphylo authored and lguohan committed Sep 20, 2018
1 parent 8a5e6ac commit 7ece396
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions files/Aboot/boot0.j2
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ kernel_params="kernel-params"

aboot_machine="arista_unknown"


# extract mount point from the swi path, e.g., /mnt/flash/sonic.swi --> /mnt/flash
if [ -z "$target_path" ]; then
if [ -z "$swipath" ]; then
Expand All @@ -61,6 +60,7 @@ image_path="$target_path/$image_name"

cmdline_base="$target_path/kernel-params-base"
cmdline_image="$image_path/kernel-cmdline"
boot_config="$target_path/boot-config"

bootconfigvars="KERNEL INITRD CONSOLESPEED PASSWORD NETDEV NETAUTO NETIP NETMASK NETGW NETDOMAIN NETDNS NETHW memtest"
flash_re=" /mnt/flash| /host"
Expand Down Expand Up @@ -88,6 +88,33 @@ clean_flash() {
done
}

update_boot_config() {
local key="$1"
local value="$2"

if grep "$key" "$boot_config" 2>&1 > /dev/null; then
sed -i "s#^$key=.*\$#$key=$value#" "$boot_config"
else
echo "$key=$value" >> "$boot_config"
fi
}

get_boot_config() {
local key="$1"

sed -n "s#^$key=##p" "$boot_config" || :
}

update_next_boot() {
local default="$(get_boot_config SWI_DEFAULT)"

if [ -z "$default" ]; then
echo "warning: no variable SWI_DEFAULT available"
else
update_boot_config SWI "$default"
fi
}

extract_image() {
mkdir -p "$image_path"

Expand All @@ -114,7 +141,9 @@ extract_image() {
fi

## use new reduced-size boot swi
echo "SWI=flash:$image_name/{{ ABOOT_BOOT_IMAGE }}" > "$target_path/boot-config"
local swi_boot_path="flash:$image_name/{{ ABOOT_BOOT_IMAGE }}"
update_boot_config SWI "$swi_boot_path"
update_boot_config SWI_DEFAULT "$swi_boot_path"

## Remove installer swi as it has lots of redundunt contents
rm -f "$swipath"
Expand Down Expand Up @@ -320,6 +349,7 @@ fi

# chainloading using kexec
if $do_kexec; then
update_next_boot
run_kexec
fi

0 comments on commit 7ece396

Please sign in to comment.