Hi @Harvey021 ! Thank you for the reply.
> Please let me know what bsp version you have built with?
I'm using uboot/optee/imx-boot based on the lf-5.10.35-2.0.0 tag. It's not built with yocto, but versions and config are the same.
> Have you Built OP-TEE to support DEK blob encapsulation?
I have added the following settings for uboot as documented:
CONFIG_IMX_HAB=y
CONFIG_CMD_DEKBLOB=y
CONFIG_IMX_OPTEE_DEK_ENCAP=y
CONFIG_CMD_PRIBLOB=y
For optee, the documentation mentions `CFG_NXPCRYPT=y CFG_GEN_DEK_BLOB=y` but there is no mention of these variables in the code or build system -- the generated binary is the same regardless of these environment variables. The variables are present in the older BSP release of optee up to 5.4 (4.14.98_2.2.0, 4.19.35_1.1.0 and 5.4.y-1.0.0) -- do I need to use these older BSP or backport from these versions?
encrypted uboot works including second stage so I assume this part works without optee support? or is optee support needed once optee started?
> I have checked your csf files. The address of blob in CSF should not start with 1. It should be the specific location of blob in memory.
I'm sorry, I was fixing my csf generation script when I wrote this post and I pasted an old version with an incorrect blob address. It should read `Blob Address = 0x41581020` (that is, linux kernel load address + linux kernel size (padded) + ivt size as it is where I put the dek blob. the ivt is pointed at in hab_auth_img, csf pointed at through ivt, and dek blob pointed at through csf)
Are there restrictions to where the dek blob should be?
For confirmation there should be no difference other than Blob address from previous message but here are my csf again with the binary dump of the csf as well in case that helps.
$ cat Image.csf_linux_enc.txt
[Header]
Version = 4.3
Hash Algorithm = sha256
Engine = CAAM
Engine Configuration = 0
Certificate Format = X509
Signature Format = CMS
[Install SRK]
File = "../cst-3.3.1-ecc-384//crts/SRK_1_2_3_4_table.bin"
Source index = 0
[Install CSFK]
File = "../cst-3.3.1-ecc-384//crts/CSF1_1_sha256_secp384r1_v3_usr_crt.pem"
[Authenticate CSF]
[Install Key]
Verification index = 0
Target index = 2
File = "../cst-3.3.1-ecc-384//crts/IMG1_1_sha256_secp384r1_v3_usr_crt.pem"
[Authenticate Data]
Verification index = 2
Blocks = 0x40480000 0 0x1000 "../secureboot/Image_signing.bin"
[Unlock]
Engine = CAAM
Features = MID
[Install Secret Key]
Verification Index = 0
Target Index = 0
Key = "../secureboot/Image.dek_linux.bin"
Key Length = 256
# Authenticate Start Address + SPL & DDR FW image length + CSF Padding
Blob Address = 0x41527020
[Decrypt Data]
# The decrypt data command below causes CST to modify the input
# file and encrypt the specified block of data. This image file
# is a copy of the file used for the authentication command above
Verification Index = 0
Mac Bytes = 16
# Start Address = Start Address + SPL header
# Offset = Image offset (image_off) = 0x40
# Decrypt size = Image length - SPL header
Blocks = 0x40481000 0x1000 0xe68000 "../secureboot/Image_signing.enc"
$ cat Image.csf_linux_sign_enc.txt
[Header]
Version = 4.3
Hash Algorithm = sha256
Engine = CAAM
Engine Configuration = 0
Certificate Format = X509
Signature Format = CMS
[Install SRK]
File = "../cst-3.3.1-ecc-384//crts/SRK_1_2_3_4_table.bin"
Source index = 0
[Install CSFK]
File = "../cst-3.3.1-ecc-384//crts/CSF1_1_sha256_secp384r1_v3_usr_crt.pem"
[Authenticate CSF]
[Install Key]
Verification index = 0
Target index = 2
File = "../cst-3.3.1-ecc-384//crts/IMG1_1_sha256_secp384r1_v3_usr_crt.pem"
[Authenticate Data]
Verification index = 2
Blocks = 0x40480000 0 0x10a7020 "../secureboot/Image_signing.enc"
[Unlock]
Engine = CAAM
Features = MID
[Install Secret Key]
Verification Index = 0
Target Index = 0
Key = "../secureboot/Image.dek_linux.bin.dummy"
Key Length = 256
# Authenticate Start Address + SPL & DDR FW image length + CSF Padding
Blob Address = 0x41527020
[Decrypt Data]
# The decrypt data command below causes CST to modify the input
# file and encrypt the specified block of data. This image file
# is a copy of the file used for the authentication command above
Verification Index = 0
Mac Bytes = 16
# Start Address = Start Address + SPL header
# Offset = Image offset (image_off) = 0x40
# Decrypt size = Image length - SPL header
Blocks = 0x40481000 0x1000 0xe68000 "../secureboot/Image_signing.enc.dummy"
$ xxd Image.csf_linux_sign_enc.bin
00000000: d400 7843 be00 0c00 0317 0000 0000 0078 ..xC...........x
00000010: be00 0c02 0900 0001 0000 022c ca00 0c00 ...........,....
00000020: 01c5 1d00 0000 042c be00 0c00 0900 0002 .......,........
00000030: 0000 058c ca00 1400 02c5 1d00 0000 078c ................
00000040: 4048 0000 010a 7020 b200 081d 0000 0001 @H....p ........
00000050: be00 0c01 bb00 0000 4152 7020 ca00 1400 ........ARp ....
00000060: 00a3 1d00 0000 08ec 4048 1000 00e6 8000 ........@H......
00000070: b200 081d 0000 0002 d701 b440 e100 6c27 ...........@..l'
00000080: 0000 0080 4d00 0180 4d73 421e 1de2 837d ....M...MsB....}
00000090: 040f 77c9 d980 0629 19a3 3927 14a0 0253 ..w....)..9'...S
000000a0: fb46 85f1 83cf 37d1 be71 d86a 428b 676d .F....7..q.jB.gm
000000b0: 17ad 3abc a8fe adc5 22ac 8a01 fcfd 33e7 ..:.....".....3.
000000c0: f4a1 4095 6077 1a37 b33d a163 00fe b58b ..@.`w.7.=.c....
000000d0: cb52 e1fb 8c51 37ff fad2 d9d0 6711 ab4e .R...Q7.....g..N
000000e0: 45f2 7c7c a7c4 a8eb e100 6c27 0000 0080 E.||......l'....
000000f0: 4d00 0180 a4f9 1733 6ed5 08a3 a651 2f1d M......3n....Q/.
00000100: 7592 6b3f 030f da8b 78eb 2e1d ed27 0729 u.k?....x....'.)
00000110: 783f f2b5 f038 1431 95d6 f257 fed1 d5d8 x?...8.1...W....
00000120: d4d1 9c2a 1e79 945c ceaf a4b8 f54d dc8c ...*.y.\.....M..
00000130: fb80 1ac3 c42a 0a3c bfed bd8b c718 388c .....*.<......8.
00000140: 74a9 167f d999 7c45 0386 104e 20ca f48c t.....|E...N ...
00000150: f958 cec9 e100 6c27 0000 0080 4d00 0180 .X....l'....M...
00000160: 3d0f a150 8978 695e c96c 4849 cda1 b545 =..P.xi^.lHI...E
00000170: 2bd1 e9c0 83e4 f22f ec7f a629 f941 a306 +....../...).A..
00000180: e2db ab7b ebf8 a54e dff8 da1f 74fb fdd8 ...{...N....t...
00000190: b2c3 2cac eabb 3523 8fb9 6dc2 ac94 a11a ..,...5#..m.....
000001a0: 0c4b ec05 6f35 288c 8fc0 55bb a884 a408 .K..o5(...U.....
000001b0: 1139 5ac9 7694 bf18 de3a d2f7 b492 ec79 .9Z.v....:.....y
000001c0: e100 6c27 0000 0080 4d00 0180 1188 3975 ..l'....M.....9u
000001d0: d9e6 5a2b 82ab 680f 4598 c207 5ecb aa21 ..Z+..h.E...^..!
000001e0: b740 6d4e 6aa2 6262 bbdc efb6 16ce e43f .@mNj.bb.......?
000001f0: a2dc fe06 6f9e c42a bffc 2e30 70e0 dd25 ....o..*...0p..%
00000200: 1553 2261 b027 23de 71ad bf5a a9d5 aaf2 .S"a.'#.q..Z....
00000210: 3c25 026f 5f89 30fb 691b b0bf 2bea 5ebe <%.o_.0.i...+.^.
00000220: b557 61c2 c6a1 ba2c d96d 082f d701 fe43 .Wa....,.m./...C
00000230: 3082 01f6 3082 017c a003 0201 0202 0101 0...0..|........
00000240: 300a 0608 2a86 48ce 3d04 0302 3026 3124 0...*.H.=...0&1$
00000250: 3022 0603 5504 030c 1b53 524b 315f 7368 0"..U....SRK1_sh
00000260: 6132 3536 5f73 6563 7033 3834 7231 5f76 a256_secp384r1_v
00000270: 335f 6361 301e 170d 3232 3034 3037 3033 3_ca0...22040703
00000280: 3539 3533 5a17 0d33 3230 3430 3430 3335 5953Z..320404035
00000290: 3935 335a 3029 3127 3025 0603 5504 030c 953Z0)1'0%..U...
000002a0: 1e43 5346 315f 315f 7368 6132 3536 5f73 .CSF1_1_sha256_s
000002b0: 6563 7033 3834 7231 5f76 335f 7573 7230 ecp384r1_v3_usr0
000002c0: 7630 1006 072a 8648 ce3d 0201 0605 2b81 v0...*.H.=....+.
000002d0: 0400 2203 6200 04dd 3712 c941 d052 1a5c ..".b...7..A.R.\
000002e0: 39d8 0c0e 755c e788 4cd2 d5f5 3b2c 8f6f 9...u\..L...;,.o
000002f0: 3f2a a4a7 2e80 23aa 3776 81ff 1224 8860 ?*....#.7v...$.`
00000300: cf4c 53bb 5cc6 f104 df0d e210 c36a a77c .LS.\........j.|
00000310: 031b 056c 6984 3aa9 a4bb bd73 c610 1dbd ...li.:....s....
00000320: 25e8 f2fc c87a c08c 1dd0 828e 3f84 cb48 %....z......?..H
00000330: 672c 5744 ba34 1ca3 7b30 7930 0906 0355 g,WD.4..{0y0...U
00000340: 1d13 0402 3000 302c 0609 6086 4801 86f8 ....0.0,..`.H...
00000350: 4201 0d04 1f16 1d4f 7065 6e53 534c 2047 B......OpenSSL G
00000360: 656e 6572 6174 6564 2043 6572 7469 6669 enerated Certifi
00000370: 6361 7465 301d 0603 551d 0e04 1604 1467 cate0...U......g
00000380: 90aa 6394 3927 bebe e72e d119 e60d 9e03 ..c.9'..........
00000390: 8afb ac30 1f06 0355 1d23 0418 3016 8014 ...0...U.#..0...
000003a0: 8599 c1e9 012d 1403 6d57 be7e 5049 55a2 .....-..mW.~PIU.
000003b0: eb2f cac7 300a 0608 2a86 48ce 3d04 0302 ./..0...*.H.=...
000003c0: 0368 0030 6502 3100 950f affc ce37 a2df .h.0e.1......7..
000003d0: 166a 0db1 f7ac 1613 91ca 731b c1f7 38ba .j........s...8.
000003e0: d899 9c61 6a4f 014f b05e c906 dcb6 871e ...ajO.O.^......
000003f0: c394 5c45 076e 93f7 0230 6f41 ac83 9c0e ..\E.n...0oA....
00000400: cedb a9a6 c11d d67c 23d6 4932 2a52 7000 .......|#.I2*Rp.
00000410: 79af 60a1 ed06 f820 697f bdbb d96d 0fdc y.`.... i....m..
00000420: 7657 6037 0460 1988 aa42 0000 d801 5f43 vW`7.`...B...._C
00000430: 3082 0157 0609 2a86 4886 f70d 0107 02a0 0..W..*.H.......
00000440: 8201 4830 8201 4402 0101 310d 300b 0609 ..H0..D...1.0...
00000450: 6086 4801 6503 0402 0130 0b06 092a 8648 `.H.e....0...*.H
00000460: 86f7 0d01 0701 3182 0121 3082 011d 0201 ......1..!0.....
00000470: 0130 2b30 2631 2430 2206 0355 0403 0c1b .0+0&1$0"..U....
00000480: 5352 4b31 5f73 6861 3235 365f 7365 6370 SRK1_sha256_secp
00000490: 3338 3472 315f 7633 5f63 6102 0101 300b 384r1_v3_ca...0.
000004a0: 0609 6086 4801 6503 0402 01a0 6930 1806 ..`.H.e.....i0..
000004b0: 092a 8648 86f7 0d01 0903 310b 0609 2a86 .*.H......1...*.
000004c0: 4886 f70d 0107 0130 1c06 092a 8648 86f7 H......0...*.H..
000004d0: 0d01 0905 310f 170d 3232 3035 3331 3032 ....1...22053102
000004e0: 3031 3132 5a30 2f06 092a 8648 86f7 0d01 0112Z0/..*.H....
000004f0: 0904 3122 0420 261d 0ec6 56a9 2be6 162b ..1". &...V.+..+
00000500: a22a b2e8 d49d af09 df67 20cb d118 ac95 .*.......g .....
00000510: 7dc1 d57e e9c8 300a 0608 2a86 48ce 3d04 }..~..0...*.H.=.
00000520: 0302 0467 3065 0230 2e95 388d b3ea 3ecf ...g0e.0..8...>.
00000530: e812 a3d2 a192 56b0 f5c6 50bf fcc4 b0ba ......V...P.....
00000540: 577b 1960 36ca c68e fc0d 32bb 0a93 f08b W{.`6.....2.....
00000550: a979 b42c 1b6c 05e2 0231 00d0 9c34 937f .y.,.l...1...4..
00000560: d420 a373 f7ac 2566 4fd1 8fd9 3e0b 6fac . .s..%fO...>.o.
00000570: b6e1 d4bf 858b bfe3 65d6 2913 a93f b499 ........e.)..?..
00000580: 2be8 0e63 fb11 2732 59d8 3100 d701 fe43 +..c..'2Y.1....C
00000590: 3082 01f6 3082 017c a003 0201 0202 0102 0...0..|........
000005a0: 300a 0608 2a86 48ce 3d04 0302 3026 3124 0...*.H.=...0&1$
000005b0: 3022 0603 5504 030c 1b53 524b 315f 7368 0"..U....SRK1_sh
000005c0: 6132 3536 5f73 6563 7033 3834 7231 5f76 a256_secp384r1_v
000005d0: 335f 6361 301e 170d 3232 3034 3037 3033 3_ca0...22040703
000005e0: 3539 3533 5a17 0d33 3230 3430 3430 3335 5953Z..320404035
000005f0: 3935 335a 3029 3127 3025 0603 5504 030c 953Z0)1'0%..U...
00000600: 1e49 4d47 315f 315f 7368 6132 3536 5f73 .IMG1_1_sha256_s
00000610: 6563 7033 3834 7231 5f76 335f 7573 7230 ecp384r1_v3_usr0
00000620: 7630 1006 072a 8648 ce3d 0201 0605 2b81 v0...*.H.=....+.
00000630: 0400 2203 6200 0481 6d7f 36b3 9485 4ef1 ..".b...m.6...N.
00000640: 33b8 4c76 4377 8da3 29c5 3096 5e8a 6587 3.LvCw..).0.^.e.
00000650: ef63 d034 2256 bdcf 8893 086d 81c3 604f .c.4"V.....m..`O
00000660: d560 e4d3 f1fe 5760 de47 383c da00 221e .`....W`.G8<..".
00000670: 310b 9826 d39a 7488 123b 00dd 4dd1 f9a5 1..&..t..;..M...
00000680: 3156 e117 e281 237a d2fe c5be 0970 27cf 1V....#z.....p'.
00000690: 2cb4 abbf 60af 63a3 7b30 7930 0906 0355 ,...`.c.{0y0...U
000006a0: 1d13 0402 3000 302c 0609 6086 4801 86f8 ....0.0,..`.H...
000006b0: 4201 0d04 1f16 1d4f 7065 6e53 534c 2047 B......OpenSSL G
000006c0: 656e 6572 6174 6564 2043 6572 7469 6669 enerated Certifi
000006d0: 6361 7465 301d 0603 551d 0e04 1604 1463 cate0...U......c
000006e0: 8e52 8758 97c0 d388 1fe8 a20a f11f 89b5 .R.X............
000006f0: 20e7 c030 1f06 0355 1d23 0418 3016 8014 ..0...U.#..0...
00000700: 8599 c1e9 012d 1403 6d57 be7e 5049 55a2 .....-..mW.~PIU.
00000710: eb2f cac7 300a 0608 2a86 48ce 3d04 0302 ./..0...*.H.=...
00000720: 0368 0030 6502 3100 b985 7caa 3817 4480 .h.0e.1...|.8.D.
00000730: 46c1 f517 40c2 cb50 10f3 ee8c 14c2 9ae6 F...@..P........
00000740: 8438 4b2e 2018 dd2f a79b b58c bafb 3ac2 .8K. ../......:.
00000750: bf68 0716 158d 5831 0230 07ca a316 f8e4 .h....X1.0......
00000760: 329b c3fd c46e 6264 9e8a 0971 5330 bb69 2....nbd...qS0.i
00000770: 1a8a d70e 0965 d327 b476 b35b 75b0 a9fd .....e.'.v.[u...
00000780: da47 abd1 38f6 0693 766e 0000 d801 5f43 .G..8...vn...._C
00000790: 3082 0157 0609 2a86 4886 f70d 0107 02a0 0..W..*.H.......
000007a0: 8201 4830 8201 4402 0101 310d 300b 0609 ..H0..D...1.0...
000007b0: 6086 4801 6503 0402 0130 0b06 092a 8648 `.H.e....0...*.H
000007c0: 86f7 0d01 0701 3182 0121 3082 011d 0201 ......1..!0.....
000007d0: 0130 2b30 2631 2430 2206 0355 0403 0c1b .0+0&1$0"..U....
000007e0: 5352 4b31 5f73 6861 3235 365f 7365 6370 SRK1_sha256_secp
000007f0: 3338 3472 315f 7633 5f63 6102 0102 300b 384r1_v3_ca...0.
00000800: 0609 6086 4801 6503 0402 01a0 6930 1806 ..`.H.e.....i0..
00000810: 092a 8648 86f7 0d01 0903 310b 0609 2a86 .*.H......1...*.
00000820: 4886 f70d 0107 0130 1c06 092a 8648 86f7 H......0...*.H..
00000830: 0d01 0905 310f 170d 3232 3035 3331 3032 ....1...22053102
00000840: 3031 3132 5a30 2f06 092a 8648 86f7 0d01 0112Z0/..*.H....
00000850: 0904 3122 0420 c94e b3a2 7a54 b3ee a582 ..1". .N..zT....
00000860: 02c1 6e7b f445 942f 20d2 64a4 1d04 8760 ..n{.E./ .d....`
00000870: 95f7 af18 3164 300a 0608 2a86 48ce 3d04 ....1d0...*.H.=.
00000880: 0302 0467 3065 0231 0080 1367 70de e6d8 ...g0e.1...gp...
00000890: 1eae c81e e545 e7cc 082f acd4 0ac6 0527 .....E.../.....'
000008a0: 0d35 b50d 2e7b 70a0 ac8d 3344 8378 b77b .5...{p...3D.x.{
000008b0: c782 e32c a3af f1e0 e002 300f 2cc5 418e ...,......0.,.A.
000008c0: ee4d 7240 1c95 ef65 bb70 b4b2 d87b 2361 .Mr@...e.p...{#a
000008d0: 539d b2e7 accd 4d34 273b 93e7 64e4 c430 S.....M4';..d..0
000008e0: 296a a63f ae04 c557 df46 bb00 ac00 2443 )j.?...W.F....$C
000008f0: 000c 0010 0b87 f772 c9fb f3cb e4e4 d8c1 .......r........
00000900: 23c9 b260 542d b8a1 4779 cfca 1ef1 33f7 #..`T-..Gy....3.
> And share your steps of what you have generated the dek_blob.
It should match what I had described in my original post, here are the commands I used:
cp "$OUT/Image_signing.bin" "$OUT/Image_signing.enc" \
|| error "Could not copy Image_signing.bin"
"$CST/linux64/bin/cst" -i "$OUT/Image.csf_linux_enc.txt" -o "$OUT/Image.csf_linux_enc.bin" \
|| error "Could not sign csf linux enc"
cp "$OUT/Image_signing.enc" "$OUT/Image_signing.enc.dummy" \
|| error "Could not copy Image_signing.bin.dummy"
"$CST/linux64/bin/cst" -i "$OUT/Image.csf_linux_sign_enc.txt" -o "$OUT/Image.csf_linux_sign_enc.bin" \
|| error "Could not sign csf linux sign enc"
rm -f "$OUT/Image_signing.enc.dummy" "$OUT/Image.dek_linux.bin.dummy"
# copy encrypted nonce
local offset_in offset_out
offset_in=$(stat -c "%s" "$OUT/Image.csf_linux_enc.bin")
[[ -n "$offset_in" ]] || error "Could not get csf_linux_enc.bin size"
offset_in=$((offset_in - 36))
offset_out=$(stat -c "%s" "$OUT/Image.csf_linux_sign_enc.bin")
[[ -n "$offset_out" ]] || error "Could not get csf_linux_sign_enc.bin size"
offset_out=$((offset_out - 36))
echo "copying csf_linux_enc.bin $offset_in -> csf_linux_sign_enc.bin $offset_out 36 bytes"
dd if="$OUT/Image.csf_linux_enc.bin" of="$OUT/Image.csf_linux_sign_enc.bin" \
status=none bs=36 count=1 \
iflag=skip_bytes oflag=seek_bytes \
skip="$offset_in" seek="$offset_out" \
|| error "Could not copy nonce/mac to csf_linux_sign_enc"
# append csf to image
cat "$OUT/Image.csf_linux_sign_enc.bin" >> "$OUT/Image_signing.enc" \
|| error "Could not append to $OUT/Image_signing.enc"
# copy DEK at proper offset
printf "linux DEK offset: %x\n" "$((linux_size + 0x20))"
dd if="$OUT/Image.dek_linux.bin" of="$OUT/Image_signing.enc" \
status=none seek=$((linux_size+0x20)) oflag=seek_bytes bs=4k conv=notrunc
after this, I copy the image to a fixed offset in /dev/mmcblk2boot0 and fix the dek blob:
# dek offset was 0x10a7020 and the image is 5MB inside the the device:
# printf "%x\n" $((5*2048+0x10a7020/512))
# ad38
u-boot=> mmc dev 2 1
u-boot=> mmc read 0x40800000 ad38 1
u-boot=> md 0x40800020 # non-transformed dek blob
40800020: 573df35e 4b27aa81 85a6d67c 564f8737 ^.=W..'K|...7.OV
40800030: a8864555 b5c0e31b 83434018 8eb87d32 UE.......@C.2}..
40800040: 00000000 00000000 00000000 00000000 ................
40800050: 00000000 00000000 00000000 00000000 ................
40800060: 00000000 00000000 00000000 00000000 ................
40800070: 00000000 00000000 00000000 00000000 ................
40800080: 437800d4 000c00be 00001703 78000000 ..xC...........x
40800090: 020c00be 01000009 2c020000 000c00ca ...........,....
408000a0: 001dc501 2c040000 000c00be 02000009 .......,........
408000b0: 8c050000 001400ca 001dc502 8c070000 ................
408000c0: 00004840 20700a01 1d0800b2 01000000 @H....p ........
408000d0: 010c00be 000000bb 20705241 001400ca ........ARp ....
408000e0: 001da300 ec080000 00104840 0080e600 ........@H......
408000f0: 1d0800b2 02000000 40b401d7 276c00e1 ...........@..l'
40800100: 80000000 8001004d 1e42734d 7d83e21d ....M...MsB....}
40800110: c9770f04 290680d9 2739a319 5302a014 ..w....)..9'...S
u-boot=> cp 0x40800020 0x40400000 8
u-boot=> dek_blob 0x40400000 0x40800020 256
u-boot=> md 0x40800020 # actual dek blob
40800020: 43580081 00205566 15296475 dcaf95c8 ..XCfU .ud).....
40800030: 7a528b3c 23c74605 059adf2b 17719616 <.Rz.F.#+.....q.
40800040: 82a00a6b a3a5289b 8233afb8 02af2615 k....(....3..&..
40800050: 3625eeca fccbfc19 c6a57680 a05b734c ..%6.....v..Ls[.
40800060: b923b5c4 27755513 046fa9ad 4ba3aa72 ..#..Uu'..o.r..K
40800070: 66e79cbc 2510cad4 00000000 00000000 ...f...%........
40800080: 437800d4 000c00be 00001703 78000000 ..xC...........x
40800090: 020c00be 01000009 2c020000 000c00ca ...........,....
408000a0: 001dc501 2c040000 000c00be 02000009 .......,........
408000b0: 8c050000 001400ca 001dc502 8c070000 ................
408000c0: 00004840 20700a01 1d0800b2 01000000 @H....p ........
408000d0: 010c00be 000000bb 20705241 001400ca ........ARp ....
408000e0: 001da300 ec080000 00104840 0080e600 ........@H......
408000f0: 1d0800b2 02000000 40b401d7 276c00e1 ...........@..l'
40800100: 80000000 8001004d 1e42734d 7d83e21d ....M...MsB....}
40800110: c9770f04 290680d9 2739a319 5302a014 ..w....)..9'...S
u-boot=> mmc write 0x40800000 ad38 1
u-boot=> run loadimage
u-boot=> md 0x41527020 # correct blob address in csf
41527020: 43580081 00205566 15296475 dcaf95c8 ..XCfU .ud).....
41527030: 7a528b3c 23c74605 059adf2b 17719616 <.Rz.F.#+.....q.
41527040: 82a00a6b a3a5289b 8233afb8 02af2615 k....(....3..&..
41527050: 3625eeca fccbfc19 c6a57680 a05b734c ..%6.....v..Ls[.
41527060: b923b5c4 27755513 046fa9ad 4ba3aa72 ..#..Uu'..o.r..K
41527070: 66e79cbc 2510cad4 00000000 00000000 ...f...%........
41527080: 437800d4 000c00be 00001703 78000000 ..xC...........x
41527090: 020c00be 01000009 2c020000 000c00ca ...........,....
415270a0: 001dc501 2c040000 000c00be 02000009 .......,........
415270b0: 8c050000 001400ca 001dc502 8c070000 ................
415270c0: 00004840 20700a01 1d0800b2 01000000 @H....p ........
415270d0: 010c00be 000000bb 20705241 001400ca ........ARp ....
415270e0: 001da300 ec080000 00104840 0080e600 ........@H......
415270f0: 1d0800b2 02000000 40b401d7 276c00e1 ...........@..l'
41527100: 80000000 8001004d 1e42734d 7d83e21d ....M...MsB....}
41527110: c9770f04 290680d9 2739a319 5302a014 ..w....)..9'...S
So the dek blob is indeed written at the correct address in memory.
I have fixed hab event parsing (patch below), this is actually helpful as the second hab event actually makes sense (something in the caam engine failed) -- perhaps you can make more use of it than me. (10a7990 is the file size, 10a7000 is the offset to the ivt within the file.
u-boot=> hab_auth_img 0x40480000 10a7990 10a7000
Authenticate image from DDR location 0x40480000...
Secure boot enabled
HAB Configuration: 0xcc, HAB State: 0x99
--------- HAB Event 1 -----------------
event data:
0xdb 0x00 0x14 0x45 0x33 0x3a 0xc0 0x00
0xbe 0x00 0x0c 0x01 0xbb 0x00 0x00 0x00
0x41 0x52 0x70 0x20
STS = HAB_FAILURE (0x33)
RSN = INVALID
CTX = HAB_CTX_COMMAND (0xC0)
ENG = HAB_ENG_ANY (0x00)
--------- HAB Event 2 -----------------
event data:
0xdb 0x00 0x24 0x45 0x33 0x30 0xc0 0x1d
0x10 0x02 0x11 0x22 0x40 0x00 0x08 0x16
0x55 0x55 0x00 0x0f 0x00 0x10 0x20 0x00
0x00 0x00 0x00 0x01 0x91 0x00 0x88 0x0e
0x00 0x00 0x02 0x05
STS = HAB_FAILURE (0x33)
RSN = HAB_ENG_FAIL (0x30)
CTX = HAB_CTX_COMMAND (0xC0)
ENG = HAB_ENG_CAAM (0x1D)
FWIW, here's the uboot patch I used, with two fixes:
- sts_str did not correspond to hab_statuses. It just happened to work out for HAB_FAILURE because it was in 2nd slot in both cases
- get_idx would fail to recognize the -1 and never end the loop
- even when it did, it didn't return idx but an out of range index; it should return the last string entry invalid at index -1 in the enum list.
diff --git a/arch/arm/mach-imx/hab.c b/arch/arm/mach-imx/hab.c
index 664444bfea5e..cea4b78caaee 100644
--- a/arch/arm/mach-imx/hab.c
+++ b/arch/arm/mach-imx/hab.c
@@ -280,9 +280,10 @@ static char *rsn_str[] = {
};
static char *sts_str[] = {
- "STS = HAB_SUCCESS (0xF0)\n",
+ "STS = HAB_ANY (0x00)\n",
"STS = HAB_FAILURE (0x33)\n",
"STS = HAB_WARNING (0x69)\n",
+ "STS = HAB_SUCCESS (0xF0)\n",
"STS = INVALID\n",
NULL
};
@@ -398,12 +399,12 @@ static inline uint8_t get_idx(uint8_t *list, uint8_t tgt)
{
uint8_t idx = 0;
uint8_t element = list[idx];
- while (element != -1) {
+ while (element != (uint8_t)-1) {
if (element == tgt)
return idx;
element = list[++idx];
}
- return -1;
+ return idx;
}
... with which CTX_FAB = 0xff starts matching the -1 used for end of list, so we need to switch it to another value or extend the type size...
I've switched to 0xfe which isn't used anywhere I could see, even if it's a bit ugly:
diff --git a/arch/arm/mach-imx/hab.c b/arch/arm/mach-imx/hab.c
index cea4b78caaee..583da4ed2fb2 100644
--- a/arch/arm/mach-imx/hab.c
+++ b/arch/arm/mach-imx/hab.c
@@ -329,7 +329,7 @@ static uint8_t hab_statuses[5] = {
HAB_FAILURE,
HAB_WARNING,
HAB_SUCCESS,
- -1
+ 0xFE
};
static uint8_t hab_reasons[26] = {
@@ -358,7 +358,7 @@ static uint8_t hab_reasons[26] = {
HAB_UNS_KEY,
HAB_UNS_PROTOCOL,
HAB_UNS_STATE,
- -1
+ 0xFE
};
static uint8_t hab_contexts[12] = {
@@ -373,7 +373,7 @@ static uint8_t hab_contexts[12] = {
HAB_CTX_AUT_DAT,
HAB_CTX_ASSERT,
HAB_CTX_EXIT,
- -1
+ 0xFE
};
static uint8_t hab_engines[16] = {
@@ -392,14 +392,14 @@ static uint8_t hab_engines[16] = {
HAB_ENG_HDCP,
HAB_ENG_RTL,
HAB_ENG_SW,
- -1
+ 0xFE
};
static inline uint8_t get_idx(uint8_t *list, uint8_t tgt)
{
uint8_t idx = 0;
uint8_t element = list[idx];
- while (element != (uint8_t)-1) {
+ while (element != 0xFE) {
if (element == tgt)
return idx;
element = list[++idx];
well, it's not the problem here anyway, but it might help to have proper diagnostic.
Thanks again for looking!