Kinetis Bootloader  2.0.0
Common bootloader for Kinetis devices
property.h
1 /*
2  * Copyright (c) 2013-2015, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _property_h
32 #define _property_h
33 
34 #include <stdint.h>
35 #include "bootloader_common.h"
36 #include "packet/command_packet.h"
37 #if !defined(BOOTLOADER_HOST)
38 #include "fsl_device_registers.h"
39 #include "utilities/vector_table_info.h"
40 #endif
41 
44 
46 // Declarations
48 
50 
51 
54 #define HAS_CMD(tag) (1 << ((tag)-kFirstCommandTag))
55 
58 #define IS_CMD_AVAILABLE(mask, tag) (((mask)&HAS_CMD(tag)) != 0)
59 
60 enum _available_commands
61 {
62  kAvailableCommands = (
63 #if !BL_FEATURE_MIN_PROFILE
64  HAS_CMD(kCommandTag_FlashEraseAll) | HAS_CMD(kCommandTag_FlashEraseRegion) | HAS_CMD(kCommandTag_WriteMemory)
65 #if BL_FEATURE_FLASH_SECURITY
66  |
67  HAS_CMD(kCommandTag_FlashSecurityDisable)
68 #endif // BL_FEATURE_ERASEALL_UNSECURE
69  |
70  HAS_CMD(kCommandTag_GetProperty) | HAS_CMD(kCommandTag_Execute) | HAS_CMD(kCommandTag_Reset) |
71  HAS_CMD(kCommandTag_SetProperty) | HAS_CMD(kCommandTag_ReadMemory) | HAS_CMD(kCommandTag_FillMemory) |
72  HAS_CMD(kCommandTag_ReceiveSbFile) | HAS_CMD(kCommandTag_Call)
73 #if BL_FEATURE_ERASEALL_UNSECURE
74  |
75  HAS_CMD(kCommandTag_FlashEraseAllUnsecure)
76 #endif // BL_FEATURE_ERASEALL_UNSECURE
77  |
78  HAS_CMD(kCommandTag_FlashReadOnce) | HAS_CMD(kCommandTag_FlashProgramOnce) |
79  HAS_CMD(kCommandTag_FlashReadResource)
80 #if BL_FEATURE_QSPI_MODULE
81  |
82  HAS_CMD(kCommandTag_ConfigureQuadSpi)
83 #endif // BL_FEATURE_QSPI_MODULE
84 
85 #else // BL_FEATURE_MIN_PROFILE
86  HAS_CMD(kCommandTag_FlashEraseAll) | HAS_CMD(kCommandTag_FlashEraseRegion) | HAS_CMD(kCommandTag_WriteMemory)
87 #if BL_FEATURE_FLASH_SECURITY
88  |
89  HAS_CMD(kCommandTag_FlashSecurityDisable)
90 #endif // BL_FEATURE_FLASH_SECURITY
91  |
92  HAS_CMD(kCommandTag_GetProperty) | HAS_CMD(kCommandTag_Execute) | HAS_CMD(kCommandTag_Reset) |
93  HAS_CMD(kCommandTag_SetProperty)
94 #if BL_FEATURE_READ_MEMORY
95  |
96  HAS_CMD(kCommandTag_ReadMemory)
97 #endif // BL_FEATURE_READ_MEMORY
98 #if BL_FEATURE_FILL_MEMORY
99  |
100  HAS_CMD(kCommandTag_FillMemory)
101 #endif // BL_FEATURE_FILL_MEMORY
102 #if BL_FEATURE_ERASEALL_UNSECURE
103  |
104  HAS_CMD(kCommandTag_FlashEraseAllUnsecure)
105 #endif // BL_FEATURE_ERASEALL_UNSECURE
106 #if BL_FEATURE_QSPI_MODULE
107  |
108  HAS_CMD(kCommandTag_ConfigureQuadSpi)
109 #endif // BL_FEATURE_QSPI_MODULE
110 
111 #endif // BL_FEATURE_MIN_PROFILE
112  )
113 };
114 
116 
119 {
120  kStatus_UnknownProperty = MAKE_STATUS(kStatusGroup_PropertyStore, 0),
123 };
124 
128 {
129  kPropertyTag_ListProperties = 0x00,
130  kPropertyTag_BootloaderVersion = 0x01,
131  kPropertyTag_AvailablePeripherals = 0x02,
132  kPropertyTag_FlashStartAddress = 0x03,
133  kPropertyTag_FlashSizeInBytes = 0x04,
134  kPropertyTag_FlashSectorSize = 0x05,
135  kPropertyTag_FlashBlockCount = 0x06,
136  kPropertyTag_AvailableCommands = 0x07,
137  kPropertyTag_CrcCheckStatus = 0x08,
138  kPropertyTag_Reserved9 = 0x09,
139  kPropertyTag_VerifyWrites = 0x0a,
140  kPropertyTag_MaxPacketSize = 0x0b,
141  kPropertyTag_ReservedRegions = 0x0c,
142  kPropertyTag_Reserved13 = 0x0d,
143  kPropertyTag_RAMStartAddress = 0x0e,
144  kPropertyTag_RAMSizeInBytes = 0x0f,
145  kPropertyTag_SystemDeviceId = 0x10,
146  kPropertyTag_FlashSecurityState = 0x11,
147  kPropertyTag_UniqueDeviceId = 0x12,
148  kPropertyTag_FacSupport = 0x13,
149  kPropertyTag_FlashAccessSegmentSize = 0x14,
150  kPropertyTag_FlashAccessSegmentCount = 0x15,
151  kPropertyTag_FlashReadMargin = 0x16,
152  kPropertyTag_QspiInitStatus = 0x17,
153  kPropertyTag_TargetVersion = 0x18,
154  kPropertyTag_ExternalMemoryAttributes = 0x19,
155  kPropertyTag_ReliableUpdateStatus = 0x1a,
156  kPropertyTag_InvalidProperty = 0xFF,
157 };
158 
161 {
162  kProperty_ReservedRegionsCount = 2,
163  kProperty_FlashReservedRegionIndex = 0,
164  kProperty_RamReservedRegionIndex = 1,
165 
166  kProperty_FlashVersionIdSizeInBytes = 8,
167 };
168 
171 {
172  kClockFlag_HighSpeed = (1 << 0)
173 };
174 
177 {
178  kBootFlag_DirectBoot = (1 << 0)
179 };
180 
181 #if !defined(BOOTLOADER_HOST)
182 enum _flash_constants
184 {
191  kBootloaderConfigAreaAddress = (uint32_t)(APP_VECTOR_TABLE) + 0x3c0
192 };
193 #endif // BOOTLOADER_HOST
194 
196 typedef struct BootloaderConfigurationData
197 {
198  uint32_t tag;
199  uint32_t crcStartAddress;
200  uint32_t crcByteCount;
201  uint32_t crcExpectedValue;
203  uint8_t i2cSlaveAddress;
205  uint16_t usbVid;
207  uint16_t usbPid;
208  uint32_t usbStringsPointer;
209  uint8_t clockFlags;
210  uint8_t clockDivider;
211  uint8_t bootFlags;
212  uint8_t pad0;
214  uint32_t keyBlobPointer;
215  uint8_t pad1;
216  uint8_t canConfig1;
217  uint16_t canConfig2;
218  uint16_t canTxId;
219  uint16_t canRxId;
222 
224 typedef struct ReservedRegion
225 {
226  uint32_t startAddress;
227  uint32_t endAddress;
229 
231 typedef struct UniqueDeviceId
232 {
233  uint32_t uidl;
234  uint32_t uidml;
235  uint32_t uidmh;
236 #if defined(BOOTLOADER_HOST) | defined(SIM_UIDH)
237  uint32_t uidh;
238 #endif
240 
243 {
250 
251  kExternalMemoryPropertyTag_Start = kExternalMemoryPropertyTag_StartAddress,
252  kExternalMemoryPropertyTag_End = kExternalMemoryPropertyTag_BlockSize,
253 };
254 
256 typedef struct
257 {
259  uint32_t startAddress;
260  uint32_t flashSizeInKB;
261  uint32_t pageSize;
262  uint32_t sectorSize;
263  uint32_t blockSize;
265 
266 enum _ram_constants
267 {
268 #if CPU_IS_ARM_CORTEX_M7
269  kRAMCount = 3,
270 #else
271  kRAMCount = 1,
272 #endif
273 };
274 
276 typedef struct PropertyStore
277 {
282  uint32_t flashStartAddress;
284  uint32_t flashSizeInBytes;
285  uint32_t flashSectorSize;
286  uint32_t flashBlockSize;
287  uint32_t flashBlockCount;
288  uint32_t ramStartAddress[kRAMCount];
289  uint32_t ramSizeInBytes[kRAMCount];
290  uint32_t crcCheckStatus;
291  uint32_t verifyWrites;
292  uint32_t availableCommands;
295  uint32_t flashFacSupport;
298  uint32_t flashReadMargin;
299  uint32_t qspiInitStatus;
300  reserved_region_t reservedRegions[kProperty_ReservedRegionsCount];
306 
308 {
310  kPropertyStoreTag = FOUR_CHAR_CODE('k', 'c', 'f', 'g')
311 };
312 
314 typedef struct ExternalMemoryPropertyInterface
315 {
316  uint32_t memoryId;
317  status_t (*get)(uint32_t tag, uint32_t *value);
319 
321 typedef struct PropertyInterface
322 {
323  status_t (*load_user_config)(void);
324  status_t (*init)(void);
325  status_t (*get)(uint8_t tag, uint8_t id, const void **value, uint32_t *valueSize);
326  status_t (*set_uint32)(uint8_t tag, uint32_t value);
329 
331 // Externs
333 
336 
338 // Prototypes
340 
341 #if __cplusplus
342 extern "C" {
343 #endif
344 
346 
347 
350 
353 
371 status_t bootloader_property_get(uint8_t tag, uint8_t memoryId, const void **value, uint32_t *valueSize);
372 
383 status_t bootloader_property_set_uint32(uint8_t tag, uint32_t value);
384 
386 
387 #if __cplusplus
388 }
389 #endif
390 
392 
393 #endif // _property_h
394 // EOF
Sector size tag.
Definition: property.h:248
status_t bootloader_property_set_uint32(uint8_t tag, uint32_t value)
Set a property.
Definition: property.c:480
uint16_t peripheralDetectionTimeoutMs
Definition: property.h:204
uint8_t pad0
[1f:1f] Reserved, set to 0xFF
Definition: property.h:212
_external_memory_property_tags
External Memory Properties tag.
Definition: property.h:242
uint32_t flashSizeInBytes
Size in bytes of program flash.
Definition: property.h:284
uint16_t canTxId
[2c:2d] txId
Definition: property.h:218
uint32_t tag
[00:03] Tag value used to validate the bootloader configuration data. Must be set to &#39;kcfg&#39;...
Definition: property.h:198
_clock_flags
Bit positions for clock flags in configuration data.
Definition: property.h:170
uint32_t qspi_config_block_pointer
[30:33] QSPI config block pointer.
Definition: property.h:220
_property_constants
Property constants.
Definition: property.h:160
Exernal Memory attribute store.
Definition: property.h:256
_property_errors
Property store status codes.
Definition: property.h:118
uint32_t keyBlobPointer
[24:27] Holds a pointer value to the key blob array used to configure OTFAD
Definition: property.h:214
status_t bootloader_property_init(void)
Initialize the property store.
Definition: property.c:151
standard_version_t serialProtocolVersion
Serial protocol version number.
Definition: property.h:279
uint8_t bootFlags
[1e:1e] One&#39;s complemnt of direct boot flag, 0xFE represents direct boot
Definition: property.h:211
bootloader_configuration_data_t configurationData
Configuration data from flash address 0x3c0-0x3ff in sector 0 (64 bytes max)
Definition: property.h:302
uint32_t flashSizeInKB
flash size of external memory
Definition: property.h:260
uint8_t i2cSlaveAddress
[11:11]
Definition: property.h:203
uint8_t pad1
[28:28] reserved
Definition: property.h:215
const property_interface_t g_propertyInterface
Property interface.
Definition: property.c:100
Pag size tag.
Definition: property.h:247
property_store_t * store
The property store.
Definition: property.h:327
uint32_t verifyWrites
Definition: property.h:291
uint32_t sectorSize
sector size of external memory
Definition: property.h:262
standard_version_t targetVersion
Target version number.
Definition: property.h:280
External Memory properties interface.
Definition: property.h:314
uint16_t canRxId
[2e:2f] rxId
Definition: property.h:219
uint16_t canConfig2
[2a:2b] Pdiv[8], Pseg1[3], Pseg2[3], rjw[2]
Definition: property.h:217
uint32_t flashAccessSegmentSize
The size in bytes of one segment of flash.
Definition: property.h:296
uint32_t flashSectorSize
The size in bytes of one sector of program flash. This is the minimum erase size. ...
Definition: property.h:285
status_t bootloader_property_load_user_config(void)
Early initialization function to get user configuration data.
Definition: property.c:118
uint32_t flashReadMargin
The margin level setting for flash erase and program Verify CMDs.
Definition: property.h:298
uint32_t availablePeripherals
Definition: property.h:281
The bootloader configuration data location .
Definition: property.h:191
uint32_t flashBlockSize
The size in bytes of one block of program flash.
Definition: property.h:286
_property_tag
Property tags.
Definition: property.h:127
Structure of a unique device id.
Definition: property.h:231
Property store status group number (103).
Definition: bootloader_common.h:146
uint8_t enabledPeripherals
[10:10]
Definition: property.h:202
uint8_t clockDivider
[1d:1d] One&#39;s complement of clock divider, zero divider is divide by 1
Definition: property.h:210
uint32_t crcByteCount
[08:0b]
Definition: property.h:200
uint32_t crcExpectedValue
[0c:0f]
Definition: property.h:201
uint32_t startAddress
start Address of external memory
Definition: property.h:259
uint16_t usbPid
[16:17]
Definition: property.h:207
uint32_t pageSize
page size of external memory
Definition: property.h:261
_boot_flags
Bit positions for boot flags in configuration data.
Definition: property.h:176
Block size tag.
Definition: property.h:249
uint32_t mmcauConfigPointer
[20:23] Holds a pointer value to the MMCAU configuration
Definition: property.h:213
Interface to property operations.
Definition: property.h:321
uint8_t clockFlags
[1c:1c] High Speed and other clock options
Definition: property.h:209
status_t bootloader_property_get(uint8_t tag, uint8_t memoryId, const void **value, uint32_t *valueSize)
Get a property.
Definition: property.c:304
Structure of version property.
Definition: bootloader_common.h:168
Memory size tag.
Definition: property.h:246
Init status tag.
Definition: property.h:244
uint32_t crcCheckStatus
Status code from the last CRC check operation.
Definition: property.h:290
Start address tag.
Definition: property.h:245
Property is read-only.
Definition: property.h:121
uint32_t flashFacSupport
Boolean indicating whether the FAC feature is supported.
Definition: property.h:295
external_memory_property_store_t externalMemoryPropertyStore
Property store for external memory.
Definition: property.h:303
uint32_t qspiInitStatus
Result of QSPI+OTFAD init during bootloader startup.
Definition: property.h:299
_property_store_tags
Definition: property.h:307
Property value is out of range.
Definition: property.h:122
uint32_t blockSize
block size of external memory
Definition: property.h:263
Structure of property store.
Definition: property.h:276
uint32_t crcStartAddress
[04:07]
Definition: property.h:199
uint8_t canConfig1
[29:29] ClkSel[1], PropSeg[3], SpeedIndex[4]
Definition: property.h:216
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:121
uint32_t usbStringsPointer
[18:1b]
Definition: property.h:208
uint32_t flashAccessSegmentCount
The count of flash access segment within flash module.
Definition: property.h:297
uint32_t reliableUpdateStatus
Status of reliable update.
Definition: property.h:304
Tag value used to validate the bootloader configuration data.
Definition: property.h:310
_flash_constants
Flash constants.
Definition: property.h:183
Format of bootloader configuration data on Flash.
Definition: property.h:196
Structure of a reserved regions entry.
Definition: property.h:224
unique_device_id_t UniqueDeviceId
Unique identification for the device.
Definition: property.h:294
uint32_t flashBlockCount
Number of blocks in the flash array.
Definition: property.h:287
uint32_t availableAttributesFlag
Available Atrributes, bit map.
Definition: property.h:258
standard_version_t bootloaderVersion
Current bootloader version.
Definition: property.h:278