-
Notifications
You must be signed in to change notification settings - Fork 838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cmake script to update otp.json from privateaes.bin #536
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,46 @@ | ||
{ | ||
"30:0": { | ||
"ecc": true, | ||
"value": [ | ||
"0x00", | ||
"0x01", | ||
"0x02", | ||
"0x03", | ||
"0x04", | ||
"0x05", | ||
"0x06", | ||
"0x07", | ||
"0x08", | ||
"0x09", | ||
"0x0a", | ||
"0x0b", | ||
"0x0c", | ||
"0x0d", | ||
"0x0e", | ||
"0x0f", | ||
"0x00", | ||
"0x10", | ||
"0x20", | ||
"0x30", | ||
"0x40", | ||
"0x50", | ||
"0x60", | ||
"0x70", | ||
"0x80", | ||
"0x90", | ||
"0xA0", | ||
"0xB0", | ||
"0xC0", | ||
"0xD0", | ||
"0xE0", | ||
"0xF0" | ||
] | ||
}, | ||
"OTP_DATA_KEY1": [ | ||
0, | ||
0, | ||
1, | ||
1, | ||
2, | ||
2, | ||
3, | ||
3, | ||
4, | ||
4, | ||
5, | ||
5, | ||
6, | ||
6, | ||
7, | ||
7 | ||
], | ||
"OTP_DATA_KEY1_VALID": "0x010101", | ||
"OTP_DATA_KEY2": [ | ||
7, | ||
7, | ||
6, | ||
6, | ||
5, | ||
5, | ||
4, | ||
4, | ||
3, | ||
3, | ||
2, | ||
2, | ||
1, | ||
1, | ||
0, | ||
0 | ||
], | ||
"OTP_DATA_KEY2_VALID": "0x010101", | ||
"PAGE30_LOCK0": "0x4a4a4a" | ||
} | ||
"30:0" : | ||
{ | ||
"ecc" : true, | ||
"value" : | ||
[ | ||
"0x00", | ||
"0x01", | ||
"0x02", | ||
"0x03", | ||
"0x04", | ||
"0x05", | ||
"0x06", | ||
"0x07", | ||
"0x08", | ||
"0x09", | ||
"0x0a", | ||
"0x0b", | ||
"0x0c", | ||
"0x0d", | ||
"0x0e", | ||
"0x0f", | ||
"0x00", | ||
"0x10", | ||
"0x20", | ||
"0x30", | ||
"0x40", | ||
"0x50", | ||
"0x60", | ||
"0x70", | ||
"0x80", | ||
"0x90", | ||
"0xa0", | ||
"0xb0", | ||
"0xc0", | ||
"0xd0", | ||
"0xe0", | ||
"0xf0" | ||
] | ||
}, | ||
"OTP_DATA_KEY1" : [ 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7 ], | ||
"OTP_DATA_KEY1_VALID" : "0x010101", | ||
"OTP_DATA_KEY2" : [ 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0 ], | ||
"OTP_DATA_KEY2_VALID" : "0x010101", | ||
"PAGE30_LOCK0" : "0x4a4a4a" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
if (CMAKE_VERSION VERSION_LESS 3.19) | ||
# Check if keyfile is not the default, and print warning | ||
file(READ ${CMAKE_CURRENT_LIST_DIR}/privateaes.bin key_file HEX) | ||
if (NOT ${key_file} STREQUAL "000102030405060708090a0b0c0d0e0f00102030405060708090a0b0c0d0e0f0") | ||
message(WARNING | ||
"Encrypted bootloader AES key not updated in otp.json file, as CMake version is < 3.19" | ||
" - you will need to change the key in otp.json manually and re-run the build" | ||
) | ||
endif() | ||
else() | ||
# Read the JSON file. | ||
file(READ ${CMAKE_CURRENT_LIST_DIR}/otp.json json_string) | ||
# Read the key file | ||
file(READ ${CMAKE_CURRENT_LIST_DIR}/privateaes.bin key_file HEX) | ||
|
||
# adds '0x' prefix, comma suffix, and quotes for every byte | ||
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "\"0x\\1\", " key_file ${key_file}) | ||
set(key_file_json "[${key_file}]") | ||
|
||
string(JSON json_string SET ${json_string} "30:0" "value" ${key_file_json}) | ||
|
||
file(WRITE ${CMAKE_CURRENT_LIST_DIR}/otp.json ${json_string}) | ||
endif() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this should be a fatal error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is a fatal error then I don't think it will work if the key file has been changed with older CMake versions, as this script gets run whenever the file is changed (and on first build), and on older CMake versions it has no way to parse the JSON file to check if the key in the JSON file matches the privateaes.bin file