|
| 1 | +# Copyright 2025 Nordic Semiconductor ASA |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +""" |
| 18 | +NRF54L15 BOOTCONF generator. |
| 19 | +""" |
| 20 | + |
| 21 | +from intelhex import IntelHex |
| 22 | +import argparse |
| 23 | +import sys |
| 24 | + |
| 25 | +SIZE_MAX_KB = 31 |
| 26 | + |
| 27 | +BOOTCONF_ADDR = 0x00FFD080 |
| 28 | + |
| 29 | +READ_ALLOWED = 0x01 |
| 30 | +WRITE_ALLOWED = 0x02 |
| 31 | +EXECUTE_ALLOWED = 0x04 |
| 32 | +SECURE = 0x08 |
| 33 | +OWNER_NONE = 0x00 |
| 34 | +OWNER_APP = 0x10 |
| 35 | +OWNER_KMU = 0x20 |
| 36 | +WRITEONCE = 0x10 |
| 37 | +LOCK = 0x20 |
| 38 | + |
| 39 | +def parse_args(): |
| 40 | + parser = argparse.ArgumentParser( |
| 41 | + description="Generate RRAMC's BOOTCONF configuration hex", |
| 42 | + formatter_class=argparse.RawDescriptionHelpFormatter, allow_abbrev=False) |
| 43 | + |
| 44 | + parser.add_argument("-o", "--output", required=False, default="b0_lock.hex", |
| 45 | + type=argparse.FileType('w', encoding='UTF-8'), |
| 46 | + help="Output file name.") |
| 47 | + parser.add_argument("-s", "--size", required=False, default="0x7C00", |
| 48 | + type=lambda x: hex(int(x, 0)), |
| 49 | + help="Size to lock.") |
| 50 | + return parser.parse_args() |
| 51 | + |
| 52 | + |
| 53 | +def main(): |
| 54 | + args = parse_args() |
| 55 | + size = int(args.size, 16) |
| 56 | + if size % 1024: |
| 57 | + sys.exit("error: requested size not aligned to 1k") |
| 58 | + size = size // 1024 |
| 59 | + if size > SIZE_MAX_KB: |
| 60 | + sys.exit("error: requested size too big") |
| 61 | + |
| 62 | + payload = bytearray([ |
| 63 | + READ_ALLOWED | EXECUTE_ALLOWED | SECURE | OWNER_NONE, |
| 64 | + LOCK, |
| 65 | + size, |
| 66 | + 0x0 |
| 67 | + ]) |
| 68 | + |
| 69 | + h = IntelHex() |
| 70 | + h.frombytes(bytes=payload, offset=BOOTCONF_ADDR) |
| 71 | + h.tofile(args.output, 'hex') |
| 72 | + |
| 73 | +if __name__ == "__main__": |
| 74 | + main() |
0 commit comments