developer | bc730da | 2022-04-06 16:37:51 +0800 | [diff] [blame] | 1 | --- a/scripts/mkits.sh |
| 2 | +++ b/scripts/mkits.sh |
| 3 | @@ -17,7 +17,7 @@ |
| 4 | usage() { |
| 5 | printf "Usage: %s -A arch -C comp -a addr -e entry" "$(basename "$0")" |
| 6 | printf " -v version -k kernel [-D name -n address -d dtb] -o its_file" |
| 7 | - printf " [-s script] [-S key_name_hint] [-r ar_ver]" |
| 8 | + printf " [-s script] [-S key_name_hint] [-r ar_ver] [-R rootfs]" |
| 9 | |
| 10 | printf "\n\t-A ==> set architecture to 'arch'" |
| 11 | printf "\n\t-C ==> set compression type 'comp'" |
| 12 | @@ -32,13 +32,14 @@ usage() { |
| 13 | printf "\n\t-o ==> create output file 'its_file'" |
| 14 | printf "\n\t-s ==> include u-boot script 'script'" |
| 15 | printf "\n\t-S ==> add signature at configurations and assign its key_name_hint by 'key_name_hint'" |
| 16 | - printf "\n\t-r ==> set anti-rollback version to 'fw_ar_ver' (dec)\n" |
| 17 | + printf "\n\t-r ==> set anti-rollback version to 'fw_ar_ver' (dec)" |
| 18 | + printf "\n\t-R ==> specify rootfs file for embedding hash\n" |
| 19 | exit 1 |
| 20 | } |
| 21 | |
| 22 | FDTNUM=1 |
| 23 | |
| 24 | -while getopts ":A:a:c:C:D:d:e:k:n:o:v:s:S:r:" OPTION |
| 25 | +while getopts ":A:a:c:C:D:d:e:k:n:o:v:s:S:r:R:" OPTION |
| 26 | do |
| 27 | case $OPTION in |
| 28 | A ) ARCH=$OPTARG;; |
| 29 | @@ -55,6 +56,7 @@ do |
| 30 | s ) UBOOT_SCRIPT=$OPTARG;; |
| 31 | S ) KEY_NAME_HINT=$OPTARG;; |
| 32 | r ) AR_VER=$OPTARG;; |
| 33 | + R ) ROOTFS_FILE=$OPTARG;; |
| 34 | * ) echo "Invalid option passed to '$0' (options:$*)" |
| 35 | usage;; |
| 36 | esac |
| 37 | @@ -89,6 +91,30 @@ if [ -n "${DTB}" ]; then |
| 38 | FDT_PROP="fdt = \"fdt-$FDTNUM\";" |
| 39 | fi |
| 40 | |
| 41 | +# Conditionally create rootfs hash information |
| 42 | +if [ -f "${ROOTFS_FILE}" ]; then |
| 43 | + ROOTFS_SIZE=$(stat -c %s ${ROOTFS_FILE}) |
| 44 | + |
| 45 | + ROOTFS_SHA1=$(sha1sum ${ROOTFS_FILE} | awk '{print "<0x"substr($0,1,8) " 0x"substr($0,9,8) " 0x"substr($0,17,8) " 0x"substr($0,25,8) " 0x"substr($0,33,8) ">"}') |
| 46 | + ROOTFS_CRC32=$(crc32sum ${ROOTFS_FILE}) |
| 47 | + |
| 48 | + ROOTFS=" |
| 49 | + rootfs { |
| 50 | + size = <${ROOTFS_SIZE}>; |
| 51 | + |
| 52 | + hash-1 { |
| 53 | + value = <0x${ROOTFS_CRC32}>; |
| 54 | + algo = \"crc32\"; |
| 55 | + }; |
| 56 | + |
| 57 | + hash-2 { |
| 58 | + value = ${ROOTFS_SHA1}; |
| 59 | + algo = \"sha1\"; |
| 60 | + }; |
| 61 | + }; |
| 62 | +" |
| 63 | +fi |
| 64 | + |
| 65 | # Conditionally create script information |
| 66 | if [ -n "${UBOOT_SCRIPT}" ]; then |
| 67 | SCRIPT="\ |
| 68 | @@ -167,6 +193,8 @@ ${FDT_NODE} |
| 69 | ${SCRIPT} |
| 70 | }; |
| 71 | |
| 72 | +${ROOTFS} |
| 73 | + |
| 74 | configurations { |
| 75 | default = \"${CONFIG}\"; |
| 76 | ${CONFIG} { |