![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Rtos API example
mbed-os/tools/targets/LPC.py@0:9fca2b23d0ba, 2019-02-23 (annotated)
- Committer:
- marcozecchini
- Date:
- Sat Feb 23 12:13:36 2019 +0000
- Revision:
- 0:9fca2b23d0ba
final commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcozecchini | 0:9fca2b23d0ba | 1 | """ |
marcozecchini | 0:9fca2b23d0ba | 2 | mbed SDK |
marcozecchini | 0:9fca2b23d0ba | 3 | Copyright (c) 2011-2013 ARM Limited |
marcozecchini | 0:9fca2b23d0ba | 4 | |
marcozecchini | 0:9fca2b23d0ba | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
marcozecchini | 0:9fca2b23d0ba | 6 | you may not use this file except in compliance with the License. |
marcozecchini | 0:9fca2b23d0ba | 7 | You may obtain a copy of the License at |
marcozecchini | 0:9fca2b23d0ba | 8 | |
marcozecchini | 0:9fca2b23d0ba | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
marcozecchini | 0:9fca2b23d0ba | 10 | |
marcozecchini | 0:9fca2b23d0ba | 11 | Unless required by applicable law or agreed to in writing, software |
marcozecchini | 0:9fca2b23d0ba | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
marcozecchini | 0:9fca2b23d0ba | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
marcozecchini | 0:9fca2b23d0ba | 14 | See the License for the specific language governing permissions and |
marcozecchini | 0:9fca2b23d0ba | 15 | limitations under the License. |
marcozecchini | 0:9fca2b23d0ba | 16 | |
marcozecchini | 0:9fca2b23d0ba | 17 | |
marcozecchini | 0:9fca2b23d0ba | 18 | http://www.nxp.com/documents/user_manual/UM10360.pdf |
marcozecchini | 0:9fca2b23d0ba | 19 | |
marcozecchini | 0:9fca2b23d0ba | 20 | 32.3.1.1 Criterion for Valid User Code |
marcozecchini | 0:9fca2b23d0ba | 21 | The reserved Cortex-M3 exception vector location 7 (offset 0x1C in the vector table) |
marcozecchini | 0:9fca2b23d0ba | 22 | should contain the 2's complement of the check-sum of table entries 0 through 6. This |
marcozecchini | 0:9fca2b23d0ba | 23 | causes the checksum of the first 8 table entries to be 0. The boot loader code checksums |
marcozecchini | 0:9fca2b23d0ba | 24 | the first 8 locations in sector 0 of the flash. If the result is 0, then execution control is |
marcozecchini | 0:9fca2b23d0ba | 25 | transferred to the user code. |
marcozecchini | 0:9fca2b23d0ba | 26 | """ |
marcozecchini | 0:9fca2b23d0ba | 27 | from struct import unpack, pack |
marcozecchini | 0:9fca2b23d0ba | 28 | |
marcozecchini | 0:9fca2b23d0ba | 29 | |
marcozecchini | 0:9fca2b23d0ba | 30 | def patch(bin_path): |
marcozecchini | 0:9fca2b23d0ba | 31 | with open(bin_path, 'r+b') as bin: |
marcozecchini | 0:9fca2b23d0ba | 32 | # Read entries 0 through 6 (Little Endian 32bits words) |
marcozecchini | 0:9fca2b23d0ba | 33 | vector = [unpack('<I', bin.read(4))[0] for _ in range(7)] |
marcozecchini | 0:9fca2b23d0ba | 34 | |
marcozecchini | 0:9fca2b23d0ba | 35 | # location 7 (offset 0x1C in the vector table) should contain the 2's |
marcozecchini | 0:9fca2b23d0ba | 36 | # complement of the check-sum of table entries 0 through 6 |
marcozecchini | 0:9fca2b23d0ba | 37 | bin.seek(0x1C) |
marcozecchini | 0:9fca2b23d0ba | 38 | bin.write(pack('<I', (~sum(vector) + 1) & 0xFFFFFFFF)) |
marcozecchini | 0:9fca2b23d0ba | 39 | |
marcozecchini | 0:9fca2b23d0ba | 40 | |
marcozecchini | 0:9fca2b23d0ba | 41 | def is_patched(bin_path): |
marcozecchini | 0:9fca2b23d0ba | 42 | with open(bin_path, 'rb') as bin: |
marcozecchini | 0:9fca2b23d0ba | 43 | # The checksum of the first 8 table entries should be 0 |
marcozecchini | 0:9fca2b23d0ba | 44 | return (sum([unpack('<I', bin.read(4))[0] for _ in range(8)]) & 0xFFFFFFFF) == 0 |
marcozecchini | 0:9fca2b23d0ba | 45 | |
marcozecchini | 0:9fca2b23d0ba | 46 | |
marcozecchini | 0:9fca2b23d0ba | 47 | if __name__ == '__main__': |
marcozecchini | 0:9fca2b23d0ba | 48 | bin_path = "C:/Users/emimon01/releases/emilmont/build/test/LPC1768/ARM/MBED_A1/basic.bin" |
marcozecchini | 0:9fca2b23d0ba | 49 | patch(bin_path) |
marcozecchini | 0:9fca2b23d0ba | 50 | assert is_patched(bin_path), "The file is not patched" |