betrusted-io / betrusted-scripts

Shell scripts for debugging and flashing betrusted
GNU General Public License v3.0
4 stars 6 forks source link

jtag_gpio.py no longer sets the BBRAM Key #10

Closed dylangerdaly closed 1 year ago

dylangerdaly commented 1 year ago

Hey everyone,

I've been attempting to setup my BBRAM Key on my precursor, I'd ultimately like to blow my AES key into eFuses however there's no documentation on how to do this yet.

I've been following https://github.com/betrusted-io/betrusted-wiki/wiki/FAQ:-FPGA-AES-Encryption-Key-(eFuse-BBRAM)#use-the-key-without-build-environment

I've managed to sign my own FPGA Bitstream and generate a soc_csr.bin, however I when I run ./jtag_gpio.py -f my_key.jtg on my generated jtg file, nothing happens (even after running it with -d to make sure it's doing something), even after I reset_soc.sh.

When I load my own soc_csr.bn precursor will hang, I assume this is because the BBRAM Key isn't set, so it's failing to decrypt the new FPGA Bitstream, if I load a nullkey'd soc_csr.bin from the CI Server it'll boot normally, then if I re-run ./jtag_gpio.py -f my_key.jtg and reset the SoC, it'll still boot, when I expect it not to, because the BBRAM Key shouldn't be the null key.

There also appears to be another way to provision BBRAM Keys, bbram_helper.py, however this method doesn't seem to work and seems to be more complex, I'd prefer to use jtag_gpio if possible

I have another few Qs here if that's okay

  1. Am I able to get a quick little step guide on how to blow my own eFuses as I'd like to remove the JTAG cable and epoxy it up, eventually I'd also like to setup my own Xous Signing Keys to remove the little dotted lines
  2. If I set my own eFuse AES Key OR BBRAM Key, am I still able to update the bitstream without having to use JTAG?
  3. If my understanding is correct, I'm okay to use a BBRAM Key, as long as I do a full backup anytime a secret is added to Precursor

Cheers!

bunnie commented 1 year ago

The bbram_helper.py method should work, I've had reports of it working from multiple users.

Is it possible for you to share a sample of the output of ./jtag_gpio.py -d -f my_key.jtg here? obviously it would have key data in it so you'd want to use a throw-away key, but seeing that output would help me casually inspect if the AES key is being inserted or not.

I'm thinking maybe the most likely issue is that maybe this command isn't doing the right thing:

python ./deps/encrypt-bitstream-python/encrypt-bitstream.py --bbram -f build/gateware/betrusted_soc.bin -i dummy.nky -k my_key.nky -o my_encrypted -p keystore.patch

it's possible that this has bit-rotted somewhat because it hasn't been maintained in a while (please note that you are in fact following a set of "legacy instructions" that were deprecated in favor of the bbram_helper.py method). What this script does is take the default bitstream and re-encrypt that bitstream to your new key. Most importantly, it's supposed to change out the configuration bits of the bitstream so that the FPGA knows to retrieve the decryption key from the BBRAM instead of from the eFuse or other bank.

There were some small changes to the header format along the way and I bet this script is outputting an old version of the header format that's incompatible with the current toolchain, and when you try to boot with that image it's not looking for the BBRAM key anymore.

Debugging that would have to wait until I'm back in my lab next week (I'm still trapped overseas because I had limited options for rebooking my flights). But, I might be able to make some progress if you can share with me the contents of

`hexdump -C soc_csr.bin | head -100'

after you have run these two commands

python ./deps/encrypt-bitstream-python/encrypt-bitstream.py --bbram -f build/gateware/betrusted_soc.bin -i dummy.nky -k my_key.nky -o my_encrypted -p keystore.patch
python ./append_csr.py -b ./my_encrypted.bin -c ./build/csr.csv -o ./soc_csr.bin

note that my_encrypted.bin should overwrite the original soc_csr.bin file with this sequence of commands, so I'm interested in the overwritten version that is output at the end, and not what was put into the sequence of commands.

The first 100 lines of the binary file would give me an idea of what's going on with the bitstream header, I can compare that against the current toolchain output and maybe visually identify the problem.

One thing I'd note is that with this legacy flow, the encyption key is derived using your local computer's random number generator. So you're not using the TRNG inside of Precursor, you're trusting your local machine to generate a very important secret, so you should make sure your local RNG is configured correctly. The bbram_helper.py script actually pulls the random number for the key out of the Precursor's TRNG, so it does not have that problem.

Answers to other questions:

  1. The eFuse blowing routine should "just work" now in the latest Xous release. The flow is self-guided and it should work without need of the JTAG port, but I'd recommend running it first before gluing anything up. If you do run the flow, I'd appreciate positive confirmation that it was successful. I have not received any reports of failures, but also, only a few have run the efuse flow that I know of.
  2. If your AES key is set, you can absolutely update without using JTAG. When a SoC update happens, it is staged in its "null key" encrypted form to a region of FLASH, and the device re-encrypts and writes it to the "live" location with the proper keys
  3. I'm not sure about what you mean by this one -- if you're using the BBRAM key, the Precursor should operate perfectly normally and not require a backup to add any secrets. However, you are recommended to do regular backups with a BBRAM flow simply because the key is volatile -- if you let the device discharge fully, or perhaps you drop the device and the battery contact disconnects briefly, the key is cleared, and you would need to restore from a backup in that case.

I personally use the BBRAM flow because I like the peace of mind of knowing that eventually the key zeroizes itself in the case that the device is lost or misplaced, but I also backup the device monthly just because the volatile key is fragile by design.

dylangerdaly commented 1 year ago

Hey! Welcome back :+1:

Absolutely, here's the output for both commands

pi@raspberrypi:~/betrusted-scripts/jtag-tools $ ./jtag_gpio.py -d -f ../my_keebyjeebies.jtg
Executing .jtg command file: ../my_keebyjeebies.jtg
DEBUG:root:start: [<JtagLeg.RS: 2>, '0', '0'] () / 0
DEBUG:root:tms reset
DEBUG:root:start: [<JtagLeg.DL: 3>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.IR: 1>, '001011', ' jpgrogram'] (JPROGRAM) /  jpgrogram
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.IR: 1>, '010100', ' isc_noop'] (ISC_NOOP) /  isc_noop
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.IR: 1>, '010100', ' isc_noop'] (ISC_NOOP) /  isc_noop
DEBUG:root:result: 0x3f
DEBUG:root:IR bypassing wait state
DEBUG:root:start: [<JtagLeg.IRP: 5>, '010000', ' isc_enable'] (ISC_ENABLE) /  isc_enable
DEBUG:root:pause
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '10101', ' '] () /  
DEBUG:root:result: 0x1f
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.DR: 0>, '10101', ' '] () /  
DEBUG:root:result: 0x1f
DEBUG:root:start: [<JtagLeg.IR: 1>, '010010', ' program_key'] (XSC_PROGRAM_KEY) /  program_key
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.DR: 0>, '11111111111111111111111111111111', ' '] () /  
DEBUG:root:result: 0xffffffff
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.IR: 1>, '010001', ' isc_program'] (ISC_PROGRAM) /  isc_program
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '00000000000000000101010101111011', ' '] () /  
DEBUG:root:result: 0xffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010001', ' isc_program'] (ISC_PROGRAM) /  isc_program
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '00111001110011000001011101101100', ' '] () /  
DEBUG:root:result: 0xffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010001', ' isc_program'] (ISC_PROGRAM) /  isc_program
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '00100000010111011010000011111010', ' '] () /  
DEBUG:root:result: 0xffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010001', ' isc_program'] (ISC_PROGRAM) /  isc_program
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '10100100100011000010110000000100', ' '] () /  
DEBUG:root:result: 0xffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010001', ' isc_program'] (ISC_PROGRAM) /  isc_program
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '00111111000001010011110110001010', ' '] () /  
DEBUG:root:result: 0xffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010001', ' isc_program'] (ISC_PROGRAM) /  isc_program
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '11101111100010100101100100110000', ' '] () /  
DEBUG:root:result: 0xffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010001', ' isc_program'] (ISC_PROGRAM) /  isc_program
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '01000100101111111110001111110001', ' '] () /  
DEBUG:root:result: 0xffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010001', ' isc_program'] (ISC_PROGRAM) /  isc_program
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '10010111111111011000000111110110', ' '] () /  
DEBUG:root:result: 0xffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010001', ' isc_program'] (ISC_PROGRAM) /  isc_program
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '00011001101101111010100101100010', ' '] () /  
DEBUG:root:result: 0xffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010101', ' bbkey_rbk'] () /  bbkey_rbk
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '1111111111111111111111111111111111111', ' '] () /  
DEBUG:root:result: 0x1fffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010101', ' bbkey_rbk'] () /  bbkey_rbk
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '1111111111111111111111111111111111111', ' '] () /  
DEBUG:root:result: 0x1fffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010101', ' bbkey_rbk'] () /  bbkey_rbk
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '1111111111111111111111111111111111111', ' '] () /  
DEBUG:root:result: 0x1fffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010101', ' bbkey_rbk'] () /  bbkey_rbk
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '1111111111111111111111111111111111111', ' '] () /  
DEBUG:root:result: 0x1fffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010101', ' bbkey_rbk'] () /  bbkey_rbk
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '1111111111111111111111111111111111111', ' '] () /  
DEBUG:root:result: 0x1fffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010101', ' bbkey_rbk'] () /  bbkey_rbk
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '1111111111111111111111111111111111111', ' '] () /  
DEBUG:root:result: 0x1fffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010101', ' bbkey_rbk'] () /  bbkey_rbk
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '1111111111111111111111111111111111111', ' '] () /  
DEBUG:root:result: 0x1fffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010101', ' bbkey_rbk'] () /  bbkey_rbk
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '1111111111111111111111111111111111111', ' '] () /  
DEBUG:root:result: 0x1fffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010101', ' bbkey_rbk'] () /  bbkey_rbk
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DR: 0>, '1111111111111111111111111111111111111', ' '] () /  
DEBUG:root:result: 0x1fffffffff
DEBUG:root:start: [<JtagLeg.IR: 1>, '010110', ' isc_disable'] (ISC_DISABLE) /  isc_disable
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.RS: 2>, '0', '0'] () / 0
DEBUG:root:tms reset
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.ID: 4>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.IR: 1>, '111111', ' bypass'] (BYPASS) /  bypass
DEBUG:root:result: 0x3f
DEBUG:root:start: [<JtagLeg.DL: 3>, '0', '0'] () / 0
DEBUG:root:start: [<JtagLeg.IR: 1>, '111111', ' bypass'] (BYPASS) /  bypass
DEBUG:root:result: 0x3f

With test key of 39cc176c205da0faa48c2c043f053d8aef8a593044bfe3f197fd81f619b7a962

pi@raspberrypi:~/betrusted-soc $ python ./append_csr.py -b ./my_encrypted.bin -c ./build/csr.csv -o ./soc_csr.bin
Built: 2023-09-07 21:48:23.112111 on raspberrypi
Tags: b'v0.9.14\n'
Parsed tags: 0.9.14-0-0
Checksum: b'2968cd8e9ef56a3ea984ab43867afc95'
pi@raspberrypi:~/betrusted-soc $ hexdump -C soc_csr.bin | head -100
00000000  ff ff ff ff ff ff ff ff  aa 99 55 66 20 00 00 00  |..........Uf ...|
00000010  30 03 e0 01 00 00 00 0b  30 00 80 01 00 00 00 12  |0.......0.......|
00000020  20 00 00 00 30 00 c0 01  00 00 00 40 30 00 a0 01  | ...0......@0...|
00000030  00 00 00 40 30 01 c0 01  00 00 00 00 20 00 00 00  |...@0....... ...|
00000040  20 00 00 00 20 00 00 00  20 00 00 00 20 00 00 00  | ... ... ... ...|
*
00000070  20 00 00 00 30 01 60 04  35 b7 b1 78 d4 7e b5 46  | ...0.`.5..x.~.F|
00000080  87 b0 c8 aa 7f 54 a3 5d  30 03 40 01 00 08 5b 98  |.....T.]0.@...[.|
00000090  fe 78 3d 09 78 e1 8d 05  5f 2f 5c 5c c3 51 4d 3f  |.x=.x..._/\\.QM?|
000000a0  4b 35 f5 bf 50 47 6e 8f  14 04 17 23 50 dc 46 6e  |K5..PGn....#P.Fn|
000000b0  19 97 88 80 f3 ba eb db  ff 96 a7 68 8b 7f 31 f5  |...........h..1.|
000000c0  8a 20 08 85 55 6b ac d7  51 10 da 5e 22 cb 65 d2  |. ..Uk..Q..^".e.|
000000d0  6f c7 3a 9c 53 c8 0f f9  3f 58 52 c9 0f 72 33 be  |o.:.S...?XR..r3.|
000000e0  b0 99 69 4c e2 19 c2 4d  8e f6 fd d4 e9 a0 0f 35  |..iL...M.......5|
000000f0  59 4c d6 76 dd ec d0 8f  d1 f8 07 02 75 af b4 ef  |YL.v........u...|
00000100  f3 39 ce 47 6f 2f ce 76  e3 ff 3f 60 7d 14 56 9f  |.9.Go/.v..?`}.V.|
00000110  ff b9 ad f0 3c 59 6c f4  4b b7 b3 cc 7a af 8e 6d  |....<Yl.K...z..m|
00000120  b0 65 10 b0 17 e0 57 52  b1 13 04 38 36 c4 d0 1d  |.e....WR...86...|
00000130  d2 15 c8 69 36 76 c6 f7  09 2f 0c 14 63 e5 1e 1d  |...i6v.../..c...|
00000140  b4 df 3a ba ea 2d 6a 67  a6 78 97 ce ac 70 7a df  |..:..-jg.x...pz.|
00000150  ee 0b 42 4a 1d 32 91 9b  a1 c7 9f 0f cf f0 b5 1b  |..BJ.2..........|
00000160  6b 95 fa 9c ef f8 ff cd  86 07 18 45 3c 46 8c 73  |k..........E<F.s|
00000170  a5 ca 05 01 c9 2e 6e 5b  2e 03 31 bb 3b d8 79 a5  |......n[..1.;.y.|
00000180  b3 6e 34 4c 7b 7e 44 a3  c5 5a 5a 24 f1 01 0f eb  |.n4L{~D..ZZ$....|
00000190  8a 12 72 4f 6e 75 cc 66  a8 02 74 81 57 f3 1d f3  |..rOnu.f..t.W...|
000001a0  39 86 b6 08 31 c8 b3 54  b0 85 a8 02 45 3e a0 0f  |9...1..T....E>..|
000001b0  02 8e 34 30 1f 4b 86 94  16 7e 02 58 11 5b 2b af  |..40.K...~.X.[+.|
000001c0  06 c6 30 64 72 d7 c5 fe  a1 b6 3b cd c6 42 dc d1  |..0dr.....;..B..|
000001d0  d1 96 de b0 59 6e e8 59  25 9b 14 28 e1 ad 75 84  |....Yn.Y%..(..u.|
000001e0  5f b5 8b fe 30 8b 13 94  f1 57 a0 8c 78 5b 04 c0  |_...0....W..x[..|
000001f0  c6 ce 61 fe dd 34 f2 fc  70 49 82 18 7a 88 91 fb  |..a..4..pI..z...|
00000200  c1 2e 3b 2a 44 36 48 ab  d9 05 23 17 65 0a e2 0d  |..;*D6H...#.e...|
00000210  08 3c 99 77 73 53 e3 77  2d fe 13 e7 38 a7 61 21  |.<.wsS.w-...8.a!|
00000220  2c ea e8 5d 8a 81 7b c6  07 e3 1e 5c e2 0b f7 c6  |,..]..{....\....|
00000230  1c b1 c9 a8 25 7b 15 94  a0 c0 4f 80 55 d9 8c 8c  |....%{....O.U...|
00000240  f7 95 6a 59 ee c5 61 7a  1e de 99 e1 7a 6f 94 5d  |..jY..az....zo.]|
00000250  00 23 99 e6 5f ff 61 b1  3d bf 01 27 58 49 05 ec  |.#.._.a.=..'XI..|
00000260  24 25 64 3a 93 13 43 a0  c0 a4 40 06 ed 11 b1 29  |$%d:..C...@....)|
00000270  dd c1 e5 30 de 0c 0f c1  c7 cd 6c 39 ea 5b 3d 9b  |...0......l9.[=.|
00000280  75 95 60 c3 88 5b 7f 98  f7 07 13 54 ce d2 12 0a  |u.`..[.....T....|
00000290  af 9b 77 f5 cf 71 5d d4  d9 2a 3b 22 89 0f 96 0c  |..w..q]..*;"....|
000002a0  02 dd 0f 49 1c 19 f3 25  0e 4f 9d 96 1f 9f 15 f3  |...I...%.O......|
000002b0  4b 22 a2 50 c3 d3 3b 8f  5f 35 ab 86 0c aa d3 67  |K".P..;._5.....g|
000002c0  56 f0 48 fa dc 71 2a b9  41 18 8f 07 97 cc f7 2d  |V.H..q*.A......-|
000002d0  22 e5 4f 06 f9 e6 cb 84  80 38 2e e3 fe 3a 27 79  |".O......8...:'y|
000002e0  ba 32 05 e3 65 0e 66 00  f5 7b fa ef 6d a5 e2 17  |.2..e.f..{..m...|
000002f0  3d f1 ff 15 53 5b e4 cb  c4 d8 7c cc 0a fb 2f c6  |=...S[....|.../.|
00000300  2c 92 da 24 61 1e 01 b4  66 43 12 e8 e2 6a 23 c4  |,..$a...fC...j#.|
00000310  33 84 8e 6f 42 ba df 85  de 92 30 92 02 37 1e 0c  |3..oB.....0..7..|
00000320  36 02 b6 8d 6e a1 c1 6e  95 08 ec cd da d9 fd df  |6...n..n........|
00000330  ed de a0 f4 ef d7 67 a9  cf 33 86 5a d7 4f 34 1a  |......g..3.Z.O4.|
00000340  59 cb 69 45 a8 c1 60 4f  d8 fe 94 86 c3 af 64 fd  |Y.iE..`O......d.|
00000350  90 ff f9 f1 21 3b 3d 90  07 e4 f4 4a f4 1b 7e 12  |....!;=....J..~.|
00000360  68 6c 69 95 d9 86 91 04  c6 ca 9c 5c 07 15 18 1c  |hli........\....|
00000370  7f ff f7 be 1e 79 18 80  89 45 79 94 7b 02 33 15  |.....y...Ey.{.3.|
00000380  30 f4 69 df bb 48 be 60  58 33 cf 6e 82 51 92 8c  |0.i..H.`X3.n.Q..|
00000390  a9 43 ef 7d 9f 2c 77 22  a8 30 48 50 e0 2f 6f da  |.C.}.,w".0HP./o.|
000003a0  ce cb d0 36 5a 03 3e c4  a0 71 1f 26 cd 46 e0 1d  |...6Z.>..q.&.F..|
000003b0  78 95 eb 30 50 24 40 c4  42 da 30 ff f5 e0 dd 9e  |x..0P$@.B.0.....|
000003c0  2b 50 de 5f 81 b2 70 4c  0c 2e 91 be 10 3b b9 f8  |+P._..pL.....;..|
000003d0  ac 5c 89 12 5f 98 bc e5  02 6a fc 9d 6a 07 94 3e  |.\.._....j..j..>|
000003e0  ba f3 90 cc b5 f2 c9 a1  52 7b e5 a8 6d 44 94 3e  |........R{..mD.>|
000003f0  9b 87 5a 4f 2a 9c b9 60  58 ad a6 51 c4 68 9b f1  |..ZO*..`X..Q.h..|
00000400  83 d7 26 9d bc 79 f5 79  30 25 0b 66 77 89 27 5e  |..&..y.y0%.fw.'^|
00000410  52 3b 42 ed 77 ea e3 de  fe 93 7a b7 c1 d4 3a 1b  |R;B.w.....z...:.|
00000420  9e ba 6f 19 7c ce 49 58  66 92 6a e1 80 dc fe 44  |..o.|.IXf.j....D|
00000430  bb 87 38 10 d9 b6 9e a6  b0 e1 6b d7 63 76 8f 9d  |..8.......k.cv..|
00000440  5f 6e 72 d6 5f a5 16 ec  1f 72 df 64 ad da bf 6d  |_nr._....r.d...m|
00000450  a5 f0 e1 60 8a 2e c9 a0  dd ef ad 1d 0d 4e f3 6d  |...`.........N.m|
00000460  21 82 9b f2 31 6f 7d fd  fa 69 94 24 33 29 97 c5  |!...1o}..i.$3)..|
00000470  97 15 18 34 99 bd a8 30  e0 e0 d5 85 47 8a 3f c8  |...4...0....G.?.|
00000480  64 6e 5b 87 ba d1 05 80  e4 78 41 dd e3 83 dc 3b  |dn[......xA....;|
00000490  1e 5f c1 ed 42 15 58 ef  73 05 b6 b1 73 70 41 9c  |._..B.X.s...spA.|
000004a0  61 83 41 aa 5e e3 75 2f  66 96 ed fb db b3 5c 07  |a.A.^.u/f.....\.|
000004b0  96 a7 b0 07 c7 ee fc 67  31 4d 41 2c c9 60 5b c0  |.......g1MA,.`[.|
000004c0  81 38 e6 48 26 0d ae 67  86 07 62 05 82 37 6b c3  |.8.H&..g..b..7k.|
000004d0  83 fd d5 42 9f 0c 47 10  74 f0 0e 46 82 2d f0 af  |...B..G.t..F.-..|
000004e0  ff fb 56 a2 0a 4d fc 94  9b b4 18 ec 1e 28 b7 bc  |..V..M.......(..|
000004f0  4d 7d cc 21 82 3f 56 e2  d4 5e 9e 0d 91 9d e3 a1  |M}.!.?V..^......|
00000500  7e 21 17 34 6f 2d 22 36  69 68 60 fe 24 a9 1f 30  |~!.4o-"6ih`.$..0|
00000510  2d c6 d7 17 4a 60 db e0  48 2b 7e f3 82 62 24 ee  |-...J`..H+~..b$.|
00000520  bc ca 66 9e 0e 84 47 36  51 3b 18 82 65 6a 60 61  |..f...G6Q;..ej`a|
00000530  ee c5 a8 a6 6d bd 2a 8a  ac 6e 3a 94 c8 57 05 fe  |....m.*..n:..W..|
00000540  b6 57 6d b6 73 89 3b e2  6b ad 5a fd cc b3 e0 48  |.Wm.s.;.k.Z....H|
00000550  6c 62 12 f6 4a 9b 69 3f  ff 98 48 36 b5 0b c8 81  |lb..J.i?..H6....|
00000560  e5 d3 1a 07 53 cc f2 21  0a 60 69 6e cc 4d 5b 45  |....S..!.`in.M[E|
00000570  4d e3 7a a3 95 50 4f 6e  ab cb 1e 3d 0e ec b6 a1  |M.z..POn...=....|
00000580  26 64 b0 f1 51 e1 be 47  0c 42 d4 fa c9 b1 b3 76  |&d..Q..G.B.....v|
00000590  9c 0e 50 5b ca 56 40 71  7e db 31 6d bb 45 95 30  |..P[.V@q~.1m.E.0|
000005a0  79 78 7c 56 c0 4f 1f d6  77 2f 44 b8 71 03 ed 7e  |yx|V.O..w/D.q..~|
000005b0  b8 e7 4d 38 37 03 43 22  a8 ba c5 7b c8 6d f3 1e  |..M87.C"...{.m..|
000005c0  4c fe 5f dc af 95 9d dc  90 3f 9c a6 4b 3c 67 5d  |L._......?..K<g]|
000005d0  7f 05 24 2c 9d 54 f5 b3  07 0b 9a 44 25 32 81 d4  |..$,.T.....D%2..|
000005e0  c8 24 4f 17 32 ae ec b1  ba 32 a0 12 b8 a7 b6 56  |.$O.2....2.....V|
000005f0  11 f4 30 c6 fb ea 12 cd  6b 60 bf b2 9c 8e 22 cd  |..0.....k`....".|
00000600  35 b1 05 90 e1 b3 80 42  99 b5 92 c7 e5 05 1f c7  |5......B........|
00000610  c7 0b 0e a5 92 37 c9 35  5f 11 fe 6e ac 6f 88 19  |.....7.5_..n.o..|
00000620  ca 94 59 c5 73 62 0d d8  e2 b7 69 a3 2c 2c ff d6  |..Y.sb....i.,,..|
00000630  a7 8d 6c 57 f4 41 11 8b  e2 57 eb 6e 73 b2 29 e0  |..lW.A...W.ns.).|
00000640  67 1b 17 fb 01 ab 3a ab  84 29 a6 e3 97 b1 07 44  |g.....:..).....D|
...

I had some issues running bbram_helper.py, it seems to output jibberish on Precursor

pi@raspberrypi:~/betrusted-scripts $ ./bbram_helper.py
It's recommended to run this script with the network disconnected, to eliminate
the possibility of key exfiltration via network. This script will initiate the
BBRAM transformation process; you will have to enter your update password
*ON THE PRECURSOR* as part of this process. This script will never request
any passwords, and you should never type that password into anything but the Precursor.

This script expects the following configuration:
 -A Raspberry Pi (3 or 4) with the Precusror debug HAT installed
 -A Precursor attached to the debug HAT via the debug flex cable
 -'No login over serial', 'hardware serial port enabled' in raspi-config->interfacing options->serial
 -This should provide a serial console at /dev/ttyS0 (not /dev/ttyAMA0)
 -No other process accessing the serial console (in particular do 'ps -aux | grep -i screen' to confirm no zombie console sessions are open
Press enter when you're ready to proceed.

Press enter on the Precursor screen to start the comms test...
problem talking to device: {} Timeout exceeded.
<pexpect.fdpexpect.fdspawn object at 0x7f967a26d0>
searcher: searcher_string:
    0: b'CONS_SENTINEL|'
You may need to enter the update password on the Precursor device now; do not type the password here!
Traceback (most recent call last):
  File "/home/pi/betrusted-scripts/./bbram_helper.py", line 656, in <module>
    main()
  File "/home/pi/betrusted-scripts/./bbram_helper.py", line 555, in main
    console.expect_exact(CONSOLE_SENTINEL, 60)
  File "/home/pi/.local/lib/python3.9/site-packages/pexpect/spawnbase.py", line 421, in expect_exact
    return exp.expect_loop(timeout)
  File "/home/pi/.local/lib/python3.9/site-packages/pexpect/expect.py", line 181, in expect_loop
    return self.timeout(e)
  File "/home/pi/.local/lib/python3.9/site-packages/pexpect/expect.py", line 144, in timeout
    raise exc
pexpect.exceptions.TIMEOUT: Timeout exceeded.
<pexpect.fdpexpect.fdspawn object at 0x7f967a26d0>
searcher: searcher_string:
    0: b'CONS_SENTINEL|'

Replies to your answers:

  1. I would guess the self guided flow displays the key somewhere for you to write down before actually blowing it?
  2. Ah, okay so the SoC update sitting on flash is null key'd, then something basically does encrypt-bitstream.py on-device, I wasn't aware that's how it worked, does this potentially expose the key?
  3. Ahh okay, so you personally use the BBRAM Flow, I'm tempted to follow this

On another note, I can't seem to set the Root Password, I get a Internal alignment error, aborting! error, I used the update script to update to latest stable Xous & Gateware, I thought maybe bbram_helper.py expects the user has already set their root password.

spoelstraethan commented 1 year ago

On another note, I can't seem to set the Root Password, I get a Internal alignment error, aborting! error, I used the update script to update to latest stable Xous & Gateware, I thought maybe bbram_helper.py expects the user has already set their root password.

Did you run the factory reset option when you ran the update? this would reset all the passwords and should trigger the fresh out of box that would let you set the unlocked password and the root password.

dylangerdaly commented 1 year ago

bbram_helper.py -d is the way to go in order to provision BBRAM Keys and have it spit out what the key is, turns out I didn't have the ribbon cable seated correctly, after re-seating the cable the script worked correctly.

I would ask for some documentation to be updated however as a few things changed that I wasn't aware of namely

  1. When you provision eFuses or BBRAM Keys, and you update the gateware, you actually load a null key'd bitstream and the device itself re-encrypts it with your BBRAM or eFuse AES Key
  2. The device self-signs the Xous Kernel, meaning the dotted line at the top (Status bar) goes away, I didn't know happened.

The TL;DR is precursor itself self-signs a lot of it's stuff now, when you provision it.

Now that I've successfully provisioned my BBRAM Key, how do I update the gateware? I'd assume the gateware itself is hardly ever updated as it'd be like updating the SoC's ROM/chip design (Usually isn't possible with SoCs/Non FPGPAs)

bunnie commented 1 year ago

Do you think those doc updates should go in the https://github.com/betrusted-io/betrusted-wiki/wiki/FAQ:-FPGA-AES-Encryption-Key-(eFuse-BBRAM) page? or should they go in the "updating" general advice page?