huangcm
2024-12-18 9d29be7f7249789d6ffd0440067187a9f040c2cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
#
# pack/pack
# (c) Copyright 2013
# Allwinner Technology Co., Ltd. <www.allwinnertech.com>
# flord wang <wangflord@allwinnertech.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
 
LOCAL_DIR=$(cd $(dirname $0) && pwd)
TOP_DIR=$(cd $LOCAL_DIR/.. && pwd)
TOOLS_DIR=$TOP_DIR/tools/pack/pctools/linux/openssl
SELECT_IC=
 
export PATH=$TOOLS_DIR:$PATH
 
function pack_error()
{
   echo -e "\033[47;31mERROR: $*\033[0m"
}
 
function pack_info()
{
   echo -e "\033[0;31;1mINFO: $*\033[0m"
}
 
function show_help()
{
   echo "build.sh - this script is used to create all keys defined in the dragon_toc.cfg"
   echo "OPTIONS"
   echo "-h            Display help message"
   echo "-i [ic_type]  IC type, e.g. a50,a64..."
   echo "-f            Force create new key"
}
 
function build_select_ic()
{
   [ -n "$SELECT_IC" ] && return 0
   local count=0
   local defidx=0
   local defval=""
 
   if [ -f $TOP_DIR/.buildconfig ]; then
       defval=$(awk -F= '/^export LICHEE_IC=/{print $2}' $TOP_DIR/.buildconfig)
   fi
 
   printf "All valid Sunxi ic:\n"
   for ic in $( find $TOP_DIR/device/config/chips/ -mindepth 1 -maxdepth 1 -type d |sort); do
       ics[$count]=`basename $ic`
       printf "%4d. ${ics[$count]}\n" $count
       [ "x$defval" == "x${ics[$count]}" ] && defidx=$count
       let count=$count+1
   done
 
   while true; do
       read -p "Please select a ic[${ics[$defidx]}]: "
       [ -z "$REPLY" ] && REPLY=$defidx
       RES=`expr match $REPLY "[0-9][0-9]*$"`
       if [ "$RES" -le 0 ]; then
           echo "please use index number"
           continue
       fi
       if [ "$REPLY" -ge $count ]; then
           echo "too big"
           continue
       fi
       if [ "$REPLY" -lt "0" ]; then
           echo "too small"
           continue
       fi
       break
   done
 
   SELECT_IC=${ics[$REPLY]}
}
 
function createkeys()
{
   printf "ready to create keys\n"
 
   find $TOP_DIR/device/config/chips/ -mindepth 1 -maxdepth 1 -type d | grep -w "$SELECT_IC"
   if [ $? -ne 0 ]; then
       pack_error "plat: $SELECT_IC is not exist"
       exit 1
   fi
 
   pack_info "SELECT_IC is $SELECT_IC\n"
 
   local toc_cfg_special=$TOP_DIR/device/config/chips/$SELECT_IC/configs/default/dragon_toc.cfg
   local toc_cfg_default=$TOP_DIR/device/config/common/sign_config/dragon_toc.cfg
   local toc_cfg=$toc_cfg_special
   local key_out=$TOP_DIR/out/$SELECT_IC/common/keys
 
   if [ -n "`find $key_out -type f 2> /dev/null`" ]; then
       if [ "xtrue" != "x$FORCE_CREATE" ]; then
           pack_info "already has key, use -f to force overwrite new key.\n"
           exit 0
       fi
   fi
 
   pack_info "creating new key\n"
 
   if [ ! -f $toc_cfg ]; then
       toc_cfg=$toc_cfg_default
   fi
 
   if [ ! -f $toc_cfg ]; then
       pack_error "dragon toc config file is not exist"
       exit 1
   fi
 
   dragonsecboot -key $toc_cfg $key_out
   if [ $? -ne 0 ]; then
       pack_error "dragon toc run error"
       exit 1
   fi
 
   if [ "x$toc_cfg" == "x$toc_cfg_special" ]; then
       pack_info "use platform[$SELECT_IC] toc config to create keys\n"
   else
       pack_info "use default toc config to create keys\n"
   fi
}
 
while getopts fhi: OPTION; do
   case $OPTION in
       i)
           SELECT_IC=$OPTARG
           ;;
       f)
           FORCE_CREATE=true
           ;;
       *)
           show_help
           exit 0
           ;;
   esac
done
 
build_select_ic
createkeys