Skip to content

Commit

Permalink
Merge pull request #3484 from kszaq/arm64_uimage_alignment
Browse files Browse the repository at this point in the history
linux: amend uimage load address for proper decompression
  • Loading branch information
MilhouseVH authored May 4, 2019
2 parents bc04a40 + 502e4de commit f3de4b0
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/linux/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ make_target() {
# arm64 target does not support creating uImage.
# Build Image first, then wrap it using u-boot's mkimage.
if [[ "$TARGET_KERNEL_ARCH" == "arm64" && "$KERNEL_TARGET" == uImage* ]]; then
if [ -z "$KERNEL_UIMAGE_LOADADDR" -o -z "$KERNEL_UIMAGE_ENTRYADDR" ]; then
die "ERROR: KERNEL_UIMAGE_LOADADDR and KERNEL_UIMAGE_ENTRYADDR have to be set to build uImage - aborting"
fi
KERNEL_UIMAGE_TARGET="$KERNEL_TARGET"
KERNEL_TARGET="${KERNEL_TARGET/uImage/Image}"
fi
Expand Down Expand Up @@ -243,16 +246,32 @@ make_target() {
fi

if [ -n "$KERNEL_UIMAGE_TARGET" ] ; then
# determine compression used for kernel image
KERNEL_UIMAGE_COMP=${KERNEL_UIMAGE_TARGET:7}
KERNEL_UIMAGE_COMP=${KERNEL_UIMAGE_COMP:-none}

# calculate new load address to make kernel Image unpack to memory area after compressed image
if [ "$KERNEL_UIMAGE_COMP" != "none" ] ; then
COMPRESSED_SIZE=$(stat -t "arch/$TARGET_KERNEL_ARCH/boot/$KERNEL_TARGET" | awk '{print $2}')
# align to 1 MiB
COMPRESSED_SIZE=$(( (($COMPRESSED_SIZE - 1 >> 20) + 1) << 20 ))
PKG_KERNEL_UIMAGE_LOADADDR=$(printf '%X' "$(( $KERNEL_UIMAGE_LOADADDR + $COMPRESSED_SIZE ))")
PKG_KERNEL_UIMAGE_ENTRYADDR=$(printf '%X' "$(( $KERNEL_UIMAGE_ENTRYADDR + $COMPRESSED_SIZE ))")
else
PKG_KERNEL_UIMAGE_LOADADDR=${KERNEL_UIMAGE_LOADADDR}
PKG_KERNEL_UIMAGE_ENTRYADDR=${KERNEL_UIMAGE_ENTRYADDR}
fi

mkimage -A $TARGET_KERNEL_ARCH \
-O linux \
-T kernel \
-C $KERNEL_UIMAGE_COMP \
-a $KERNEL_UIMAGE_LOADADDR \
-e $KERNEL_UIMAGE_ENTRYADDR \
-a $PKG_KERNEL_UIMAGE_LOADADDR \
-e $PKG_KERNEL_UIMAGE_ENTRYADDR \
-d arch/$TARGET_KERNEL_ARCH/boot/$KERNEL_TARGET \
arch/$TARGET_KERNEL_ARCH/boot/$KERNEL_UIMAGE_TARGET

KERNEL_TARGET="${KERNEL_UIMAGE_TARGET}"
fi
}

Expand Down

0 comments on commit f3de4b0

Please sign in to comment.