Skip to content
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

Merged
merged 2 commits into from
May 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions files/Aboot/boot0.j2
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kernel_params=kernel-params

aboot_machine="arista_unknown"

target_path=/mnt/flash
[ -z "$target_path" ] && target_path=/mnt/flash
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

image_path="$target_path/image-%%IMAGE_VERSION%%"

# expect the swi to be a non empty file
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2>/dev/null || true [](start = 44, length = 20)

No need to handle stderr and return code.
https://www.gnu.org/software/bash/manual/bashref.html#Command-Substitution

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
Expand All @@ -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
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-utilities