35 #define MAX_CHUNKS_LOST 10
39 0xD0, 0xAC, 0xCE, 0x55,
40 0xDE, 0xAD, 0xBE, 0xEF };
45 static bool _updating =
false;
46 static uint32_t _adler32;
47 static uint32_t _offaddr = 0x0;
48 static uint32_t _lastSec = 0xFFFFFFFF;
50 static bool _failed =
false;
53 static bool updProtectGolden() {
68 logInfo(
"No password protection present, setting");
70 if (!updProtectGolden())
return false;
81 bool updStart(
int imageIdx, uint32_t chunkCount)
93 _lastSec = 0xFFFFFFFF;
96 _offaddr = imageIdx * FLASH_SPACING;
97 logDebug(
"Starting update of image %d with %d chunks", imageIdx, chunkCount);
110 if (_curaddr != _offaddr + chunkNo * UPD_CHUNK_SIZE)
123 #ifndef UPDATE_SIMULATE
133 #ifndef UPDATE_SIMULATE
143 bool updVerify(uint32_t imgNo, uint32_t chunkNo, uint8_t * chunk,
bool * result)
151 if (!
sfRead(addr, vbuf, UPD_CHUNK_SIZE))
return errRebase(_logModInfo.name);
153 if (memcmp(chunk, vbuf, UPD_CHUNK_SIZE) != 0) *result =
false;
163 bool updEnd(uint32_t * chunkLostList, uint32_t * chunksCount)
167 logDebug(
"Update done");
183 bool updCheckImage(
int index)
198 uint32_t addr = imgNo * FLASH_SPACING;
203 if (!
sfRead(addr, hdr1,
sizeof(hdr1)))
return errRebase(_logModInfo.name);
204 if (!
sfRead(addr + 292, tag2,
sizeof(tag2)))
return errRebase(_logModInfo.name);
206 if (hdr1[0] == 0xDA && hdr1[1] == 0x7A)
208 memcpy(imgInfo, &hdr1[2],
sizeof(
UpdImgInfo));
209 }
else if (tag2[0] == 0x11 && tag2[1] == 0x22 && tag2[2] == 0x00 && tag2[3] == 0x44)
231 if (!updProtectGolden())
return false;
bool updVerify(uint32_t imgNo, uint32_t chunkNo, uint8_t *chunk, bool *result)
Verify a chunk.
bool sfQuadEnable(bool enable)
Quad enable,.
bool sfLockUnlock(SfPassword *password)
Unlocks or locks the flash with the specified password.
uint8_t SfPassword[8]
Serial Flash password.
bool updWrite(uint32_t chunkNo, uint8_t *chunk)
Write a update chunk.
Defines the configuration of the LM32 SOC for the CLBv2.
#define E_UPD_SOMECHUNKS
Some chunks lost, check chunkLostList.
#define ADLER32_INIT_VAL
Value to which the Adler32 checksum should be initialized.
bool updUnlock()
Unlocks the golden image for writing.
bool updImgInfo(uint32_t imgNo, UpdImgInfo *imgInfo)
Retrieve image information for the specified location.
#define UPD_IMGTYPE_NONE
There is no image at the specified location.
bool updIsUpdating(int *index)
Returns whether or not the storage is in update mode.
int8_t imgType
Image type.
bool updInit()
Initializes the update module.
#define SF_INFO_STS_PASSWORD_PROTECT
Whether (part of) the flash is password.
bool updEnd(uint32_t *chunkLostList, uint32_t *chunksCount)
Ends the update.
SfInfo sfInfo
Flash info, only valid after successful initialization.
uint32_t sectorSize
Sector size in bytes.
bool updLock()
Locks the golden image for writing.
#define E_INVSTATE
Generic error: Module is in a state in which.
#define E_INVARGUMENT
Generic error: invalid argument.
bool updStart(int imageIdx, uint32_t chunkCount)
Starts an image update.
Manages the global system error.
bool sfErase(uint32_t address)
Erase a sector in flash.
#define SF_INFO_STS_LOCKED
Whether part of the flash is locked.
uint8_t sts
Device status, see SF_INFO_STS_*.
void updCancel()
Aborts the update.
uint32_t swRev
Software revision.
bool sfSetPasswordOTP(SfPassword *password)
Password protects specific sectors from being modified.
#define UPD_IMGTYPE_UNKNOWN
There is an image, but it has no meta-data.
uint32_t fwRev
Firmware revision.
bool sfProtect(uint32_t address)
Protects a specific sector from being erased or programmed.
bool sfProgXPage(uint32_t address, uint8_t *data, uint32_t count)
Program cross pages.
This module is responsible for distributing error codes.
#define LOG_DEF(NAME,...)
Define a logger for a module.
const int updMaxImages
Maximum no of images.
static bool errRebase(const char *name)
Rebases the cause of the error message.
bool sfRead(uint32_t address, uint8_t *data, uint32_t count)
Read from a specific address in flash.
This module provides checksum functions.
bool errSet(uint32_t code, const char *error, const char *name)
Sets an error.
#define ERROR(CODE,...)
Expands an error code to an error code with a description (if ERROR_W_DESCR is declared).
This driver implements access to the Serial Flash.
#define UPD_CHUNK_SIZE
chunk size for updates, in bytes
Implements a generic logger facility.
#define E_UPD_PROTECTED
Protection is not cleared.
#define logInfo(MSG,...)
Write a log message with formatting on info level.
bool sfUnProtect()
Unprotects the entire flash array.
Facilitates the update process.