Skip to content

Commit 7ece396

Browse files
Staphylolguohan
authored andcommitted
Add SWI_DEFAULT support in boot0 (#2056)
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.
1 parent 8a5e6ac commit 7ece396

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

files/Aboot/boot0.j2

+32-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ kernel_params="kernel-params"
4848

4949
aboot_machine="arista_unknown"
5050

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

6261
cmdline_base="$target_path/kernel-params-base"
6362
cmdline_image="$image_path/kernel-cmdline"
63+
boot_config="$target_path/boot-config"
6464

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

91+
update_boot_config() {
92+
local key="$1"
93+
local value="$2"
94+
95+
if grep "$key" "$boot_config" 2>&1 > /dev/null; then
96+
sed -i "s#^$key=.*\$#$key=$value#" "$boot_config"
97+
else
98+
echo "$key=$value" >> "$boot_config"
99+
fi
100+
}
101+
102+
get_boot_config() {
103+
local key="$1"
104+
105+
sed -n "s#^$key=##p" "$boot_config" || :
106+
}
107+
108+
update_next_boot() {
109+
local default="$(get_boot_config SWI_DEFAULT)"
110+
111+
if [ -z "$default" ]; then
112+
echo "warning: no variable SWI_DEFAULT available"
113+
else
114+
update_boot_config SWI "$default"
115+
fi
116+
}
117+
91118
extract_image() {
92119
mkdir -p "$image_path"
93120

@@ -114,7 +141,9 @@ extract_image() {
114141
fi
115142

116143
## use new reduced-size boot swi
117-
echo "SWI=flash:$image_name/{{ ABOOT_BOOT_IMAGE }}" > "$target_path/boot-config"
144+
local swi_boot_path="flash:$image_name/{{ ABOOT_BOOT_IMAGE }}"
145+
update_boot_config SWI "$swi_boot_path"
146+
update_boot_config SWI_DEFAULT "$swi_boot_path"
118147

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

321350
# chainloading using kexec
322351
if $do_kexec; then
352+
update_next_boot
323353
run_kexec
324354
fi
325355

0 commit comments

Comments
 (0)