-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate_bitstream.py
64 lines (56 loc) · 2.07 KB
/
generate_bitstream.py
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
import os
import sys
from boofuzz.helpers import mkdir_safe
from boofuzz.primitives import Static
from src.constants import CONSTANTS
from src.primitives import *
if len(sys.argv) > 2:
CONSTANTS.update_board(sys.argv[1])
bitstream_name = sys.argv[2]
else:
raise ValueError("please pass a board and a bitstream name as arguments")
### BITSTREAM DEFINITION START ###
bitstream = [
SyncWord(),
EncryptedSeries7Block(
name="encrypted_block",
children=(
Type1WritePacket(name="write_to_idcode", register_address=12),
Static(
name="idcode_value",
default_value=CONSTANTS.BOARD_CONSTANTS.DEVICE_IDCODE,
),
Type1WritePacket(name="write_to_far", register_address=1),
Static(name="far_value", default_value=b"\x00\x00\x00\x00"),
Type1WritePacket(name="write_to_cmd", register_address=4),
Static(name="wcfg_code", default_value=b"\x00\x00\x00\x01"),
Type1WritePacket(name="write_to_fdri", register_address=2, word_count=0),
Type2WritePacket(
name="write_to_fdri_type_2",
word_count=3 * CONSTANTS.BOARD_CONSTANTS.FRAME_LENGTH,
),
Static(
name="fdri_value_1",
default_value=b"\xF0\x0D\xF0\x0D"
* CONSTANTS.BOARD_CONSTANTS.FRAME_LENGTH,
),
Static(
name="fdri_value_2",
default_value=b"\xBE\xEF\xBE\xEF"
* CONSTANTS.BOARD_CONSTANTS.FRAME_LENGTH,
),
Static(
name="fdri_value_3",
default_value=b"\xDE\xAD\xC0\xDE"
* CONSTANTS.BOARD_CONSTANTS.FRAME_LENGTH,
),
),
pad_child_data=True,
key_file_name="test_key.nky",
),
]
### BITSTREAM DEFINITION END ###
bitstream_bytes = b"".join(primitive.render() for primitive in bitstream)
mkdir_safe(CONSTANTS.BITSTREAMS_DIR)
with open(os.path.join(CONSTANTS.BITSTREAMS_DIR, bitstream_name), "wb") as f:
f.write(bitstream_bytes)