testsk
6.73 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#!/bin/sh
SKDIR=`pwd`
#
# general testing params
#
OBJCOPY=mips-linux-objcopy
OBJCOPY_REMOVE_SECTS="-R .reginfo -R .note -R .comment -R .mdebug"
# tools
HOST_TOOL_DIR=$ROOT/usr/sbin
HOST_DATA_DIR=$ROOT/usr/host_data
TICKROM=$HOST_TOOL_DIR/tickrom
PUBROM=$HOST_TOOL_DIR/pubrom
WRITE_FLASH_TOOL=$HOST_TOOL_DIR/writeflash
V2_TOOL2=$HOST_TOOL_DIR/v2Create
SIMOS_BIN=$HOST_TOOL_DIR/simos
# values, with defaults, that may be altered by env settings
bbid_local= bbprivkey_local=
if [[ -z $BBID ]]; then
bbid_local=1
BBID="1"
fi
if [[ -z $BB_PRIV_KEY ]]; then
bbprivkey_local=1
BB_PRIV_KEY="a81902767e25db170f3449c5d94b162fa81902767e25db170f3449c5d94b162f"
fi
if [[ -z $BB_ROM_HW_RIGHTS ]]; then
BB_ROM_HW_RIGHTS="-r 0xffffffff"
fi
if [[ -z $BB_ROM_SW_RIGHTS ]]; then
BB_ROM_SW_RIGHTS="-R 0"
fi
if [[ -z $BB_CERTS_FILE ]]; then
BB_CERTS_FILE=$HOST_DATA_DIR/cert.sys
fi
if [[ -z $BB_ROM_RECRYPT ]]; then
BB_ROM_RECRYPT=-E
fi
if [[ -z $BB_CRL_FILE ]]; then
# placeholder for clarity
BB_CRL_FILE=$HOST_DATA_DIR/crl.sys
fi
# generated in this script
BB_ECCCERT=ecccert.bin
BB_CERT=cert.bin
V2_CONSTFILE=$HOST_DATA_DIR/virage2.in
V2_TMPFILE=v2.bin
# specify sysapp to use
SYSAPP_DIR=../../bbapps/boot/sysapp
SYSAPP_AES=$SYSAPP_DIR/sysapp.aes
SYSAPP_TIK=$SYSAPP_DIR/sysapp.tik
# packaged rom cid and fs name
SYSAPP_LOADED_ROM_CID=3150822347
SYSAPP_LOADED_ROM_AES=bbcdbbcb.app
# to test server integration
SERVER_TEST_DIR=~/source/bb/server
SERVER_SK_AES=$SERVER_TEST_DIR/sk.aes
SERVER_SYSAPP_AES=$SERVER_TEST_DIR/sysapp.aes
SERVER_SYSAPP_TIK=$SERVER_TEST_DIR/sysapp.tik
SERVER_TIK_FILE=$SERVER_TEST_DIR/ticket.sys
SERVER_CERTS_FILE=$SERVER_TEST_DIR/cert.sys
SERVER_GAME_FILE=$SERVER_TEST_DIR/00000002.app
# support SIMOS-based testing
TMPFILE=j.j
ROM_ELF=../../lib/bbboot/final/rom.elf
WRITE_FLASH_OUT=flash.img
# size for flashimg in MB
WRITE_FLASH_FSIZE=64
#
# general purpose functions to support simulations
#
function build_v2 {
# build v2 packaged as ascii hex
$V2_TOOL2 -b $BBID -p $BB_PRIV_KEY -e $BB_ECCCERT -c $BB_CERT $V2_CONSTFILE $V2_TMPFILE
# XXX: this make depends on V2_TMPFILE, above, being v2.bin
if ! make v2.hex
then
echo "failed to convert virage 2 to hex"
exit 1
fi
}
# package a prebuilt rom that will be loaded by the sysapp. creates
# cmd and eticket. takes an args:
# first) full pathname of game rom (.bin file) to be packaged
# remainder) args to make used to build testapp
function package_rom {
# package and generate cmd
if ! $PUBROM $BB_ROM_RECRYPT $BB_ROM_SW_RIGHTS $BB_ROM_HW_RIGHTS $1 \
$SYSAPP_LOADED_ROM_CID
then
echo "failed to package sysapp-loadable game rom and create cmd"
exit 1
fi
# generate the ticket
# for now, only one ticket per file
rm -f ticket.sys
if ! $TICKROM -c $BB_ECCCERT $SYSAPP_LOADED_ROM_CID ticket.sys
then
echo "failed to create rom eticket"
exit 1
fi
}
# create a nand file with sk, sysapp "ticket" block, and sysapp.
# args are regular fs files to be loaded to fs.
function create_bootable_nand_file {
# create module nand-flash image
if ! $WRITE_FLASH_TOOL -s $WRITE_FLASH_FSIZE -k sk.aes \
-b $SYSAPP_AES -l $SYSAPP_TIK -v $@
then
echo "failed to create module nand flash image"
exit 1
fi
}
# create a nand file with sk, sysapp "ticket" block, and sysapp.
# args are regular fs files to be loaded to fs.
function create_server_nand_file {
# create module nand-flash image
if ! $WRITE_FLASH_TOOL -s $WRITE_FLASH_FSIZE -k $SERVER_SK_AES \
-b $SERVER_SYSAPP_AES -l $SERVER_SYSAPP_TIK -v $@
then
echo "failed to create module nand flash image"
exit 1
fi
}
function build_simos_bootrom
{
# build romsimos.elf loadable by simos
$OBJCOPY -O binary -S $OBJCOPY_REMOVE_SECTS $ROM_ELF rom.bin
$OBJCOPY -j .bss --add-section .text=./rom.bin $ROM_ELF $TMPFILE
$OBJCOPY --set-section-flags .text=alloc,load,readonly,code \
--adjust-section-vma .text=0xbfc00000 $TMPFILE \
romsimos.elf
}
function run_simos
{
# run simos
export SIMOS_FLASH=$WRITE_FLASH_OUT;
export SIMOS_VIRAGE2=v2.hex;
echo r | $SIMOS_BIN
}
#
# functions to drive the specific simulation
#
# The first arg must be the rom binary (full path), while the remainder
# are consistent with what package_loadapp expects.
function build_appload {
build_v2
build_simos_bootrom
package_rom $1
if [[ -a $BB_CRL_FILE ]]; then
cp $BB_CRL_FILE /tmp/crl.sys
create_bootable_nand_file ticket.sys $BB_CERTS_FILE \
$SYSAPP_LOADED_ROM_AES /tmp/crl.sys
rm -f /tmp/crl.sys
else
create_bootable_nand_file ticket.sys $BB_CERTS_FILE $SYSAPP_LOADED_ROM_AES
fi
}
# used to simulate with server generated content and secure bundle.
#
function build_server_test {
build_v2
build_simos_bootrom
create_server_nand_file $SERVER_TIK_FILE $SERVER_CERTS_FILE \
$SERVER_GAME_FILE
}
function cleanup {
make clobber
rm -f $V2_TMPFILE romsimos.elf rom.bin $WRITE_FLASH_OUT \
$BB_CERT $BB_ECCCERT $TMPFILE
}
function usage {
echo "testsk [-s] [-S] [-m] <build_type>"
echo " where -s runs simos after building,"
echo " -S builds with the server PKI,"
echo " -m build for dram memory debug output, and"
echo " build_type may be:"
echo " appload clean."
echo " NOTE: rtl runs the rtl simulator, so -s"
echo " should not be used for this build."
exit 1
}
#
# Entry for script processing
#
simos_sim=false
dram_log=false
server_pki=false
while getopts "smS" a
do
case $a in
s) simos_sim=true;;
m) dram_log=true;;
S) server_pki=true;;
*) usage;;
esac
done
shift $(($OPTIND - 1))
if (($# < 1)); then
echo "build_type argument is mandatory."
usage
exit 1
fi
SK_DRAM_LOG="SK_LOG_RDB=1"
if [[ $dram_log = true ]]; then
SK_DRAM_LOG="SK_LOG_MEM=1"
fi
SK_SERVER_PKI=
if [[ $server_pki = true ]]; then
SK_SERVER_PKI="SK_SERVER_PKI=1"
fi
# other args that may be included for SK_MAKE_ARGS:
# DEBUG=1
# NO_ECC_KEYGEN=1
SK_MAKE_ARGS="$SK_DRAM_LOG $SK_SERVER_PKI"
if [[ $1 = appload ]]; then
cleanup
make exports $SK_MAKE_ARGS || (echo "failed to build SK lib" && exit 1)
# $2, below, should be full path to rom we're going to load
build_appload $2
elif [[ $1 = server ]]; then
# precede with content pub ritual on server side to produce
# sk/sysapp and content. set SERVER_ defines accordingly.
if [[ -n $bbid_local || -n $bbprivkey_local ]]; then
echo Must set env BBID and BB_PRIV_KEY to match server target BB
exit 1
fi
build_server_test
elif [[ $1 = clean ]]; then
cleanup
else
echo "must supply an arg: simos, rtl, clean\n"
exit 1
fi
if [[ $simos_sim = true ]]; then
run_simos
fi