property.h
/*
* Copyright (c) 2013-2015, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _property_h
#define _property_h
#include <stdint.h>
#include "bootloader_common.h"
#include "packet/command_packet.h"
#if !defined(BOOTLOADER_HOST)
#include "fsl_device_registers.h"
#include "utilities/vector_table_info.h"
#endif
// Declarations
#define HAS_CMD(tag) (1 << ((tag)-kFirstCommandTag))
#define IS_CMD_AVAILABLE(mask, tag) (((mask)&HAS_CMD(tag)) != 0)
enum _available_commands
{
kAvailableCommands = (
#if !BL_FEATURE_MIN_PROFILE
HAS_CMD(kCommandTag_FlashEraseAll) | HAS_CMD(kCommandTag_FlashEraseRegion) | HAS_CMD(kCommandTag_WriteMemory)
#if BL_FEATURE_FLASH_SECURITY
|
HAS_CMD(kCommandTag_FlashSecurityDisable)
#endif // BL_FEATURE_ERASEALL_UNSECURE
|
HAS_CMD(kCommandTag_GetProperty) | HAS_CMD(kCommandTag_Execute) | HAS_CMD(kCommandTag_Reset) |
HAS_CMD(kCommandTag_SetProperty) | HAS_CMD(kCommandTag_ReadMemory) | HAS_CMD(kCommandTag_FillMemory) |
HAS_CMD(kCommandTag_ReceiveSbFile) | HAS_CMD(kCommandTag_Call)
#if BL_FEATURE_ERASEALL_UNSECURE
|
HAS_CMD(kCommandTag_FlashEraseAllUnsecure)
#endif // BL_FEATURE_ERASEALL_UNSECURE
|
HAS_CMD(kCommandTag_FlashReadOnce) | HAS_CMD(kCommandTag_FlashProgramOnce) |
HAS_CMD(kCommandTag_FlashReadResource)
#if BL_FEATURE_QSPI_MODULE
|
HAS_CMD(kCommandTag_ConfigureQuadSpi)
#endif // BL_FEATURE_QSPI_MODULE
#else // BL_FEATURE_MIN_PROFILE
HAS_CMD(kCommandTag_FlashEraseAll) | HAS_CMD(kCommandTag_FlashEraseRegion) | HAS_CMD(kCommandTag_WriteMemory)
#if BL_FEATURE_FLASH_SECURITY
|
HAS_CMD(kCommandTag_FlashSecurityDisable)
#endif // BL_FEATURE_FLASH_SECURITY
|
HAS_CMD(kCommandTag_GetProperty) | HAS_CMD(kCommandTag_Execute) | HAS_CMD(kCommandTag_Reset) |
HAS_CMD(kCommandTag_SetProperty)
#if BL_FEATURE_READ_MEMORY
|
HAS_CMD(kCommandTag_ReadMemory)
#endif // BL_FEATURE_READ_MEMORY
#if BL_FEATURE_FILL_MEMORY
|
HAS_CMD(kCommandTag_FillMemory)
#endif // BL_FEATURE_FILL_MEMORY
#if BL_FEATURE_ERASEALL_UNSECURE
|
HAS_CMD(kCommandTag_FlashEraseAllUnsecure)
#endif // BL_FEATURE_ERASEALL_UNSECURE
#if BL_FEATURE_QSPI_MODULE
|
HAS_CMD(kCommandTag_ConfigureQuadSpi)
#endif // BL_FEATURE_QSPI_MODULE
#endif // BL_FEATURE_MIN_PROFILE
)
};
enum _property_errors
{
kStatus_UnknownProperty = MAKE_STATUS(kStatusGroup_PropertyStore, 0),
kStatus_ReadOnlyProperty = MAKE_STATUS(kStatusGroup_PropertyStore, 1),
kStatus_InvalidPropertyValue = MAKE_STATUS(kStatusGroup_PropertyStore, 2)
};
enum _property_tag
{
kPropertyTag_ListProperties = 0x00,
kPropertyTag_BootloaderVersion = 0x01,
kPropertyTag_AvailablePeripherals = 0x02,
kPropertyTag_FlashStartAddress = 0x03,
kPropertyTag_FlashSizeInBytes = 0x04,
kPropertyTag_FlashSectorSize = 0x05,
kPropertyTag_FlashBlockCount = 0x06,
kPropertyTag_AvailableCommands = 0x07,
kPropertyTag_CrcCheckStatus = 0x08,
kPropertyTag_Reserved9 = 0x09,
kPropertyTag_VerifyWrites = 0x0a,
kPropertyTag_MaxPacketSize = 0x0b,
kPropertyTag_ReservedRegions = 0x0c,
kPropertyTag_Reserved13 = 0x0d,
kPropertyTag_RAMStartAddress = 0x0e,
kPropertyTag_RAMSizeInBytes = 0x0f,
kPropertyTag_SystemDeviceId = 0x10,
kPropertyTag_FlashSecurityState = 0x11,
kPropertyTag_UniqueDeviceId = 0x12,
kPropertyTag_FacSupport = 0x13,
kPropertyTag_FlashAccessSegmentSize = 0x14,
kPropertyTag_FlashAccessSegmentCount = 0x15,
kPropertyTag_FlashReadMargin = 0x16,
kPropertyTag_QspiInitStatus = 0x17,
kPropertyTag_TargetVersion = 0x18,
kPropertyTag_ExternalMemoryAttributes = 0x19,
kPropertyTag_ReliableUpdateStatus = 0x1a,
kPropertyTag_InvalidProperty = 0xFF,
};
enum _property_constants
{
kProperty_ReservedRegionsCount = 2,
kProperty_FlashReservedRegionIndex = 0,
kProperty_RamReservedRegionIndex = 1,
kProperty_FlashVersionIdSizeInBytes = 8,
};
enum _clock_flags
{
kClockFlag_HighSpeed = (1 << 0)
};
enum _boot_flags
{
kBootFlag_DirectBoot = (1 << 0)
};
#if !defined(BOOTLOADER_HOST)
enum _flash_constants
{
kBootloaderConfigAreaAddress = (uint32_t)(APP_VECTOR_TABLE) + 0x3c0
};
#endif // BOOTLOADER_HOST
typedef struct BootloaderConfigurationData
{
uint32_t tag;
uint32_t crcStartAddress;
uint32_t crcByteCount;
uint32_t crcExpectedValue;
uint8_t enabledPeripherals;
uint8_t i2cSlaveAddress;
uint16_t peripheralDetectionTimeoutMs;
uint16_t usbVid;
uint16_t usbPid;
uint32_t usbStringsPointer;
uint8_t clockFlags;
uint8_t clockDivider;
uint8_t bootFlags;
uint8_t pad0;
uint32_t mmcauConfigPointer;
uint32_t keyBlobPointer;
uint8_t pad1;
uint8_t canConfig1;
uint16_t canConfig2;
uint16_t canTxId;
uint16_t canRxId;
uint32_t qspi_config_block_pointer;
} bootloader_configuration_data_t;
typedef struct ReservedRegion
{
uint32_t startAddress;
uint32_t endAddress;
} reserved_region_t;
typedef struct UniqueDeviceId
{
uint32_t uidl;
uint32_t uidml;
uint32_t uidmh;
#if defined(BOOTLOADER_HOST) | defined(SIM_UIDH)
uint32_t uidh;
#endif
} unique_device_id_t;
enum _external_memory_property_tags
{
kExternalMemoryPropertyTag_InitStatus = 0,
kExternalMemoryPropertyTag_StartAddress = 1,
kExternalMemoryPropertyTag_MemorySizeInKbytes = 2,
kExternalMemoryPropertyTag_PageSize = 3,
kExternalMemoryPropertyTag_SectorSize = 4,
kExternalMemoryPropertyTag_BlockSize = 5,
kExternalMemoryPropertyTag_Start = kExternalMemoryPropertyTag_StartAddress,
kExternalMemoryPropertyTag_End = kExternalMemoryPropertyTag_BlockSize,
};
typedef struct
{
uint32_t availableAttributesFlag;
uint32_t startAddress;
uint32_t flashSizeInKB;
uint32_t pageSize;
uint32_t sectorSize;
uint32_t blockSize;
} external_memory_property_store_t;
enum _ram_constants
{
#if CPU_IS_ARM_CORTEX_M7
kRAMCount = 3,
#else
kRAMCount = 1,
#endif
};
typedef struct PropertyStore
{
standard_version_t bootloaderVersion;
standard_version_t serialProtocolVersion;
standard_version_t targetVersion;
uint32_t availablePeripherals;
uint32_t flashStartAddress;
uint32_t flashSizeInBytes;
uint32_t flashSectorSize;
uint32_t flashBlockSize;
uint32_t flashBlockCount;
uint32_t ramStartAddress[kRAMCount];
uint32_t ramSizeInBytes[kRAMCount];
uint32_t crcCheckStatus;
uint32_t verifyWrites;
uint32_t availableCommands;
unique_device_id_t UniqueDeviceId;
uint32_t flashFacSupport;
uint32_t flashAccessSegmentSize;
uint32_t flashAccessSegmentCount;
uint32_t flashReadMargin;
uint32_t qspiInitStatus;
reserved_region_t reservedRegions[kProperty_ReservedRegionsCount];
bootloader_configuration_data_t
configurationData;
external_memory_property_store_t externalMemoryPropertyStore;
uint32_t reliableUpdateStatus;
} property_store_t;
enum _property_store_tags
{
kPropertyStoreTag = FOUR_CHAR_CODE('k', 'c', 'f', 'g')
};
typedef struct ExternalMemoryPropertyInterface
{
uint32_t memoryId;
status_t (*get)(uint32_t tag, uint32_t *value);
} external_memory_property_interface_t;
typedef struct PropertyInterface
{
status_t (*load_user_config)(void);
status_t (*init)(void);
status_t (*get)(uint8_t tag, uint8_t id, const void **value, uint32_t *valueSize);
status_t (*set_uint32)(uint8_t tag, uint32_t value);
property_store_t *store;
} property_interface_t;
// Externs
extern const property_interface_t g_propertyInterface;
// Prototypes
#if __cplusplus
extern "C" {
#endif
status_t bootloader_property_load_user_config(void);
status_t bootloader_property_init(void);
status_t bootloader_property_get(uint8_t tag, uint8_t memoryId, const void **value, uint32_t *valueSize);
status_t bootloader_property_set_uint32(uint8_t tag, uint32_t value);
#if __cplusplus
}
#endif
#endif // _property_h
// EOF
kExternalMemoryPropertyTag_SectorSize
Sector size tag.
Definition: property.h:248
bootloader_property_set_uint32
status_t bootloader_property_set_uint32(uint8_t tag, uint32_t value)
Set a property.
Definition: property.c:480
bootloader_configuration_data_t::peripheralDetectionTimeoutMs
uint16_t peripheralDetectionTimeoutMs
Definition: property.h:204
bootloader_configuration_data_t::pad0
uint8_t pad0
[1f:1f] Reserved, set to 0xFF
Definition: property.h:212
_external_memory_property_tags
_external_memory_property_tags
External Memory Properties tag.
Definition: property.h:242
property_store_t::flashSizeInBytes
uint32_t flashSizeInBytes
Size in bytes of program flash.
Definition: property.h:284
bootloader_configuration_data_t::canTxId
uint16_t canTxId
[2c:2d] txId
Definition: property.h:218
bootloader_configuration_data_t::tag
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
_clock_flags
Bit positions for clock flags in configuration data.
Definition: property.h:170
bootloader_configuration_data_t::qspi_config_block_pointer
uint32_t qspi_config_block_pointer
[30:33] QSPI config block pointer.
Definition: property.h:220
_property_constants
_property_constants
Property constants.
Definition: property.h:160
external_memory_property_store_t
Exernal Memory attribute store.
Definition: property.h:256
_property_errors
_property_errors
Property store status codes.
Definition: property.h:118
bootloader_configuration_data_t::keyBlobPointer
uint32_t keyBlobPointer
[24:27] Holds a pointer value to the key blob array used to configure OTFAD
Definition: property.h:214
bootloader_property_init
status_t bootloader_property_init(void)
Initialize the property store.
Definition: property.c:151
property_store_t::serialProtocolVersion
standard_version_t serialProtocolVersion
Serial protocol version number.
Definition: property.h:279
bootloader_configuration_data_t::bootFlags
uint8_t bootFlags
[1e:1e] One&#39;s complemnt of direct boot flag, 0xFE represents direct boot
Definition: property.h:211
property_store_t::configurationData
bootloader_configuration_data_t configurationData
Configuration data from flash address 0x3c0-0x3ff in sector 0 (64 bytes max)
Definition: property.h:302
external_memory_property_store_t::flashSizeInKB
uint32_t flashSizeInKB
flash size of external memory
Definition: property.h:260
bootloader_configuration_data_t::i2cSlaveAddress
uint8_t i2cSlaveAddress
[11:11]
Definition: property.h:203
bootloader_configuration_data_t::pad1
uint8_t pad1
[28:28] reserved
Definition: property.h:215
g_propertyInterface
const property_interface_t g_propertyInterface
Property interface.
Definition: property.c:100
kExternalMemoryPropertyTag_PageSize
Pag size tag.
Definition: property.h:247
property_interface_t::store
property_store_t * store
The property store.
Definition: property.h:327
property_store_t::verifyWrites
uint32_t verifyWrites
Definition: property.h:291
external_memory_property_store_t::sectorSize
uint32_t sectorSize
sector size of external memory
Definition: property.h:262
property_store_t::targetVersion
standard_version_t targetVersion
Target version number.
Definition: property.h:280
external_memory_property_interface_t
External Memory properties interface.
Definition: property.h:314
bootloader_configuration_data_t::canRxId
uint16_t canRxId
[2e:2f] rxId
Definition: property.h:219
bootloader_configuration_data_t::canConfig2
uint16_t canConfig2
[2a:2b] Pdiv[8], Pseg1[3], Pseg2[3], rjw[2]
Definition: property.h:217
property_store_t::flashAccessSegmentSize
uint32_t flashAccessSegmentSize
The size in bytes of one segment of flash.
Definition: property.h:296
property_store_t::flashSectorSize
uint32_t flashSectorSize
The size in bytes of one sector of program flash. This is the minimum erase size. ...
Definition: property.h:285
bootloader_property_load_user_config
status_t bootloader_property_load_user_config(void)
Early initialization function to get user configuration data.
Definition: property.c:118
property_store_t::flashReadMargin
uint32_t flashReadMargin
The margin level setting for flash erase and program Verify CMDs.
Definition: property.h:298
property_store_t::availablePeripherals
uint32_t availablePeripherals
Definition: property.h:281
kBootloaderConfigAreaAddress
The bootloader configuration data location .
Definition: property.h:191
property_store_t::flashBlockSize
uint32_t flashBlockSize
The size in bytes of one block of program flash.
Definition: property.h:286
_property_tag
_property_tag
Property tags.
Definition: property.h:127
unique_device_id_t
Structure of a unique device id.
Definition: property.h:231
kStatusGroup_PropertyStore
Property store status group number (103).
Definition: bootloader_common.h:146
bootloader_configuration_data_t::enabledPeripherals
uint8_t enabledPeripherals
[10:10]
Definition: property.h:202
bootloader_configuration_data_t::clockDivider
uint8_t clockDivider
[1d:1d] One&#39;s complement of clock divider, zero divider is divide by 1
Definition: property.h:210
bootloader_configuration_data_t::crcByteCount
uint32_t crcByteCount
[08:0b]
Definition: property.h:200
bootloader_configuration_data_t::crcExpectedValue
uint32_t crcExpectedValue
[0c:0f]
Definition: property.h:201
external_memory_property_store_t::startAddress
uint32_t startAddress
start Address of external memory
Definition: property.h:259
bootloader_configuration_data_t::usbPid
uint16_t usbPid
[16:17]
Definition: property.h:207
external_memory_property_store_t::pageSize
uint32_t pageSize
page size of external memory
Definition: property.h:261
_boot_flags
_boot_flags
Bit positions for boot flags in configuration data.
Definition: property.h:176
kExternalMemoryPropertyTag_BlockSize
Block size tag.
Definition: property.h:249
bootloader_configuration_data_t::mmcauConfigPointer
uint32_t mmcauConfigPointer
[20:23] Holds a pointer value to the MMCAU configuration
Definition: property.h:213
property_interface_t
Interface to property operations.
Definition: property.h:321
bootloader_configuration_data_t::clockFlags
uint8_t clockFlags
[1c:1c] High Speed and other clock options
Definition: property.h:209
bootloader_property_get
status_t bootloader_property_get(uint8_t tag, uint8_t memoryId, const void **value, uint32_t *valueSize)
Get a property.
Definition: property.c:304
standard_version_t
Structure of version property.
Definition: bootloader_common.h:168
kExternalMemoryPropertyTag_MemorySizeInKbytes
Memory size tag.
Definition: property.h:246
kExternalMemoryPropertyTag_InitStatus
Init status tag.
Definition: property.h:244
property_store_t::crcCheckStatus
uint32_t crcCheckStatus
Status code from the last CRC check operation.
Definition: property.h:290
kExternalMemoryPropertyTag_StartAddress
Start address tag.
Definition: property.h:245
kStatus_ReadOnlyProperty
Property is read-only.
Definition: property.h:121
property_store_t::flashFacSupport
uint32_t flashFacSupport
Boolean indicating whether the FAC feature is supported.
Definition: property.h:295
property_store_t::externalMemoryPropertyStore
external_memory_property_store_t externalMemoryPropertyStore
Property store for external memory.
Definition: property.h:303
property_store_t::qspiInitStatus
uint32_t qspiInitStatus
Result of QSPI+OTFAD init during bootloader startup.
Definition: property.h:299
_property_store_tags
_property_store_tags
Definition: property.h:307
kStatus_InvalidPropertyValue
Property value is out of range.
Definition: property.h:122
external_memory_property_store_t::blockSize
uint32_t blockSize
block size of external memory
Definition: property.h:263
property_store_t
Structure of property store.
Definition: property.h:276
bootloader_configuration_data_t::crcStartAddress
uint32_t crcStartAddress
[04:07]
Definition: property.h:199
bootloader_configuration_data_t::canConfig1
uint8_t canConfig1
[29:29] ClkSel[1], PropSeg[3], SpeedIndex[4]
Definition: property.h:216
status_t
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:121
bootloader_configuration_data_t::usbStringsPointer
uint32_t usbStringsPointer
[18:1b]
Definition: property.h:208
property_store_t::flashAccessSegmentCount
uint32_t flashAccessSegmentCount
The count of flash access segment within flash module.
Definition: property.h:297
property_store_t::reliableUpdateStatus
uint32_t reliableUpdateStatus
Status of reliable update.
Definition: property.h:304
kPropertyStoreTag
Tag value used to validate the bootloader configuration data.
Definition: property.h:310
_flash_constants
_flash_constants
Flash constants.
Definition: property.h:183
bootloader_configuration_data_t
Format of bootloader configuration data on Flash.
Definition: property.h:196
reserved_region_t
Structure of a reserved regions entry.
Definition: property.h:224
property_store_t::UniqueDeviceId
unique_device_id_t UniqueDeviceId
Unique identification for the device.
Definition: property.h:294
property_store_t::flashBlockCount
uint32_t flashBlockCount
Number of blocks in the flash array.
Definition: property.h:287
external_memory_property_store_t::availableAttributesFlag
uint32_t availableAttributesFlag
Available Atrributes, bit map.
Definition: property.h:258
property_store_t::bootloaderVersion
standard_version_t bootloaderVersion
Current bootloader version.
Definition: property.h:278