Skip to content

Commit 8a1c7fa

Browse files
authored
Merge pull request #4813 from jacobjohnson-ON/master
Dual Flash and Hex file support on NCS36510
2 parents 59f313b + bd60add commit 8a1c7fa

File tree

3 files changed

+110
-50
lines changed

3 files changed

+110
-50
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,82 @@
1+
/*###ICF### Section handled by ICF editor, don't touch! ****/
2+
/*-Editor annotation file-*/
3+
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_1.xml" */
4+
/*-Specials-*/
5+
define symbol __ICFEDIT_intvec_start__ = 0x00003000;
6+
/*-Memory Regions-*/
7+
define symbol __ICFEDIT_region_IROM1_start__ = 0x00003000; /* FLASHA program start*/
8+
define symbol __ICFEDIT_region_IROM1_end__ = 0x00051FFF; /* 316K = 320K - 4K(FIB table), FLASHA end */
9+
define symbol __ICFEDIT_region_IROM2_start__ = 0x00102000;
10+
define symbol __ICFEDIT_region_IROM2_end__ = 0x00151FFF; /* 320K */
11+
define symbol __ICFEDIT_region_EROM1_start__ = 0x0;
12+
define symbol __ICFEDIT_region_EROM1_end__ = 0x0;
13+
define symbol __ICFEDIT_region_EROM2_start__ = 0x0;
14+
define symbol __ICFEDIT_region_EROM2_end__ = 0x0;
15+
define symbol __ICFEDIT_region_EROM3_start__ = 0x0;
16+
define symbol __ICFEDIT_region_EROM3_end__ = 0x0;
117

2-
/* The memory space denoting the maximum possible amount of addressable memory */
3-
define memory Mem with size = 4G;
18+
define symbol __ICFEDIT_region_IRAM1_start__ = 0x3FFFC000; /* RAMA start */
19+
define symbol __ICFEDIT_region_IRAM1_end__ = 0x3FFFFFFF; /* RAMA end */
20+
define symbol __ICFEDIT_region_IRAM2_start__ = 0x3FFF8000; /* RAMB start */
21+
define symbol __ICFEDIT_region_IRAM2_end__ = 0x3FFFBFFF; /* RAMB end */
22+
define symbol __ICFEDIT_region_IRAM3_start__ = 0x3FFF4000; /* RAMC start */
23+
define symbol __ICFEDIT_region_IRAM3_end__ = 0x3FFF7FFF; /* RAMC end */
24+
define symbol __ICFEDIT_region_ERAM1_start__ = 0x0;
25+
define symbol __ICFEDIT_region_ERAM1_end__ = 0x0;
26+
define symbol __ICFEDIT_region_ERAM2_start__ = 0x0;
27+
define symbol __ICFEDIT_region_ERAM2_end__ = 0x0;
28+
define symbol __ICFEDIT_region_ERAM3_start__ = 0x0;
29+
define symbol __ICFEDIT_region_ERAM3_end__ = 0x0;
430

5-
/* Memory regions in an address space */
6-
define region FLASHA = Mem:[from 0x00003000 size 0x4D000]; /* 308K = 320K - 4K(FIB table) - 8K(Persistent) */
7-
define region FLASHB = Mem:[from 0x00100000 size 0x50000];
8-
define region RAMA = Mem:[from 0x3FFFC000 size 0x4000];
9-
define region RAMB = Mem:[from 0x3FFF8000 size 0x4000];
10-
/* G2H ZPRO requires RAMC to be enabled */
11-
define region RAMC = Mem:[from 0x3FFF4000 + 0x90 size 0x4000 - 0x90]; /* 8_byte_aligned(35 vectors * 4 bytes each) = 0x90 */
12-
define region RAM_ALL = Mem:[from 0x3FFF4000 + 0x90 size 0xC000 - 0x90]; /* 8_byte_aligned(35 vectors * 4 bytes each) = 0x90 */
31+
/*-Sizes-*/
32+
define symbol __ICFEDIT_size_cstack__ = 0x200;
33+
define symbol __ICFEDIT_size_heap__ = 0x4000;
34+
/**** End of ICF editor section. ###ICF###*/
1335

14-
/* Create a stack */
15-
define block CSTACK with size = 0x200, alignment = 8 { };
1636

17-
/* No Heap is created for C library, all memory management should be handled by the application */
18-
define block HEAP with alignment = 8, size = 0x3000 { };
37+
define memory mem with size = 4G;
38+
define region FLASH_region = mem:[from __ICFEDIT_region_IROM1_start__ to __ICFEDIT_region_IROM1_end__]
39+
| mem:[from __ICFEDIT_region_IROM2_start__ to __ICFEDIT_region_IROM2_end__];
1940

20-
/* Handle initialization */
21-
do not initialize { section .noinit };
41+
define region RAM_VECTOR_region = mem:[from __ICFEDIT_region_IRAM3_start__ to __ICFEDIT_region_IRAM3_start__ + 0x90 - 1];
2242

23-
/* Initialize RW sections, exclude zero-initialized sections */
24-
initialize by copy with packing = none { readwrite };
43+
define region RAM_region = mem:[from __ICFEDIT_region_IRAM3_start__ + 0x90 to __ICFEDIT_region_IRAM3_end__]
44+
| mem:[from __ICFEDIT_region_IRAM2_start__ to __ICFEDIT_region_IRAM2_end__]
45+
| mem:[from __ICFEDIT_region_IRAM1_start__ to __ICFEDIT_region_IRAM1_end__ - __ICFEDIT_size_cstack__ ];
46+
47+
define region CSTACK_region = mem:[from __ICFEDIT_region_IRAM1_end__ - __ICFEDIT_size_cstack__ + 1 to __ICFEDIT_region_IRAM1_end__];
48+
49+
50+
/* Define overlays for MIB's, ths allows view of one MIB from a application level while
51+
* MAC and PHY only know about their own MIB */
52+
define overlay MIBOVERLAY { section MIBSTARTSECTION };
53+
define overlay MIBOVERLAY { section MIBSECTION };
54+
55+
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
56+
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
57+
define block RAM_VECTORS with alignment = 8, size = 0x90 { };
58+
59+
initialize by copy { readwrite };
60+
61+
if (isdefinedsymbol(__USE_DLIB_PERTHREAD))
62+
{
63+
// Required in a multi-threaded application
64+
initialize by copy with packing = none { section __DLIB_PERTHREAD };
65+
}
2566

2667
/* Initialize the code in RAM, copied over from FLASH */
2768
initialize by copy with packing = none { readonly code section EXECINRAM };
28-
/*keep { readonly code section .EXECINRAM* } except { readonly code section EXECINRAM };*/
2969

30-
/* Place startup code at a fixed address */
31-
place at start of FLASHA { readonly section .intvec, readonly section SWVERSION,readonly section FIBTABLE,readonly section .cstartup };
70+
/*initialize by copy { readwrite };*/
71+
do not initialize { section .noinit };
72+
3273

33-
/* Place code and data */
74+
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec, readonly section SWVERSION, readonly section FIBTABLE };
3475

35-
/* Place constants and initializers in FLASHA: .rodata and .data_init */
36-
place in FLASHA { readonly };
76+
place in FLASH_region { readonly section .cstartup, readonly };
3777

38-
/* Place .data, .bss, and .noinit */
39-
/* and STACK */
40-
/* The relocatable exception table needs to be aligned at 0x0 or multiple of 0x100,
41-
* hence, place it as first block in RAM.
42-
*/
43-
place at start of RAM_ALL { section RAM_VECTORS };
44-
place in RAM_ALL { readonly code section EXECINRAM };
45-
place at end of RAM_ALL { block CSTACK };
78+
place at start of RAM_VECTOR_region {block RAM_VECTORS};
4679

80+
place in RAM_region { readwrite, block HEAP, section XHEAP, readonly code section EXECINRAM, overlay MIBOVERLAY, readwrite section MIBENDSECTION};
4781

48-
place in RAM_ALL { readwrite };
49-
place in RAM_ALL { block HEAP };
82+
place at end of CSTACK_region { block CSTACK };

Diff for: targets/targets.json

+1
Original file line numberDiff line numberDiff line change
@@ -3165,6 +3165,7 @@
31653165
"value": "0xFFFFFFFF"
31663166
}
31673167
},
3168+
"OUTPUT_EXT": "hex",
31683169
"post_binary_hook": {"function": "NCS36510TargetCode.ncs36510_addfib"},
31693170
"macros": ["CM3", "CPU_NCS36510", "TARGET_NCS36510", "LOAD_ADDRESS=0x3000"],
31703171
"supported_toolchains": ["GCC_ARM", "ARM", "IAR"],

Diff for: tools/targets/NCS.py

+42-16
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
from tools.config import Config
1919

2020
FIB_BASE = 0x2000
21+
TRIM_BASE = 0x2800
2122
FLASH_BASE = 0x3000
23+
FLASHA_SIZE = 0x52000
24+
FLASHB_BASE = 0x00102000
25+
FLASHB_SIZE = 0x52000
2226
FW_REV = 0x01000100
23-
TRIM_BASE = 0x2800
2427

2528
def ranges(i):
2629
for _, b in itertools.groupby(enumerate(i), lambda x_y: x_y[1] - x_y[0]):
@@ -29,17 +32,17 @@ def ranges(i):
2932

3033

3134
def add_fib_at_start(arginput):
32-
input_file = arginput + ".bin"
33-
file_name_hex = arginput + "_fib.hex"
35+
input_file = arginput + ".hex"
36+
file_name_hex = arginput + ".hex"
3437
file_name_bin = arginput + ".bin"
3538

3639
# Read in hex file
3740
input_hex_file = intelhex.IntelHex()
38-
input_hex_file.padding = 0x00
39-
input_hex_file.loadbin(input_file, offset=FLASH_BASE)
40-
41+
input_hex_file.loadhex(input_file)
42+
#set padding value to be returned when reading from unspecified address
43+
input_hex_file.padding = 0xFF
44+
# Create new hex file
4145
output_hex_file = intelhex.IntelHex()
42-
output_hex_file.padding = 0x00
4346

4447
# Get the starting and ending address
4548
addresses = input_hex_file.addresses()
@@ -48,17 +51,41 @@ def add_fib_at_start(arginput):
4851
regions = len(start_end_pairs)
4952

5053
if regions == 1:
54+
#single range indicating fits within first flash block (<320K)
5155
start, end = start_end_pairs[0]
56+
print("Memory start 0x%08X, end 0x%08X" % (start, end))
57+
# Compute checksum over the range (don't include data at location of crc)
58+
size = end - start + 1
59+
data = input_hex_file.tobinarray(start=start, size=size)
60+
crc32 = binascii.crc32(data) & 0xFFFFFFFF
5261
else:
53-
start = min(min(start_end_pairs))
54-
end = max(max(start_end_pairs))
62+
#multiple ranges indicating requires both flash blocks (>320K)
63+
start, end = start_end_pairs[0]
64+
start2, end2 = start_end_pairs[1]
65+
print("Region 1: memory start 0x%08X, end 0x%08X" % (start, end))
66+
print("Region 2: memory start 0x%08X, end 0x%08X" % (start2, end2))
67+
# Compute checksum over the range (don't include data at location of crc)
68+
# replace end with end of flash block A
69+
end = FLASHA_SIZE - 1
70+
size = end - start + 1
71+
data = input_hex_file.tobinarray(start=start, size=size)
72+
73+
# replace start2 with base of flash block B
74+
start2 = FLASHB_BASE
75+
size2 = end2 - start2 + 1
76+
data2 = input_hex_file.tobinarray(start=start2, size=size2)
77+
78+
#concatenate data and data2 arrays together
79+
data.extend(data2)
80+
crc32 = binascii.crc32(data) & 0xFFFFFFFF
81+
82+
#replace size with sum of two memory region sizes
83+
size = size + size2
5584

5685
assert start >= FLASH_BASE, ("Error - start 0x%x less than begining of user\
5786
flash area" %start)
58-
# Compute checksum over the range (don't include data at location of crc)
59-
size = end - start + 1
60-
data = input_hex_file.tobinarray(start=start, size=size)
61-
crc32 = binascii.crc32(data) & 0xFFFFFFFF
87+
88+
assert regions <= 2, ("Error - more than 2 memory regions found")
6289

6390
fw_rev = FW_REV
6491

@@ -177,7 +204,7 @@ def add_fib_at_start(arginput):
177204
output_hex_file[trim_area_start + 1] = (mac_addr_low >> 8) & 0xFF
178205
output_hex_file[trim_area_start + 2] = (mac_addr_low >> 16) & 0xFF
179206
output_hex_file[trim_area_start + 3] = (mac_addr_low >> 24) & 0xFF
180-
207+
181208
output_hex_file[trim_area_start + 4] = mac_addr_high & 0xFF
182209
output_hex_file[trim_area_start + 5] = (mac_addr_high >> 8) & 0xFF
183210
output_hex_file[trim_area_start + 6] = (mac_addr_high >> 16) & 0xFF
@@ -202,7 +229,7 @@ def add_fib_at_start(arginput):
202229
output_hex_file[trim_area_start + 21] = (txtune >> 8) & 0xFF
203230
output_hex_file[trim_area_start + 22] = (txtune >> 16) & 0xFF
204231
output_hex_file[trim_area_start + 23] = (txtune >> 24) & 0xFF
205-
232+
206233
# pad the rest of the area with 0xFF
207234
for i in range(trim_area_start + trim_size, user_code_start):
208235
output_hex_file[i] = 0xFF
@@ -212,4 +239,3 @@ def add_fib_at_start(arginput):
212239

213240
# Write out file(s)
214241
output_hex_file.tofile(file_name_hex, 'hex')
215-
output_hex_file.tofile(file_name_bin, 'bin')

0 commit comments

Comments
 (0)