Skip to content

Commit 58e9117

Browse files
cbrown38350mbrossard
authored andcommitted
NXP: KV5x additions
1 parent fea51e8 commit 58e9117

File tree

4 files changed

+307
-0
lines changed

4 files changed

+307
-0
lines changed

source/board/twrkv58f.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @file twrkv58f.c
3+
* @brief board ID for the NXP TWR-KV58F220M board
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright (c) 2009-2019, ARM Limited, All Rights Reserved
7+
* SPDX-License-Identifier: Apache-2.0
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
10+
* not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
#include "target_board.h"
23+
#include "target_family.h"
24+
25+
const board_info_t g_board_info = {
26+
.infoVersion = 0x0,
27+
.board_id = "0240",
28+
.family_id = kNXP_KinetisV_FamilyID,
29+
.flags = kEnablePageErase,
30+
.target_cfg = &target_device,
31+
};
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/* Flash OS Routines (Automagically Generated)
2+
* Copyright (c) 2009-2019 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
static const uint32_t mkv58f_flash_prog_blob[] = {
18+
0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2,
19+
0xb510483e, 0x5120f24c, 0xf64d81c1, 0x81c11128, 0xf0218801, 0x80010101, 0x78414839, 0x0160f001,
20+
0xbf0c2940, 0x21002101, 0x444a4a36, 0xb1397011, 0xf0217841, 0x70410160, 0xf0117841, 0xd1fb0f60,
21+
0x44484831, 0xf864f000, 0xbf182800, 0xbd102001, 0x4448482c, 0xb1587800, 0x78414829, 0x0160f021,
22+
0x0140f041, 0x78417041, 0x0160f001, 0xd1fa2940, 0x47702000, 0xb5104824, 0x44484924, 0xf891f000,
23+
0xbf182800, 0x2100bd10, 0xe8bd481f, 0x44484010, 0xb958f000, 0x4c1cb570, 0x444c4605, 0x4b1b4601,
24+
0x68e24620, 0xf8b6f000, 0xbf182800, 0x2300bd70, 0x68e24629, 0x4070e8bd, 0x44484813, 0xb94cf000,
25+
0x460cb570, 0x4606460b, 0x480f4601, 0x4615b084, 0xf0004448, 0x2800f8eb, 0xb004bf1c, 0x2000bd70,
26+
0xe9cd2101, 0x90021000, 0x462b4807, 0x46314622, 0xf0004448, 0xb004f97f, 0x0000bd70, 0x40052000,
27+
0x4007e000, 0x00000004, 0x00000008, 0x6b65666b, 0xbf042800, 0x47702004, 0x6cc949ea, 0x6103f3c1,
28+
0xbf08290f, 0x1180f44f, 0x4ae7bf1f, 0xf832447a, 0x02891011, 0xe9c02200, 0x21022100, 0x61426081,
29+
0x618202c9, 0x1203e9c0, 0x52a0f04f, 0x2108e9c0, 0x47702000, 0xbf0e2800, 0x61012004, 0x47702000,
30+
0x48da4602, 0x49d96840, 0x0070f440, 0x47706048, 0x217048d7, 0x21807001, 0x78017001, 0x0f80f011,
31+
0x7800d0fb, 0x0f20f010, 0x2067bf1c, 0xf0104770, 0xbf1c0f10, 0x47702068, 0x0001f010, 0x2069bf18,
32+
0x28004770, 0x2004bf04, 0xb5104770, 0x4ac84604, 0x403bf06f, 0x48c76050, 0xbf144281, 0x2000206b,
33+
0xbf182800, 0x4620bd10, 0xffd2f7ff, 0x46204603, 0xffc6f7ff, 0xbd104618, 0xbf042800, 0x47702004,
34+
0x60532300, 0x60d36093, 0x61536113, 0x61d36193, 0x68c16011, 0xe9d06051, 0xfbb11001, 0x6090f0f0,
35+
0x21102008, 0x0103e9c2, 0x1005e9c2, 0x61d02004, 0x47702000, 0x4df0e92d, 0x4615b088, 0x460c4698,
36+
0x466a4682, 0xffd8f7ff, 0x4621462a, 0x9b044650, 0xf931f000, 0xbf1c0007, 0xe8bdb008, 0xe9dd8df0,
37+
0x19604600, 0xfbb51e45, 0xfb06f0f6, 0xb1205010, 0xf0f6fbb5, 0x43701c40, 0x42ac1e45, 0xf8dfbf98,
38+
0xd81cb270, 0x407ff024, 0x6010f040, 0x0004f8cb, 0x45804898, 0x206bbf14, 0x28002000, 0xb008bf1c,
39+
0x8df0e8bd, 0xf7ff4650, 0x4607ff73, 0x0010f8da, 0xbf182800, 0xb9174780, 0x42ac4434, 0x4650d9e2,
40+
0xff5ef7ff, 0x4638b008, 0x8df0e8bd, 0xbf042a00, 0x47702004, 0x45f0e92d, 0x4614b089, 0x460d461e,
41+
0x466a4680, 0xff88f7ff, 0x46294632, 0x9b034640, 0xf8e1f000, 0xbf1c0007, 0xe8bdb009, 0x9d0085f0,
42+
0xbf182e00, 0xa1e8f8df, 0xf854d025, 0xf8ca0b04, 0x98030008, 0xbf042804, 0x407ff025, 0x60c0f040,
43+
0x2808d009, 0xf854d109, 0xf8ca0b04, 0xf025000c, 0xf040407f, 0xf8ca60e0, 0x46400004, 0xff28f7ff,
44+
0x1010f8d8, 0x29004607, 0x4788bf18, 0x9803b91f, 0x1a364405, 0x4640d1d9, 0xff12f7ff, 0x4638b009,
45+
0x85f0e8bd, 0xbf042800, 0x47702004, 0xea424a62, 0x4a5f4101, 0xe70b6051, 0x4dffe92d, 0x4614b088,
46+
0x460d469a, 0x9808466a, 0xff36f7ff, 0x46294622, 0x98089b05, 0xf88ff000, 0xbf1c2800, 0xe8bdb00c,
47+
0x466a8df0, 0x98084629, 0xff26f7ff, 0xf8dd9e00, 0x42708008, 0x0100f1c8, 0x42474008, 0xbf0842b7,
48+
0x2c004447, 0xf8dfbf18, 0xd01fb128, 0x42a51bbd, 0x4625bf88, 0xf0269805, 0xfbb5417f, 0xf041f0f0,
49+
0xf8cb7180, 0x04001004, 0x200aea40, 0x00fff040, 0x0008f8cb, 0xf7ff9808, 0x2800fecb, 0xb00cbf1c,
50+
0x8df0e8bd, 0x442e1b64, 0xd1df4447, 0x2000b00c, 0x8df0e8bd, 0xbf042b00, 0x47702004, 0x4dffe92d,
51+
0x4616b088, 0x7a14e9dd, 0x460c461d, 0xf8dd466a, 0x98088058, 0xfee0f7ff, 0x3007e9dd, 0x46214632,
52+
0xf839f000, 0xbf1c2800, 0xe8bdb00c, 0x9c008df0, 0xbf042e00, 0xe8bdb00c, 0xf8df8df0, 0xf06fb094,
53+
0xea40407f, 0xf0246707, 0xf040407f, 0xf8cb7000, 0xf8cb0004, 0x68287008, 0x000cf8cb, 0xf7ff9808,
54+
0xb168fe87, 0x0f00f1ba, 0xf8cabf18, 0xf1b84000, 0xbf1c0f00, 0xf8c82100, 0xb00c1000, 0x8df0e8bd,
55+
0x1a769907, 0x0103f021, 0x9907440d, 0xd1da440c, 0xe8bdb00c, 0x28008df0, 0x2004bf04, 0xf1a34770,
56+
0x42190301, 0x421abf0e, 0x47702065, 0x428b6803, 0x6840d806, 0x44184411, 0xbf244288, 0x47702000,
57+
0x47702066, 0x40048000, 0x000003b4, 0x4001f000, 0x40020000, 0x6b65666b, 0x4000ffff, 0x40020004,
58+
0x40020010, 0x00100008, 0x00200018, 0x00400030, 0x00800060, 0x010000c0, 0x02000180, 0x04000300,
59+
0x00000600, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
60+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
61+
};
62+
63+
// Start address of flash
64+
static const uint32_t flash_start = 0x10000000;
65+
// Size of flash
66+
static const uint32_t flash_size = 0x00100000;
67+
68+
/**
69+
* List of start and size for each size of flash sector
70+
* The size will apply to all sectors between the listed address and the next address
71+
* in the list.
72+
* The last pair in the list will have sectors starting at that address and ending
73+
* at address start + size.
74+
*/
75+
static const sector_info_t sectors_info[] = {
76+
{ 0x10000000, 0x00001000 },
77+
};
78+
79+
static const program_target_t flash = {
80+
0x00000021, // Init
81+
0x00000071, // UnInit
82+
0x00000095, // EraseChip
83+
0x000000b5, // EraseSector
84+
0x000000e1, // ProgramPage
85+
0x0, // Verify
86+
87+
// BKPT : start of blob + 1
88+
// RSB : blob start + header + rw data offset
89+
// RSP : stack pointer
90+
{
91+
0x00000001,
92+
0x00000524,
93+
0x00000800
94+
},
95+
96+
0x00000000 + 0x00000A00, // mem buffer location
97+
0x00000000, // location to write prog_blob in target RAM
98+
sizeof(mkv58f_flash_prog_blob), // prog_blob size
99+
mkv58f_flash_prog_blob, // address of prog_blob
100+
0x00000400 // ram_to_flash_bytes_to_be_written
101+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @file target.c
3+
* @brief Target information for the k64f
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright (c) 2017-2019, ARM Limited, All Rights Reserved
7+
* SPDX-License-Identifier: Apache-2.0
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
10+
* not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
#include "target_config.h"
23+
24+
// The file flash_blob.c must only be included in target.c
25+
#include "flash_blob.c"
26+
27+
// target information
28+
target_cfg_t target_device = {
29+
.sectors_info = sectors_info,
30+
.sector_info_length = (sizeof(sectors_info))/(sizeof(sector_info_t)),
31+
.flash_regions[0].start = 0x00000000,
32+
.flash_regions[0].end = 0x00100000,
33+
.flash_regions[0].flags = kRegionIsDefault,
34+
.flash_regions[0].flash_algo = (program_target_t *) &flash,
35+
.ram_regions[0].start = 0x1fff0000,
36+
.ram_regions[0].end = 0x20030000,
37+
};
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/**
2+
* @file target_reset_Kseries.c
3+
* @brief Target reset for the Kinetis K series
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright (c) 2009-2019, ARM Limited, All Rights Reserved
7+
* SPDX-License-Identifier: Apache-2.0
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
10+
* not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
#include "target_reset.h"
23+
#include "swd_host.h"
24+
#include "info.h"
25+
#include "target_family.h"
26+
27+
#define MDM_STATUS 0x01000000
28+
#define MDM_CTRL 0x01000004
29+
#define MDM_IDR 0x010000fc
30+
#define MDM_ID 0x001c0000 // K64, K22 (K series)
31+
32+
static void target_before_init_debug(void)
33+
{
34+
swd_set_target_reset(1);
35+
}
36+
37+
static uint8_t target_unlock_sequence(void)
38+
{
39+
uint32_t val;
40+
41+
// read the device ID
42+
if (!swd_read_ap(MDM_IDR, &val)) {
43+
return 0;
44+
}
45+
46+
// verify the result
47+
if (val != MDM_ID) {
48+
return 0;
49+
}
50+
51+
if (!swd_read_ap(MDM_STATUS, &val)) {
52+
return 0;
53+
}
54+
55+
// flash in secured mode
56+
if (val & (1 << 2)) {
57+
// hold the device in reset
58+
swd_set_target_reset(1);
59+
60+
// write the mass-erase enable bit
61+
if (!swd_write_ap(MDM_CTRL, 1)) {
62+
return 0;
63+
}
64+
65+
while (1) {
66+
// wait until mass erase is started
67+
if (!swd_read_ap(MDM_STATUS, &val)) {
68+
return 0;
69+
}
70+
71+
if (val & 1) {
72+
break;
73+
}
74+
}
75+
76+
// mass erase in progress
77+
while (1) {
78+
// keep reading until procedure is complete
79+
if (!swd_read_ap(MDM_CTRL, &val)) {
80+
return 0;
81+
}
82+
83+
if (val == 0) {
84+
break;
85+
}
86+
}
87+
}
88+
89+
return 1;
90+
}
91+
92+
// Check Flash Configuration Field bytes at address 0x400-0x40f to ensure that flash security
93+
// won't be enabled.
94+
//
95+
// FCF bytes:
96+
// [0x0-0x7]=backdoor key
97+
// [0x8-0xb]=flash protection bytes
98+
// [0xc]=FSEC:
99+
// [7:6]=KEYEN (2'b10 is backdoor key enabled, all others backdoor key disabled)
100+
// [5:4]=MEEN (2'b10 mass erase disabled, all other mass erase enabled)
101+
// [3:2]=FSLACC (2'b00 and 2'b11 factory access enabled, 2'b01 and 2'b10 factory access disabled)
102+
// [1:0]=SEC (2'b10 flash security disabled, all other flash security enabled)
103+
// [0xd]=FOPT
104+
// [0xe]=EEPROM protection bytes (FlexNVM devices only)
105+
// [0xf]=data flash protection bytes (FlexNVM devices only)
106+
//
107+
// This function checks that:
108+
// - FSEC does not disable mass erase or secure the device.
109+
//
110+
static uint8_t security_bits_set(uint32_t addr, uint8_t *data, uint32_t size)
111+
{
112+
const uint32_t fsec_addr = 0x40C;
113+
114+
if ((addr <= fsec_addr) && (addr + size) > fsec_addr) {
115+
uint8_t fsec = data[fsec_addr - addr];
116+
117+
// make sure we can unsecure the device or dont program at all
118+
if ((fsec & 0x30) == 0x20) {
119+
// Dont allow programming mass-erase disabled state
120+
return 1;
121+
}
122+
123+
// Security is OK long as we can mass-erase (comment the following out to enable target security)
124+
if ((fsec & 0x03) != 0x02) {
125+
return 1;
126+
}
127+
}
128+
129+
return 0;
130+
}
131+
132+
const target_family_descriptor_t g_nxp_kinetis_kseries = {
133+
.family_id = kNXP_KinetisV_FamilyID,
134+
.default_reset_type = kHardwareReset,
135+
.target_before_init_debug = target_before_init_debug,
136+
.target_unlock_sequence = target_unlock_sequence,
137+
.security_bits_set = security_bits_set,
138+
};

0 commit comments

Comments
 (0)