2 # SPDX-License-Identifier: GPL-2.0-only
4 # XIP kernel .data segment compressor
6 # Created by: Nicolas Pitre, August 2017
7 # Copyright: (C) 2017 Linaro Limited
10 # This script locates the start of the .data section in xipImage and
11 # substitutes it with a compressed version. The needed offsets are obtained
12 # from symbol addresses in vmlinux. It is expected that .data extends to
13 # the end of xipImage.
22 # Use "make V=1" to debug this script.
23 case "$KBUILD_VERBOSE" in
30 # extract hex value for symbol in $1
31 local val
=$
($NM "$VMLINUX" 2>/dev
/null |
sed -n "/ $1\$/{s/ .*$//p;q}")
32 [ "$val" ] ||
{ echo "can't find $1 in $VMLINUX" 1>&2; exit 1; }
33 # convert from hex to decimal
37 __data_loc
=$
(sym_val __data_loc
)
38 _edata_loc
=$
(sym_val _edata_loc
)
39 base_offset
=$
(sym_val _xiprom
)
41 # convert to file based offsets
42 data_start
=$
(($__data_loc - $base_offset))
43 data_end
=$
(($_edata_loc - $base_offset))
45 # Make sure data occupies the last part of the file.
46 file_end
=$
(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" "$XIPIMAGE")
47 if [ "$file_end" != "$data_end" ]; then
48 printf "end of xipImage doesn't match with _edata_loc (%#x vs %#x)\n" \
49 $
(($file_end + $base_offset)) $_edata_loc 1>&2
53 # be ready to clean up
54 trap 'rm -f "$XIPIMAGE.tmp"; exit 1' 1 2 3
56 # substitute the data section by a compressed version
57 $DD if="$XIPIMAGE" count
=$data_start iflag
=count_bytes of
="$XIPIMAGE.tmp"
58 $DD if="$XIPIMAGE" skip
=$data_start iflag
=skip_bytes |
59 $KGZIP -9 >> "$XIPIMAGE.tmp"
61 # replace kernel binary
62 mv -f "$XIPIMAGE.tmp" "$XIPIMAGE"