PAL
A Platform Abstraction Layer connects the mbed-client with the underlying platform.
Macros | Typedefs | Enumerations | Functions | Variables
pal_plat_update.cpp File Reference
#include "pal_plat_update.h"
#include "crc.h"
#include <mbed.h>
#include <flash-journal-strategy-sequential/flash_journal_strategy_sequential.h>
#include <storage-volume-manager/storage_volume_manager.h>

Macros

#define PAL_UPDATE_JOURNAL_SIZE   0x80000UL
 
#define PAL_UPDATE_JOURNAL_START_OFFSET   0x80000UL
 
#define PAL_UPDATE_ACTIVE_METADATA_HEADER_OFFSET   0x80000UL
 
#define SIZEOF_SHA256   256/8
 
#define FIRMWARE_HEADER_MAGIC   0x5a51b3d4UL
 
#define FIRMWARE_HEADER_VERSION   1
 

Typedefs

typedef struct FirmwareHeader FirmwareHeader_t
 

Enumerations

enum  pal_pi_mbed_fsm_t {
  PAL_PI_MBED_FSM_NONE, PAL_PI_MBED_FSM_SETUP, PAL_PI_MBED_FSM_WRITE, PAL_PI_MBED_FSM_READ,
  PAL_PI_MBED_FSM_COMMIT, PAL_PI_MBED_FSM_GETACTIVEHASH
}
 
enum  pal_pi_mbed_getativehash_state_t {
  PAL_PI_GETATIVEHASH_UNINITIALIZED, PAL_PI_GETATIVEHASH_VOLUME_MANAGER_INITIALIZED, PAL_PI_GETATIVEHASH_STORAGE_DRIVER_INITIALIZED, PAL_PI_GETATIVEHASH_DONE,
  PAL_PI_GETATIVEHASH_ERROR
}
 
enum  pal_pi_mbed_setup_state_t {
  PAL_PI_SETUP_UNINITIALIZED, PAL_PI_SETUP_VOLUME_MANAGER_INITIALIZED, PAL_PI_SETUP_STORAGE_DRIVER_INITIALIZED, PAL_PI_SETUP_DONE,
  PAL_PI_SETUP_ERROR = -1
}
 
enum  pal_pi_mbed_read_state_t { PAL_PI_READ_SKIP_METADATA, PAL_PI_READ_UNINITIALIZED, PAL_PI_READ_DONE, PAL_PI_READ_ERROR }
 
enum  pal_pi_mbed_commit_state_t { PAL_PI_COMMIT_UNINITIALIZED, PAL_PI_COMMIT_RESIDUAL_LOGGED, PAL_PI_COMMIT_DONE, PAL_PI_COMMIT_ERROR }
 
enum  pal_pi_mbed_write_state_t {
  PAL_PI_WRITE_UNINITIALIZED, PAL_PI_WRITE_METADATA_LOGGED, PAL_PI_WRITE_RESIDUAL_LOGGED, PAL_PI_WRITE_DONE,
  PAL_PI_WRITE_ERROR
}
 

Functions

void PAL_PI_MBED_journal_callbackHandler (int32_t status, FlashJournal_OpCode_t cmd_code)
 
void PAL_PI_MBED_journalMTD_callbackHandler (int32_t status, ARM_STORAGE_OPERATION operation)
 
void PAL_PI_MBED_volumeManager_initializeCallbackHandler (int32_t status)
 
ARM_DRIVER_STORAGE ARM_Driver_Storage_ (0)
 
int PAL_PI_MBED_Setup_StateMachine_Enter ()
 
void PAL_PI_MBED_Setup_StateMachine_Advance (int32_t status)
 
int PAL_PI_MBED_Write_StateMachine_Enter (int32_t status)
 
void PAL_PI_MBED_Write_StateMachine_Advance (int32_t status)
 
int PAL_PI_MBED_Read_StateMachine_Enter ()
 
void PAL_PI_MBED_Read_StateMachine_Advance (int32_t status)
 
int PAL_PI_MBED_Commit_StateMachine_Enter ()
 
void PAL_PI_MBED_Commit_StateMachine_Advance (int32_t status)
 
palStatus_t pal_plat_imageInitAPI (palImageSignalEvent_t CBfunction)
 
palStatus_t pal_plat_imageDeInit (void)
 
palStatus_t pal_plat_imageGetMaxNumberOfImages (uint8_t *imageNumber)
 
palStatus_t pal_plat_imageSetVersion (palImageId_t imageId, const palConstBuffer_t *version)
 
palStatus_t pal_plat_imageGetDirectMemAccess (palImageId_t imageId, void **imagePtr, size_t *imageSizeInBytes)
 
palStatus_t pal_plat_imageActivate (palImageId_t imageId)
 
int PAL_PI_MBED_GetAtiveHash_StateMachine ()
 
palStatus_t pal_plat_imageGetActiveHash (palBuffer_t *hash)
 
palStatus_t pal_plat_imageGetActiveVersion (palBuffer_t *version)
 
palStatus_t pal_plat_imageWriteHashToMemory (const palConstBuffer_t *const hashValue)
 
palStatus_t pal_plat_imageSetHeader (palImageId_t imageId, palImageHeaderDeails_t *details)
 
palStatus_t pal_plat_imageReserveSpace (palImageId_t imageId, size_t imageSize)
 
int PAL_PI_MBED_Write_LogResidual ()
 
palStatus_t pal_plat_imageWrite (palImageId_t imageId, size_t offset, palConstBuffer_t *chunk)
 
palStatus_t pal_plat_imageReadToBuffer (palImageId_t imageId, size_t offset, palBuffer_t *chunk)
 
palStatus_t pal_plat_imageFlush (palImageId_t package_id)
 

Variables

FlashJournal_t pal_pi_mbed_journal
 
FlashJournal_Info_t pal_pi_mbed_journal_info
 
uint8_t * pal_pi_mbed_overflow_buffer
 
uint32_t pal_pi_mbed_overflow_buffer_size = 0
 
ARM_DRIVER_STORAGE * mtd = &ARM_Driver_Storage_(0)
 
uint8_t pal_pi_mbed_metadata_logged
 

Macro Definition Documentation

#define FIRMWARE_HEADER_MAGIC   0x5a51b3d4UL
#define FIRMWARE_HEADER_VERSION   1
#define PAL_UPDATE_ACTIVE_METADATA_HEADER_OFFSET   0x80000UL
#define PAL_UPDATE_JOURNAL_SIZE   0x80000UL
#define PAL_UPDATE_JOURNAL_START_OFFSET   0x80000UL
#define SIZEOF_SHA256   256/8

Typedef Documentation

typedef struct FirmwareHeader FirmwareHeader_t

Enumeration Type Documentation

Enumerator
PAL_PI_COMMIT_UNINITIALIZED 
PAL_PI_COMMIT_RESIDUAL_LOGGED 
PAL_PI_COMMIT_DONE 
PAL_PI_COMMIT_ERROR 
Enumerator
PAL_PI_MBED_FSM_NONE 
PAL_PI_MBED_FSM_SETUP 
PAL_PI_MBED_FSM_WRITE 
PAL_PI_MBED_FSM_READ 
PAL_PI_MBED_FSM_COMMIT 
PAL_PI_MBED_FSM_GETACTIVEHASH 
Enumerator
PAL_PI_GETATIVEHASH_UNINITIALIZED 
PAL_PI_GETATIVEHASH_VOLUME_MANAGER_INITIALIZED 
PAL_PI_GETATIVEHASH_STORAGE_DRIVER_INITIALIZED 
PAL_PI_GETATIVEHASH_DONE 
PAL_PI_GETATIVEHASH_ERROR 
Enumerator
PAL_PI_READ_SKIP_METADATA 
PAL_PI_READ_UNINITIALIZED 
PAL_PI_READ_DONE 
PAL_PI_READ_ERROR 
Enumerator
PAL_PI_SETUP_UNINITIALIZED 
PAL_PI_SETUP_VOLUME_MANAGER_INITIALIZED 
PAL_PI_SETUP_STORAGE_DRIVER_INITIALIZED 
PAL_PI_SETUP_DONE 
PAL_PI_SETUP_ERROR 
Enumerator
PAL_PI_WRITE_UNINITIALIZED 
PAL_PI_WRITE_METADATA_LOGGED 
PAL_PI_WRITE_RESIDUAL_LOGGED 
PAL_PI_WRITE_DONE 
PAL_PI_WRITE_ERROR 

Function Documentation

ARM_DRIVER_STORAGE ARM_Driver_Storage_ ( )
void PAL_PI_MBED_Commit_StateMachine_Advance ( int32_t  status)
int PAL_PI_MBED_Commit_StateMachine_Enter ( )
int PAL_PI_MBED_GetAtiveHash_StateMachine ( )
void PAL_PI_MBED_journal_callbackHandler ( int32_t  status,
FlashJournal_OpCode_t  cmd_code 
)
void PAL_PI_MBED_journalMTD_callbackHandler ( int32_t  status,
ARM_STORAGE_OPERATION  operation 
)
void PAL_PI_MBED_Read_StateMachine_Advance ( int32_t  status)
int PAL_PI_MBED_Read_StateMachine_Enter ( )
void PAL_PI_MBED_Setup_StateMachine_Advance ( int32_t  status)
int PAL_PI_MBED_Setup_StateMachine_Enter ( )
void PAL_PI_MBED_volumeManager_initializeCallbackHandler ( int32_t  status)
int PAL_PI_MBED_Write_LogResidual ( )
void PAL_PI_MBED_Write_StateMachine_Advance ( int32_t  status)
int PAL_PI_MBED_Write_StateMachine_Enter ( int32_t  status)
palStatus_t pal_plat_imageActivate ( palImageId_t  imageId)

Set the imageId to be the active image (after device reset).

Parameters
[in]imageIdThe image ID.
palStatus_t pal_plat_imageDeInit ( void  )

Clear all the resources used by the pal_update APIs.

Returns
The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
palStatus_t pal_plat_imageFlush ( palImageId_t  imageId)

Flush the entire image data after writing ends for imageId.

Parameters
[in]imageIdThe image ID.
Returns
The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
palStatus_t pal_plat_imageGetActiveHash ( palBuffer_t hash)

Retrieve the hash value of the active image to hash buffer with max size hash maxBufferLength, and set the hash bufferLength to the hash size.

Parameters
[out]hashThe hash and actual size of hash read.
palStatus_t pal_plat_imageGetActiveVersion ( palBuffer_t version)

Retrieve the version of the active image to version buffer with the size set to version bufferLength.

Parameters
[out]versionThe version and actual size of version read.
palStatus_t pal_plat_imageGetDirectMemAccess ( palImageId_t  imageId,
void **  imagePtr,
size_t *  imageSizeInBytes 
)

Verify whether the imageId is readable and set imagePtr to point to the beginning of the image in the memory and imageSizeInBytes to the image size. In case of failure sets imagePtr to NULL and returns the relevant palStatus_t error.

Parameters
[in]imageIdThe image ID.
[out]imagePtrA pointer to the start of the image.
[out]imageSizeInBytesThe size of the image.
Returns
The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
palStatus_t pal_plat_imageGetMaxNumberOfImages ( uint8_t *  imageNumber)

Set the imageNumber to the number of available images. You can do this through hard coded define inside the linker script.

Parameters
[out]imageNumberThe total number of images the system supports.
Returns
The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
palStatus_t pal_plat_imageInitAPI ( palImageSignalEvent_t  CBfunction)

Set the callback function that is called before the end of each API (except imageGetDirectMemAccess).

Parameters
[in]CBfunctionA pointer to the callback function.
Returns
The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
palStatus_t pal_plat_imageReadToBuffer ( palImageId_t  imageId,
size_t  offset,
palBuffer_t chunk 
)

Read the max of chunk maxBufferLength bytes from the imageId with relative offset and store it in chunk buffer. Set the chunk bufferLength value to the actual number of bytes read. Note: Please use this API in case the image is not directly accessible via the imageGetDirectMemAccess function.

Parameters
[in]imageIdThe image ID.
[in]offsetThe offset to start reading from.
[out]chunkThe data and actual bytes read.
palStatus_t pal_plat_imageReserveSpace ( palImageId_t  imageId,
size_t  imageSize 
)

Claim space in the relevant storage region for imageId with the size of the image.

Parameters
[in]imageIdThe image ID.
[in]imageSizeThe size of the images.
Returns
The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
palStatus_t pal_plat_imageSetHeader ( palImageId_t  imageId,
palImageHeaderDeails_t details 
)

Set up the details for the image header. The data is written when the image write is called for the first time.

Parameters
[in]imageIdThe image ID.
[in]detailsThe data needed to build the image header.
Returns
The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
palStatus_t pal_plat_imageSetVersion ( palImageId_t  imageId,
const palConstBuffer_t version 
)

Update the image version of imageId to version written in version buffer with version bufferLength.

Parameters
[in]imageIdThe image ID.
[in]versionThe image version and its length.
Returns
The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
palStatus_t pal_plat_imageWrite ( palImageId_t  imageId,
size_t  offset,
palConstBuffer_t chunk 
)

Write the data in the chunk buffer with the size written in chunk bufferLength in the location of imageId adding the relative offset.

Parameters
[in]imageIdThe image ID.
[in]offsetthe relative offset to write the data into
[in]chunkA pointer to struct containing the data and the data length to write.
Returns
The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
palStatus_t pal_plat_imageWriteHashToMemory ( const palConstBuffer_t *const  hashValue)

Write the dataId stored in dataBuffer to memory accessible to the bootloader. Currently, only HASH is available.

Parameters
[in]hashValueThe data and size of the HASH.

Variable Documentation

ARM_DRIVER_STORAGE* mtd = &ARM_Driver_Storage_(0)
FlashJournal_t pal_pi_mbed_journal
FlashJournal_Info_t pal_pi_mbed_journal_info
uint8_t pal_pi_mbed_metadata_logged
uint8_t* pal_pi_mbed_overflow_buffer
uint32_t pal_pi_mbed_overflow_buffer_size = 0