blob: 9a2f163d518af484e68ec01acce1a6d54d6e0797 [file] [log] [blame]
xf.liaa4d92f2023-09-13 00:18:58 -07001#!/bin/bash
2
3set -e
4
5if [ $# -lt 2 ]; then
6 echo "$0 private_key work_dir"
7 exit -1
8fi
9
10PRIVATE_KEY=$1
11WORK_DIR=$2
12#v3t for old device, sha256 is not supported, only md5
13DEVICE=$3
14HASH_STR="sha256"
15
16echo "PRIVATE_KEY:" $PRIVATE_KEY
17echo "WORK_DIR:" $WORK_DIR
18
19#ap_cpucap name changed for checking errors
20if [ -f $WORK_DIR/ap_cpucap.bin ]; then
21 mv $WORK_DIR/ap_cpucap.bin $WORK_DIR/inter_ap_cpucap.bin
22fi
23# vehicle device zloader.bin structure
24# ---------------------------------------------------------------
25# | 8 KB | 24 KB | 8KB |
26# ---------------------------------------------------------------
27# | bootrom1.bin | bootrom2.bin | zloader3.bin |
28# ---------------------------------------------------------------
29if [ x"$DEVICE" = x"v3t" ]; then
30 HASH_STR="md5"
31 if [ `ls -s $WORK_DIR/zloader.bin | awk '{print $1}'` -gt 32 ]; then
32 #old v3t device for vehicle
33 fileread $WORK_DIR/zloader.bin 0 8192 $WORK_DIR/bootrom1.bin
34 fileread $WORK_DIR/zloader.bin 8192 24576 $WORK_DIR/bootrom2.bin
35 fileread $WORK_DIR/zloader.bin 32768 0 $WORK_DIR/zloader3.bin
36 SignImage -z -i $WORK_DIR/bootrom1.bin -k $PRIVATE_KEY -t $HASH_STR
37 SignImage -z -i $WORK_DIR/bootrom2.bin -k $PRIVATE_KEY -t $HASH_STR
38 SignImage -z -i $WORK_DIR/zloader3.bin -k $PRIVATE_KEY -t $HASH_STR
39 cat $WORK_DIR/bootrom1.bin $WORK_DIR/bootrom2.bin $WORK_DIR/zloader3.bin > $WORK_DIR/zloader.bin
40 rm -v $WORK_DIR/bootrom1.bin $WORK_DIR/bootrom2.bin $WORK_DIR/zloader3.bin
41 else
42 #old v3t device for mdl/mifi etc.
43 SignImage -z -i $WORK_DIR/zloader.bin -k $PRIVATE_KEY -t $HASH_STR
44 fi
xf.lice873192023-11-08 17:10:35 -080045 SignImage -z -i $WORK_DIR/tloader.bin -k $PRIVATE_KEY -t $HASH_STR
xf.liaa4d92f2023-09-13 00:18:58 -070046fi
47echo "HASH_STR:" $HASH_STR
48SignImage -r -i $WORK_DIR/uboot.bin -k $PRIVATE_KEY -t $HASH_STR
49
50# ap_rootfs.img ap_cpuap.bin
51# ---------------------------------------------------------------------------------------------------------------
52# | 640 Bytes | 640 Bytes | 64 Bytes | 64 Bytes |
53# ---------------------------------------------------------------------------------------------------------------
54# | ap_cpuap.bin signdata | ap_rootfs.img signdata | ap_rootfs.img mkimage header | ap_cpuap.bin mkimage header |
55# ---------------------------------------------------------------------------------------------------------------
56#mkimage -A arm -O linux -C none -T filesystem -a 0 -e 0 -n 'rootfs' -d $WORK_DIR/ap_rootfs.img $WORK_DIR/ap_rootfs_u.img
57fileread $WORK_DIR/ap_cpuap.bin 1280 64 $WORK_DIR/rootfs_mkimage_header.img
58cat $WORK_DIR/rootfs_mkimage_header.img $WORK_DIR/ap_rootfs.img > $WORK_DIR/ap_rootfs.u
59SignImage -i $WORK_DIR/ap_rootfs.u -o $WORK_DIR/ap_rootfs.signed -k $PRIVATE_KEY -t $HASH_STR
60fileread $WORK_DIR/ap_rootfs.signed 0 704 $WORK_DIR/ap_rootfs.sign
61filewrite $WORK_DIR/ap_cpuap.bin 640 $WORK_DIR/ap_rootfs.sign $WORK_DIR/ap_cpuap.bin
62SignImage -r -i $WORK_DIR/ap_cpuap.bin -k $PRIVATE_KEY -t $HASH_STR
63
64SignImage -r -i $WORK_DIR/evb_cpurpm.img -k $PRIVATE_KEY -t $HASH_STR
65SignImage -r -i $WORK_DIR/evb_cpuphy.bin -k $PRIVATE_KEY -t $HASH_STR
66SignImage -r -i $WORK_DIR/inter_ap_cpucap.bin -k $PRIVATE_KEY -t $HASH_STR
67
68if [ -f $WORK_DIR/ap_caprootfs.img.dm ]; then
69 echo "ap_caprootfs.img resign start"
70 rm -rf $WORK_DIR/verity && mkdir -p $WORK_DIR/verity
71 zxic_parse_squashfs_verity $WORK_DIR/ap_caprootfs.img.dm $WORK_DIR/verity/sign $WORK_DIR/verity/raw_table $WORK_DIR/verity/hash_tree_offset
72 SignImage -d -i $WORK_DIR/verity/raw_table -o $WORK_DIR/verity/raw_table.signed -k $PRIVATE_KEY -t $HASH_STR
73 fileseek $WORK_DIR/ap_caprootfs.img $WORK_DIR/verity/sign > $WORK_DIR/verity/sign_offset
xf.lice873192023-11-08 17:10:35 -080074 filewrite $WORK_DIR/ap_caprootfs.img $WORK_DIR/verity/sign_offset $WORK_DIR/verity/raw_table.signed $WORK_DIR/ap_caprootfs.img
xf.liaa4d92f2023-09-13 00:18:58 -070075
76 #fix ap_caprootfs.img.dm
77 fileseek $WORK_DIR/ap_caprootfs.img.dm $WORK_DIR/verity/sign > $WORK_DIR/verity/sign_offset
xf.lice873192023-11-08 17:10:35 -080078 filewrite $WORK_DIR/ap_caprootfs.img.dm $WORK_DIR/verity/sign_offset $WORK_DIR/verity/raw_table.signed $WORK_DIR/ap_caprootfs.img.dm
xf.liaa4d92f2023-09-13 00:18:58 -070079
80 echo "ap_caprootfs.img resign success"
81fi
82if [ -f $WORK_DIR/cap_oem.img.dm ]; then
83 echo "cap_oem.img resign start"
84 rm -rf $WORK_DIR/verity && mkdir -p $WORK_DIR/verity
85 zxic_parse_squashfs_verity $WORK_DIR/cap_oem.img.dm $WORK_DIR/verity/sign $WORK_DIR/verity/raw_table $WORK_DIR/verity/hash_tree_offset
86 SignImage -d -i $WORK_DIR/verity/raw_table -o $WORK_DIR/verity/raw_table.signed -k $PRIVATE_KEY -t $HASH_STR
87 fileseek $WORK_DIR/cap_oem.img $WORK_DIR/verity/sign > $WORK_DIR/verity/sign_offset
xf.lice873192023-11-08 17:10:35 -080088 filewrite $WORK_DIR/cap_oem.img $WORK_DIR/verity/sign_offset $WORK_DIR/verity/raw_table.signed $WORK_DIR/cap_oem.img
xf.liaa4d92f2023-09-13 00:18:58 -070089
90 #fix cap_oem.img.dm
91 fileseek $WORK_DIR/cap_oem.img.dm $WORK_DIR/verity/sign > $WORK_DIR/verity/sign_offset
xf.lice873192023-11-08 17:10:35 -080092 filewrite $WORK_DIR/cap_oem.img.dm $WORK_DIR/verity/sign_offset $WORK_DIR/verity/raw_table.signed $WORK_DIR/cap_oem.img.dm
xf.liaa4d92f2023-09-13 00:18:58 -070093 echo "cap_oem.img resign success"
94fi
95
96mv $WORK_DIR/inter_ap_cpucap.bin $WORK_DIR/ap_cpucap.bin
97
98rm -fv $WORK_DIR/ap_rootfs.u
99rm -fv $WORK_DIR/ap_rootfs.sign
100rm -fv $WORK_DIR/rootfs_mkimage_header.img
101rm -fv $WORK_DIR/ap_rootfs.signed
xf.li9d1a0e12023-09-20 01:43:20 -0700102rm -fv $WORK_DIR/ap_imagefs*.img
xf.liaa4d92f2023-09-13 00:18:58 -0700103rm -fr $WORK_DIR/verity