Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0-only
0003 
0004 # XIP kernel .data segment compressor
0005 #
0006 # Created by:   Nicolas Pitre, August 2017
0007 # Copyright:    (C) 2017  Linaro Limited
0008 #
0009 
0010 # This script locates the start of the .data section in xipImage and
0011 # substitutes it with a compressed version. The needed offsets are obtained
0012 # from symbol addresses in vmlinux. It is expected that .data extends to
0013 # the end of xipImage.
0014 
0015 set -e
0016 
0017 VMLINUX="$1"
0018 XIPIMAGE="$2"
0019 
0020 DD="dd status=none"
0021 
0022 # Use "make V=1" to debug this script.
0023 case "$KBUILD_VERBOSE" in
0024 *1*)
0025         set -x
0026         ;;
0027 esac
0028 
0029 sym_val() {
0030         # extract hex value for symbol in $1
0031         local val=$($NM "$VMLINUX" 2>/dev/null | sed -n "/ $1\$/{s/ .*$//p;q}")
0032         [ "$val" ] || { echo "can't find $1 in $VMLINUX" 1>&2; exit 1; }
0033         # convert from hex to decimal
0034         echo $((0x$val))
0035 }
0036 
0037 __data_loc=$(sym_val __data_loc)
0038 _edata_loc=$(sym_val _edata_loc)
0039 base_offset=$(sym_val _xiprom)
0040 
0041 # convert to file based offsets
0042 data_start=$(($__data_loc - $base_offset))
0043 data_end=$(($_edata_loc - $base_offset))
0044 
0045 # Make sure data occupies the last part of the file.
0046 file_end=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" "$XIPIMAGE")
0047 if [ "$file_end" != "$data_end" ]; then
0048         printf "end of xipImage doesn't match with _edata_loc (%#x vs %#x)\n" \
0049                $(($file_end + $base_offset)) $_edata_loc 1>&2
0050         exit 1;
0051 fi
0052 
0053 # be ready to clean up
0054 trap 'rm -f "$XIPIMAGE.tmp"; exit 1' 1 2 3
0055 
0056 # substitute the data section by a compressed version
0057 $DD if="$XIPIMAGE" count=$data_start iflag=count_bytes of="$XIPIMAGE.tmp"
0058 $DD if="$XIPIMAGE"  skip=$data_start iflag=skip_bytes |
0059 $KGZIP -9 >> "$XIPIMAGE.tmp"
0060 
0061 # replace kernel binary
0062 mv -f "$XIPIMAGE.tmp" "$XIPIMAGE"