-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[aboot]: refactor boot0.j2 to support one image SONiC-to-SONiC upgrade #557
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ kernel_params=kernel-params | |
|
||
aboot_machine="arista_unknown" | ||
|
||
target_path=/mnt/flash | ||
[ -z "$target_path" ] && target_path=/mnt/flash | ||
image_path="$target_path/image-%%IMAGE_VERSION%%" | ||
|
||
# expect the swi to be a non empty file | ||
|
@@ -41,15 +41,18 @@ parse_environment_config() { | |
done | ||
} | ||
|
||
extract_image() { | ||
clean_flash() { | ||
## Remove all the other unnecssary files except swi file, boot-config | ||
for f in $(ls -A $target_path); do | ||
if [ $f != "${swipath##*/}" ] && [ $f != "boot-config" ]; then | ||
rm -rf "$target_path/$f" | ||
fi | ||
done | ||
} | ||
|
||
extract_image() { | ||
|
||
mkdir "$image_path" | ||
mkdir -p "$image_path" | ||
|
||
## Unzip the image | ||
unzip -oq "$swipath" -x boot0 -d "$image_path" | ||
|
@@ -58,10 +61,10 @@ extract_image() { | |
rm -f $swipath | ||
|
||
## detect rootfs type | ||
rootfs_type=`grep /mnt/flash /proc/mounts | cut -d' ' -f3` | ||
rootfs_type=`grep " $target_path " /proc/mounts | cut -d' ' -f3` | ||
|
||
## vfat does not support symbol link | ||
if [ $rootfs_type != "vfat" ]; then | ||
if [ -n "$sonic_upgrade" ] || [ "$rootfs_type" != "vfat" ]; then | ||
mkdir -p "$image_path/{{ DOCKERFS_DIR }}" | ||
|
||
## extract docker archive | ||
|
@@ -70,15 +73,12 @@ extract_image() { | |
## clean up docker archive | ||
rm -f "$image_path/{{ FILESYSTEM_DOCKERFS }}" | ||
else | ||
echo "/mnt/flash is $rootfs_type, extract {{ FILESYSTEM_DOCKERFS }} in later stage" | ||
echo "$target_path is $rootfs_type, extract {{ FILESYSTEM_DOCKERFS }} in later stage" | ||
fi | ||
|
||
## use new reduced-size boot swi | ||
echo "SWI=flash:image-%%IMAGE_VERSION%%/{{ ABOOT_BOOT_IMAGE }}" > "$target_path/boot-config" | ||
|
||
## remove original boot swi | ||
rm -f "$swipath" | ||
|
||
## sync disk operations | ||
sync | ||
} | ||
|
@@ -120,6 +120,17 @@ platform_specific() { | |
fi | ||
} | ||
|
||
# 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No need to handle stderr and return code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it works. I can revisit it later, but I do not want to change this for this pr. |
||
if [ "$GIT_REVISION" != "$LOCAL_IMAGEHASH" ]; then | ||
[ -z "$sonic_upgrade" ] && clean_flash | ||
extract_image | ||
fi | ||
|
||
[ -z "$sonic_upgrade" ] || exit 0 | ||
|
||
# build the new cmdline | ||
echo "$append" >/tmp/append | ||
parse_environment_config >>/tmp/append | ||
cat /etc/cmdline | sed "/^\(${bootconfigvars// /\|}\|crashkernel\|loglevel\|ignore_loglevel\)\(\$\|=\)/d;/^\$/d" >>/tmp/append | ||
|
@@ -129,6 +140,8 @@ echo "rw loop=image-%%IMAGE_VERSION%%/fs.squashfs loopfstype=squashfs apparmor=1 | |
# process platform specific operations | ||
platform_specific | ||
|
||
[ -e ${taget_path}/machine.conf ] || write_machine_config | ||
|
||
# use extra parameters from kernel-params hook if the file exists | ||
if [ -f "$image_path/$kernel_params" ]; then | ||
cat "$image_path/$kernel_params" >>/tmp/append | ||
|
@@ -141,14 +154,6 @@ if ! grep -q "root=" /tmp/append; then | |
echo "root=$rootdev" >>/tmp/append | ||
fi | ||
|
||
# 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 | ||
extract_image | ||
write_machine_config | ||
fi | ||
|
||
# chainloading using kexec | ||
initrd_path="$image_path/$initrd" | ||
kernel_path="$image_path/$kernel" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it more readable to rewrite similar blocks by 'if-else'.
The shortcuts is useful for simple error handling, but confusing for complex conditions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if target_path is null, then assign target_path. It is the simplest logic.