Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
pal_update.c
00001 /******************************************************************************* 00002 * Copyright 2016, 2017 ARM Ltd. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 *******************************************************************************/ 00016 00017 00018 #include "pal.h" 00019 #include "pal_plat_update.h" 00020 #include "pal_update.h" 00021 #include "pal_macros.h" 00022 00023 #include <stdlib.h> 00024 #include <stdio.h> 00025 #include <inttypes.h> 00026 00027 PAL_PRIVATE uint8_t palUpdateInitFlag = 0; 00028 00029 #define PAL_KILOBYTE 1024 00030 #define TRACE_GROUP "PAL" 00031 00032 #ifndef PAL_UPDATE_IMAGE_LOCATION 00033 #error "Please definee PAL_UPDATE_IMAGE_LOCATION to UPDATE_USE_FLASH (value 1) or UPDATE_USE_FS(2)" 00034 #endif 00035 00036 #if (PAL_UPDATE_IMAGE_LOCATION == PAL_UPDATE_USE_FS) 00037 #define SEEK_POS_INVALID 0xFFFFFFFF 00038 PAL_PRIVATE FirmwareHeader_t pal_pi_mbed_firmware_header; 00039 PAL_PRIVATE palImageSignalEvent_t g_palUpdateServiceCBfunc; 00040 PAL_PRIVATE palFileDescriptor_t image_file[IMAGE_COUNT_MAX]; 00041 PAL_PRIVATE bool last_read_nwrite[IMAGE_COUNT_MAX]; 00042 PAL_PRIVATE uint32_t last_seek_pos[IMAGE_COUNT_MAX]; 00043 PAL_PRIVATE bool valid_index(uint32_t index); 00044 PAL_PRIVATE size_t safe_read(uint32_t index, size_t offset, uint8_t *buffer, uint32_t size); 00045 PAL_PRIVATE size_t safe_write(uint32_t index, size_t offset, const uint8_t *buffer, uint32_t size); 00046 PAL_PRIVATE bool open_if_necessary(uint32_t index, bool read_nwrite); 00047 PAL_PRIVATE bool seek_if_necessary(uint32_t index, size_t offset, bool read_nwrite); 00048 PAL_PRIVATE bool close_if_necessary(uint32_t index); 00049 PAL_PRIVATE const char *image_path_alloc_from_index(uint32_t index); 00050 PAL_PRIVATE const char *header_path_alloc_from_index(uint32_t index); 00051 PAL_PRIVATE const char *path_join_and_alloc(const char * const * path_list); 00052 00053 PAL_PRIVATE palStatus_t pal_set_fw_header(palImageId_t index, FirmwareHeader_t *headerP); 00054 PAL_PRIVATE uint32_t internal_crc32(const uint8_t* buffer, uint32_t length); 00055 00056 00057 char* pal_imageGetFolder(void) 00058 { 00059 return PAL_UPDATE_FIRMWARE_DIR; 00060 } 00061 00062 00063 palStatus_t pal_imageInitAPI(palImageSignalEvent_t CBfunction) 00064 { 00065 palStatus_t status = PAL_SUCCESS; 00066 //printf("pal_imageInitAPI\r\n"); 00067 PAL_MODULE_INIT(palUpdateInitFlag); 00068 00069 // create absolute path. 00070 00071 00072 pal_fsMkDir(PAL_UPDATE_FIRMWARE_DIR); 00073 00074 g_palUpdateServiceCBfunc = CBfunction; 00075 g_palUpdateServiceCBfunc(PAL_IMAGE_EVENT_INIT); 00076 return status; 00077 } 00078 00079 palStatus_t pal_imageDeInit(void) 00080 { 00081 //printf("pal_plat_imageDeInit\r\n"); 00082 PAL_MODULE_DEINIT(palUpdateInitFlag); 00083 00084 for (int i = 0; i < IMAGE_COUNT_MAX; i++) 00085 { 00086 close_if_necessary(i); 00087 } 00088 00089 return PAL_SUCCESS; 00090 } 00091 00092 palStatus_t pal_imagePrepare(palImageId_t imageId, palImageHeaderDeails_t *headerDetails) 00093 { 00094 //printf("pal_imagePrepare(imageId=%lu, size=%lu)\r\n", imageId, headerDetails->imageSize); 00095 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00096 palStatus_t ret = PAL_ERR_INVALID_ARGUMENT ; 00097 uint8_t *buffer; 00098 00099 // write the image header to file system 00100 memset(&pal_pi_mbed_firmware_header,0,sizeof(pal_pi_mbed_firmware_header)); 00101 pal_pi_mbed_firmware_header.totalSize = headerDetails->imageSize; 00102 pal_pi_mbed_firmware_header.magic = FIRMWARE_HEADER_MAGIC; 00103 pal_pi_mbed_firmware_header.version = FIRMWARE_HEADER_VERSION; 00104 pal_pi_mbed_firmware_header.firmwareVersion = headerDetails->version; 00105 00106 // XXX: as the code expects buffer to have a SHA256, we better at least check for it and 00107 // fail operation early if it is not. 00108 if (headerDetails->hash.bufferLength == SIZEOF_SHA256) 00109 { 00110 memcpy(pal_pi_mbed_firmware_header.firmwareSHA256,headerDetails->hash.buffer,SIZEOF_SHA256); 00111 00112 pal_pi_mbed_firmware_header.checksum = internal_crc32((uint8_t *) &pal_pi_mbed_firmware_header, 00113 sizeof(pal_pi_mbed_firmware_header)); 00114 00115 ret = pal_set_fw_header(imageId, &pal_pi_mbed_firmware_header); 00116 } 00117 00118 /*Check that the size of the image is valid and reserve space for it*/ 00119 if (ret == PAL_SUCCESS) 00120 { 00121 buffer = malloc(PAL_KILOBYTE); 00122 if (NULL != buffer) 00123 { 00124 uint32_t writeCounter = 0; 00125 memset(buffer,0,PAL_KILOBYTE); 00126 while(writeCounter <= headerDetails->imageSize) 00127 { 00128 int written = safe_write(imageId,0,buffer,PAL_KILOBYTE); 00129 writeCounter+=PAL_KILOBYTE; 00130 if (PAL_KILOBYTE != written) 00131 { 00132 ret = PAL_ERR_UPDATE_ERROR ; 00133 } 00134 } 00135 if ((PAL_SUCCESS == ret) && (writeCounter < headerDetails->imageSize)) 00136 { 00137 //writing the last bytes 00138 int written = safe_write(imageId,0,buffer,(headerDetails->imageSize - writeCounter)); 00139 if ((headerDetails->imageSize - writeCounter) != written) 00140 { 00141 ret = PAL_ERR_UPDATE_ERROR ; 00142 } 00143 } 00144 free(buffer); 00145 if (PAL_SUCCESS == ret) 00146 { 00147 ret = pal_fsFseek(&(image_file[imageId]),0,PAL_FS_OFFSET_SEEKSET); 00148 } 00149 else 00150 { 00151 char *image_path=(char *)image_path_alloc_from_index(imageId); 00152 pal_fsUnlink(image_path); 00153 free(image_path); 00154 } 00155 } 00156 else 00157 { 00158 ret = PAL_ERR_NO_MEMORY ; 00159 } 00160 } 00161 if (PAL_SUCCESS == ret) 00162 { 00163 g_palUpdateServiceCBfunc(PAL_IMAGE_EVENT_PREPARE); 00164 } 00165 else 00166 { 00167 g_palUpdateServiceCBfunc(PAL_IMAGE_EVENT_ERROR); 00168 } 00169 00170 00171 return ret; 00172 } 00173 00174 palStatus_t pal_imageWrite(palImageId_t imageId, size_t offset, palConstBuffer_t *chunk) 00175 { 00176 //printf("pal_imageWrite(imageId=%lu, offset=%lu)\r\n", imageId, offset); 00177 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00178 palStatus_t ret = PAL_ERR_UPDATE_ERROR ; 00179 00180 int xfer_size_or_error = safe_write(imageId, offset, chunk->buffer, chunk->bufferLength); 00181 if ((xfer_size_or_error < 0) || ((uint32_t)xfer_size_or_error != chunk->bufferLength)) 00182 { 00183 //printf("Error writing to file\r\n"); 00184 } 00185 else 00186 { 00187 ret = PAL_SUCCESS; 00188 g_palUpdateServiceCBfunc(PAL_IMAGE_EVENT_WRITE); 00189 } 00190 00191 return ret; 00192 } 00193 00194 palStatus_t pal_imageFinalize(palImageId_t imageId) 00195 { 00196 //printf("pal_imageFinalize(id=%i)\r\n", imageId); 00197 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00198 palStatus_t ret = PAL_ERR_UPDATE_ERROR ; 00199 00200 if (close_if_necessary(imageId)) 00201 { 00202 ret = PAL_SUCCESS; 00203 g_palUpdateServiceCBfunc(PAL_IMAGE_EVENT_FINALIZE); 00204 } 00205 00206 return ret; 00207 } 00208 00209 palStatus_t pal_imageGetDirectMemoryAccess(palImageId_t imageId, void** imagePtr, size_t* imageSizeInBytes) 00210 { 00211 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00212 palStatus_t status = PAL_SUCCESS; 00213 status = pal_plat_imageGetDirectMemAccess(imageId, imagePtr, imageSizeInBytes); 00214 return status; 00215 } 00216 00217 palStatus_t pal_imageReadToBuffer(palImageId_t imageId, size_t offset, palBuffer_t *chunk) 00218 { 00219 //printf("pal_imageReadToBuffer(imageId=%lu, offset=%lu)\r\n", imageId, offset); 00220 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00221 palStatus_t ret = PAL_ERR_UPDATE_ERROR ; 00222 00223 int xfer_size_or_error = safe_read(imageId, offset, chunk->buffer, chunk->maxBufferLength); 00224 if (xfer_size_or_error < 0) 00225 { 00226 //printf("Error reading from file\r\n"); 00227 } 00228 else 00229 { 00230 chunk->bufferLength = xfer_size_or_error; 00231 g_palUpdateServiceCBfunc(PAL_IMAGE_EVENT_READTOBUFFER); 00232 ret = PAL_SUCCESS; 00233 } 00234 00235 return ret; 00236 } 00237 00238 palStatus_t pal_imageActivate(palImageId_t imageId) 00239 { 00240 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00241 palStatus_t status = PAL_SUCCESS; 00242 status = pal_plat_imageActivate(imageId); 00243 return status; 00244 } 00245 00246 palStatus_t pal_imageGetFirmwareHeaderData(palImageId_t imageId, palBuffer_t *headerData) 00247 { 00248 palStatus_t ret = PAL_SUCCESS; 00249 palFileDescriptor_t file = 0; 00250 size_t xfer_size; 00251 if (NULL == headerData) 00252 { 00253 return PAL_ERR_NULL_POINTER ; 00254 } 00255 if (headerData->maxBufferLength < sizeof(palFirmwareHeader_t)) 00256 { 00257 PAL_LOG_ERR("Firmware header buffer size is too small(is %" PRIu32 " needs to be at least %zu)\r\n" 00258 ,headerData->maxBufferLength, sizeof(palFirmwareHeader_t)); 00259 return PAL_ERR_INVALID_ARGUMENT ; 00260 } 00261 00262 const char *file_path = header_path_alloc_from_index(imageId); 00263 if (file_path) 00264 { 00265 ret = pal_fsFopen(file_path, PAL_FS_FLAG_READONLY, &file); 00266 if (ret == PAL_SUCCESS) 00267 { 00268 ret = pal_fsFread(&file, headerData->buffer, sizeof(palFirmwareHeader_t), &xfer_size); 00269 if (PAL_SUCCESS == ret) 00270 { 00271 headerData->bufferLength = xfer_size; 00272 } 00273 pal_fsFclose(&file); 00274 } 00275 free((void*)file_path); 00276 } 00277 else 00278 { 00279 ret = PAL_ERR_NO_MEMORY ; 00280 } 00281 return ret; 00282 } 00283 00284 palStatus_t pal_imageGetActiveHash(palBuffer_t *hash) 00285 { 00286 //printf("pal_imageGetActiveHash\r\n"); 00287 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00288 palStatus_t ret; 00289 00290 if (hash->maxBufferLength < SIZEOF_SHA256) 00291 { 00292 ret = PAL_ERR_BUFFER_TOO_SMALL ; 00293 goto exit; 00294 } 00295 00296 hash->bufferLength = 0; 00297 memset(hash->buffer, 0, hash->maxBufferLength); 00298 00299 ret = pal_plat_imageGetActiveHash(hash); 00300 if (ret == PAL_SUCCESS) 00301 { 00302 g_palUpdateServiceCBfunc(PAL_IMAGE_EVENT_GETACTIVEHASH); 00303 } 00304 00305 exit: 00306 return ret; 00307 } 00308 00309 palStatus_t pal_imageGetActiveVersion(palBuffer_t *version) 00310 { 00311 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00312 palStatus_t status = PAL_SUCCESS; 00313 status = pal_plat_imageGetActiveVersion(version); 00314 return status; 00315 } 00316 00317 palStatus_t pal_imageWriteDataToMemory(palImagePlatformData_t dataId, const palConstBuffer_t * const dataBuffer) 00318 { 00319 palStatus_t status = PAL_SUCCESS; 00320 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00321 // this switch is for further use when there will be more options 00322 switch(dataId) 00323 { 00324 case PAL_IMAGE_DATA_HASH: 00325 status = pal_plat_imageWriteHashToMemory (dataBuffer); 00326 break; 00327 default: 00328 { 00329 PAL_LOG_ERR("Update image write to memory error"); 00330 status = PAL_ERR_GENERIC_FAILURE ; 00331 } 00332 } 00333 return status; 00334 } 00335 00336 PAL_PRIVATE palStatus_t pal_set_fw_header(palImageId_t index, FirmwareHeader_t *headerP) 00337 { 00338 palStatus_t ret; 00339 palFileDescriptor_t file = 0; 00340 size_t xfer_size; 00341 00342 const char *file_path = header_path_alloc_from_index(index); 00343 ret = pal_fsFopen(file_path, PAL_FS_FLAG_READWRITETRUNC, &file); 00344 if (ret != PAL_SUCCESS) 00345 { 00346 //printf("pal_fsFopen returned 0x%x\r\n", ret); 00347 goto exit; 00348 } 00349 00350 ret = pal_fsFwrite(&file, headerP, sizeof(FirmwareHeader_t), &xfer_size); 00351 if (ret != PAL_SUCCESS) 00352 { 00353 //printf("pal_fsFread returned 0x%x\r\n", ret); 00354 goto exit; 00355 } 00356 else if (xfer_size != sizeof(FirmwareHeader_t)) 00357 { 00358 //printf("Size written %lu expected %lu\r\n", xfer_size, sizeof(FirmwareHeader_t)); 00359 goto exit; 00360 } 00361 00362 ret = PAL_SUCCESS; 00363 00364 exit: 00365 if (file != 0) 00366 { 00367 ret = pal_fsFclose(&file); 00368 if (ret != PAL_SUCCESS) 00369 { 00370 //printf("Error closing file %s\r\n", file_path); 00371 ret = PAL_ERR_UPDATE_ERROR ; 00372 } 00373 } 00374 free((void*)file_path); 00375 00376 return ret; 00377 } 00378 00379 /** 00380 * @brief Bitwise CRC32 calculation 00381 * @details Modified from ARM Keil code: 00382 * http://www.keil.com/appnotes/docs/apnt_277.asp 00383 * 00384 * @param buffer Input byte array. 00385 * @param length Number of bytes in array. 00386 * 00387 * @return CRC32 00388 */ 00389 PAL_PRIVATE uint32_t internal_crc32(const uint8_t* buffer, 00390 uint32_t length) 00391 { 00392 const uint8_t* current = buffer; 00393 uint32_t crc = 0xFFFFFFFF; 00394 00395 while (length--) 00396 { 00397 crc ^= *current++; 00398 00399 for (uint32_t counter = 0; counter < 8; counter++) 00400 { 00401 if (crc & 1) 00402 { 00403 crc = (crc >> 1) ^ 0xEDB88320; 00404 } 00405 else 00406 { 00407 crc = crc >> 1; 00408 } 00409 } 00410 } 00411 00412 return (crc ^ 0xFFFFFFFF); 00413 } 00414 00415 PAL_PRIVATE bool valid_index(uint32_t index) 00416 { 00417 return (index < IMAGE_COUNT_MAX); 00418 } 00419 00420 PAL_PRIVATE size_t safe_read(uint32_t index, size_t offset, uint8_t *buffer, uint32_t size) 00421 { 00422 const bool read_nwrite = true; 00423 size_t xfer_size = 0; 00424 palStatus_t status; 00425 00426 if ((!valid_index(index)) || (!open_if_necessary(index, read_nwrite)) || (!seek_if_necessary(index, offset, read_nwrite))) 00427 { 00428 return 0; 00429 } 00430 00431 status = pal_fsFread(&(image_file[index]), buffer, size, &xfer_size); 00432 if (status == PAL_SUCCESS) 00433 { 00434 last_read_nwrite[index] = read_nwrite; 00435 last_seek_pos[index] += xfer_size; 00436 } 00437 00438 return xfer_size; 00439 } 00440 00441 PAL_PRIVATE size_t safe_write(uint32_t index, size_t offset, const uint8_t *buffer, uint32_t size) 00442 { 00443 const bool read_nwrite = false; 00444 size_t xfer_size = 0; 00445 palStatus_t status; 00446 if ((!valid_index(index)) || (!open_if_necessary(index, read_nwrite)) || (!seek_if_necessary(index, offset, read_nwrite))) 00447 { 00448 return 0; 00449 } 00450 status = pal_fsFseek(&(image_file[index]), offset, PAL_FS_OFFSET_SEEKSET); 00451 if (status == PAL_SUCCESS) 00452 { 00453 status = pal_fsFwrite(&(image_file[index]), buffer, size, &xfer_size); 00454 if (status == PAL_SUCCESS) 00455 { 00456 last_read_nwrite[index] = read_nwrite; 00457 last_seek_pos[index] += xfer_size; 00458 00459 if (size != xfer_size) 00460 { 00461 //printf("WRONG SIZE expected %u got %lu\r\n", size, xfer_size); 00462 return 0; 00463 } 00464 00465 } 00466 } 00467 00468 return xfer_size; 00469 } 00470 00471 PAL_PRIVATE bool open_if_necessary(uint32_t index, bool read_nwrite) 00472 { 00473 if (!valid_index(index)) 00474 { 00475 return false; 00476 } 00477 if ( (unsigned int*)image_file[index] == NULL ) 00478 { 00479 const char *file_path = image_path_alloc_from_index(index); 00480 pal_fsFileMode_t mode = read_nwrite ? PAL_FS_FLAG_READWRITE : PAL_FS_FLAG_READWRITETRUNC; 00481 00482 palStatus_t ret = pal_fsFopen(file_path, mode, &(image_file[index])); 00483 free((void*)file_path); 00484 last_seek_pos[index] = 0; 00485 if (ret != PAL_SUCCESS) 00486 { 00487 return false; 00488 } 00489 } 00490 00491 return true; 00492 } 00493 00494 PAL_PRIVATE bool seek_if_necessary(uint32_t index, size_t offset, bool read_nwrite) 00495 { 00496 if (!valid_index(index)) 00497 { 00498 return false; 00499 } 00500 00501 if ((read_nwrite != last_read_nwrite[index]) || 00502 (offset != last_seek_pos[index])) 00503 { 00504 palStatus_t ret = pal_fsFseek(&(image_file[index]), offset, PAL_FS_OFFSET_SEEKSET); 00505 if (ret != PAL_SUCCESS) 00506 { 00507 last_seek_pos[index] = SEEK_POS_INVALID; 00508 return false; 00509 } 00510 } 00511 00512 last_read_nwrite[index] = read_nwrite; 00513 last_seek_pos[index] = offset; 00514 00515 return true; 00516 } 00517 00518 PAL_PRIVATE bool close_if_necessary(uint32_t index) 00519 { 00520 if (!valid_index(index)) 00521 { 00522 return false; 00523 } 00524 00525 palFileDescriptor_t file = image_file[index]; 00526 image_file[index] = 0; 00527 last_seek_pos[index] = SEEK_POS_INVALID; 00528 00529 if (file != 0) 00530 { 00531 palStatus_t ret = pal_fsFclose(&file); 00532 if (ret != 0) 00533 { 00534 return false; 00535 } 00536 } 00537 00538 return true; 00539 } 00540 00541 PAL_PRIVATE const char *image_path_alloc_from_index(uint32_t index) 00542 { 00543 char file_name[32] = {0}; 00544 snprintf(file_name, sizeof(file_name)-1, "image_%" PRIu32 ".bin", index); 00545 file_name[sizeof(file_name) - 1] = 0; 00546 const char * const path_list[] = { 00547 (char*)PAL_UPDATE_FIRMWARE_DIR, 00548 file_name, 00549 NULL 00550 }; 00551 00552 return path_join_and_alloc(path_list); 00553 } 00554 00555 PAL_PRIVATE const char *header_path_alloc_from_index(uint32_t index) 00556 { 00557 char file_name[32] = {0}; 00558 00559 if (ACTIVE_IMAGE_INDEX == index) 00560 { 00561 snprintf(file_name, sizeof(file_name)-1, "header_active.bin"); 00562 } 00563 else 00564 { 00565 snprintf(file_name, sizeof(file_name)-1, "header_%" PRIu32 ".bin", index); 00566 } 00567 00568 const char * const path_list[] = { 00569 (char*)PAL_UPDATE_FIRMWARE_DIR, 00570 file_name, 00571 NULL 00572 }; 00573 00574 return path_join_and_alloc(path_list); 00575 } 00576 00577 00578 PAL_PRIVATE const char *path_join_and_alloc(const char * const * path_list) 00579 { 00580 uint32_t string_size = 1; 00581 uint32_t pos = 0; 00582 00583 // Determine size of string to return 00584 while (path_list[pos] != NULL) 00585 { 00586 // Size of string and space for separator 00587 string_size += strlen(path_list[pos]) + 1; 00588 pos++; 00589 } 00590 00591 // Allocate and initialize memory 00592 char *path = (char*)malloc(string_size); 00593 if (NULL != path) 00594 { 00595 memset(path, 0, string_size); 00596 // Write joined path 00597 pos = 0; 00598 while (path_list[pos] != NULL) 00599 { 00600 bool has_slash = '/' == path_list[pos][strlen(path_list[pos]) - 1]; 00601 bool is_last = NULL == path_list[pos + 1]; 00602 strncat(path, path_list[pos], string_size - strlen(path) - 1); 00603 if (!has_slash && !is_last) 00604 { 00605 strncat(path, "/", string_size - strlen(path) - 1); 00606 } 00607 pos++; 00608 } 00609 } 00610 return path; 00611 } 00612 00613 00614 00615 00616 #elif (PAL_UPDATE_IMAGE_LOCATION == PAL_UPDATE_USE_FLASH) 00617 00618 palStatus_t pal_imageInitAPI(palImageSignalEvent_t CBfunction) 00619 { 00620 PAL_MODULE_INIT(palUpdateInitFlag); 00621 palStatus_t status = PAL_SUCCESS; 00622 status = pal_plat_imageInitAPI(CBfunction); 00623 return status; 00624 } 00625 00626 palStatus_t pal_imageDeInit(void) 00627 { 00628 PAL_MODULE_DEINIT(palUpdateInitFlag); 00629 palStatus_t status = PAL_SUCCESS; 00630 status = pal_plat_imageDeInit(); 00631 return status; 00632 } 00633 00634 00635 00636 palStatus_t pal_imagePrepare(palImageId_t imageId, palImageHeaderDeails_t *headerDetails) 00637 { 00638 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00639 palStatus_t status = PAL_SUCCESS; 00640 pal_plat_imageSetHeader(imageId,headerDetails); 00641 status = pal_plat_imageReserveSpace(imageId, headerDetails->imageSize); 00642 00643 return status; 00644 } 00645 00646 palStatus_t pal_imageWrite (palImageId_t imageId, size_t offset, palConstBuffer_t *chunk) 00647 { 00648 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00649 palStatus_t status = PAL_SUCCESS; 00650 status = pal_plat_imageWrite(imageId, offset, chunk); 00651 return status; 00652 } 00653 00654 palStatus_t pal_imageFinalize(palImageId_t imageId) 00655 { 00656 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00657 palStatus_t status = PAL_SUCCESS; 00658 status = pal_plat_imageFlush(imageId); 00659 return status; 00660 } 00661 00662 palStatus_t pal_imageGetDirectMemoryAccess(palImageId_t imageId, void** imagePtr, size_t* imageSizeInBytes) 00663 { 00664 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00665 palStatus_t status = PAL_SUCCESS; 00666 status = pal_plat_imageGetDirectMemAccess(imageId, imagePtr, imageSizeInBytes); 00667 return status; 00668 } 00669 00670 palStatus_t pal_imageReadToBuffer(palImageId_t imageId, size_t offset, palBuffer_t *chunk) 00671 { 00672 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00673 palStatus_t status = PAL_SUCCESS; 00674 00675 status = pal_plat_imageReadToBuffer(imageId,offset,chunk); 00676 return status; 00677 } 00678 00679 palStatus_t pal_imageActivate(palImageId_t imageId) 00680 { 00681 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00682 palStatus_t status = PAL_SUCCESS; 00683 status = pal_plat_imageActivate(imageId); 00684 return status; 00685 } 00686 00687 palStatus_t pal_imageGetActiveHash(palBuffer_t *hash) 00688 { 00689 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00690 palStatus_t status = PAL_SUCCESS; 00691 status = pal_plat_imageGetActiveHash(hash); 00692 return status; 00693 } 00694 00695 palStatus_t pal_imageGetActiveVersion(palBuffer_t *version) 00696 { 00697 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00698 palStatus_t status = PAL_SUCCESS; 00699 status = pal_plat_imageGetActiveVersion(version); 00700 return status; 00701 } 00702 00703 palStatus_t pal_imageWriteDataToMemory(palImagePlatformData_t dataId, const palConstBuffer_t * const dataBuffer) 00704 { 00705 palStatus_t status = PAL_SUCCESS; 00706 PAL_MODULE_IS_INIT(palUpdateInitFlag); 00707 // this switch is for further use when there will be more options 00708 switch(dataId) 00709 { 00710 case PAL_IMAGE_DATA_HASH: 00711 status = pal_plat_imageWriteHashToMemory (dataBuffer); 00712 break; 00713 default: 00714 { 00715 PAL_LOG_ERR("Update write data to mem status %d", (int)dataId); 00716 status = PAL_ERR_GENERIC_FAILURE ; 00717 } 00718 } 00719 return status; 00720 } 00721 00722 #endif
Generated on Mon Aug 29 2022 19:53:41 by
