Skip to content

Commit 870523c

Browse files
committed
Implemente write slot OSAL API to make slot read/write operation explicit
1 parent fd1f74e commit 870523c

File tree

8 files changed

+111
-18
lines changed

8 files changed

+111
-18
lines changed

osal/efr32_wisun/osal_efr32_wisun.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
#define OSAL_EFR32_WISUN_NVM_KEY_BACKUP_IMG (OSAL_EFR32_WISUN_NVM_KEY_BASE + 0x0002U)
3131
#define GECKO_BTL_SLOT_CPY_CHUNK_SIZE 1024U
3232

33-
33+
#define GECKO_BTL_UPLOAD_SLOT_ID 0
34+
#define GECKO_BTL_BACKUP_SLOT_ID 1
3435

3536
struct trickle_timer {
3637
uint32_t t0;
@@ -621,6 +622,29 @@ osal_basetype_t osal_write_firmware_slothdr(uint8_t slotid, osal_csmp_slothdr_t
621622
return OSAL_SUCCESS;
622623
}
623624

625+
osal_basetype_t osal_write_storage(osal_slotid_t slotid,
626+
osal_csmp_slothdr_t *slot,
627+
uint32_t offset,
628+
uint8_t *data,
629+
uint32_t len)
630+
{
631+
int32_t ret = 0L;
632+
633+
if (slot == NULL || data == NULL || !len) {
634+
return OSAL_FAILURE;
635+
}
636+
637+
ret = bootloader_writeStorage(__slotid2gblslotid(slotid), offset, data, len);
638+
639+
if (ret != BOOTLOADER_OK) {
640+
DPRINTF("write_storage: bootloader_writeStorage failed\n");
641+
return OSAL_FAILURE;
642+
}
643+
644+
return OSAL_SUCCESS;
645+
}
646+
647+
624648
osal_basetype_t osal_deploy_and_reboot_firmware(osal_slotid_t slotid, osal_csmp_slothdr_t *slot)
625649
{
626650
uint32_t gecko_btl_slot_id = 0UL;

osal/efr32_wisun/osal_platform_types.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,4 @@ typedef int osal_sd_set_t;
5555

5656
#define CSMP_IMAGE_HDR_SIZE 256
5757

58-
#define GECKO_BTL_UPLOAD_SLOT_ID 0
59-
60-
#define GECKO_BTL_BACKUP_SLOT_ID 1
61-
6258
#endif

osal/freertos/osal_freertos.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,22 @@ osal_basetype_t osal_write_firmware_slothdr(osal_slotid_t slotid, osal_csmp_slot
524524
return OSAL_SUCCESS;
525525
}
526526

527+
osal_basetype_t osal_write_storage(osal_slotid_t slotid,
528+
osal_csmp_slothdr_t *slot,
529+
uint32_t offset,
530+
uint8_t *data,
531+
uint32_t len)
532+
{
533+
(void) slotid;
534+
if (slot == NULL || data == NULL || !len) {
535+
return OSAL_FAILURE;
536+
}
537+
538+
(void) memcpy(&slot->image[offset], data, len);
539+
540+
return OSAL_SUCCESS;
541+
}
542+
527543
osal_basetype_t osal_deploy_and_reboot_firmware(osal_slotid_t slotid, osal_csmp_slothdr_t *slot)
528544
{
529545
(void) slotid;

osal/linux/osal_linux.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,22 @@ osal_basetype_t osal_write_firmware_slothdr(osal_slotid_t slotid, osal_csmp_slot
499499
return OSAL_SUCCESS;
500500
}
501501

502+
osal_basetype_t osal_write_storage(osal_slotid_t slotid,
503+
osal_csmp_slothdr_t *slot,
504+
uint32_t offset,
505+
uint8_t *data,
506+
uint32_t len)
507+
{
508+
(void) slotid;
509+
if (slot == NULL || data == NULL || !len) {
510+
return OSAL_FAILURE;
511+
}
512+
513+
(void) memcpy(&slot->image[offset], data, len);
514+
515+
return OSAL_SUCCESS;
516+
}
517+
502518

503519
osal_basetype_t osal_deploy_and_reboot_firmware(osal_slotid_t slotid, osal_csmp_slothdr_t *slot)
504520
{

osal/osal.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,21 @@ osal_basetype_t osal_read_firmware_slothdr(osal_slotid_t slotid, osal_csmp_sloth
608608
*****************************************************************************/
609609
osal_basetype_t osal_write_firmware_slothdr(osal_slotid_t slotid, osal_csmp_slothdr_t *slot);
610610

611+
/****************************************************************************
612+
* @fn osal_write_storage
613+
* @brief write data to the storage
614+
* @param[in] slotid slot id
615+
* @param[in] slot slot structure
616+
* @param[in] offset offset to write
617+
* @param[in] data data to write
618+
* @param[in] len length of data
619+
* @return returns 0 on success and -1 on error
620+
*****************************************************************************/
621+
osal_basetype_t osal_write_storage(osal_slotid_t slotid,
622+
osal_csmp_slothdr_t *slot,
623+
uint32_t offset,
624+
uint8_t *data,
625+
uint32_t len);
611626

612627
/****************************************************************************
613628
* @fn osal_deploy_and_reboot_firmware

sample/tlvs/efr32_wisun_tlvs.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,8 @@ void imageBlock_post(tlvid_t tlvid, Image_Block *tlv) {
803803
DPRINTF("sample_firmwaremgmt: Valid image block %lu write offset=%lu\n",
804804
g_imageBlock.blocknum, offset);
805805

806+
osal_basetype_t ret = OSAL_FAILURE;
806807
uint32_t gecko_btl_slot_offset = offset;
807-
int32_t gecko_btl_ret = 0;
808808
uint32_t gecko_btl_chunk_size = g_imageBlock.blockdata.len;
809809
uint8_t *gecko_btl_data_ptr = g_imageBlock.blockdata.data;
810810

@@ -821,13 +821,17 @@ void imageBlock_post(tlvid_t tlvid, Image_Block *tlv) {
821821
gecko_btl_data_ptr = g_imageBlock.blockdata.data;
822822

823823
}
824-
gecko_btl_ret = bootloader_writeStorage(GECKO_BTL_UPLOAD_SLOT_ID,
825-
gecko_btl_slot_offset,
826-
gecko_btl_data_ptr,
827-
gecko_btl_chunk_size);
824+
825+
ret = osal_write_storage(UPLOAD_IMAGE, &g_slothdr[UPLOAD_IMAGE],
826+
gecko_btl_slot_offset, gecko_btl_data_ptr, gecko_btl_chunk_size);
828827

829-
printf("[FW UPDATE] Image block POST %lu, ret: %ld, offset %lu (slot offset: %lu):\n",
830-
g_imageBlock.blocknum, gecko_btl_ret, offset, gecko_btl_slot_offset);
828+
if (ret != OSAL_SUCCESS) {
829+
DPRINTF("sample_firmwaremgmt: Failed to write image block %lu to slot\n",
830+
g_imageBlock.blocknum);
831+
tlv->retval = false;
832+
g_downloadbusy = false;
833+
return;
834+
}
831835

832836
mapval ^= (1 << bit);
833837
g_slothdr[UPLOAD_IMAGE].nblkmap[word] = mapval;

sample/tlvs/freertos_tlvs.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -786,14 +786,25 @@ void imageBlock_post(tlvid_t tlvid, Image_Block *tlv) {
786786

787787
return;
788788
}
789+
790+
osal_basetype_t ret = OSAL_FAILURE;
791+
789792
// Write image block to slot at valid offset
790793
if (offset < OSAL_CSMP_FWMGMT_SLOTIMG_SIZE &&
791794
((offset + g_imageBlock.blockdata.len) < OSAL_CSMP_FWMGMT_SLOTIMG_SIZE)) {
792795
DPRINTF("sample_firmwaremgmt: Valid image block %u write offset=%u\n",
793796
g_imageBlock.blocknum, offset);
794-
memcpy(&g_slothdr[UPLOAD_IMAGE].image[offset], g_imageBlock.blockdata.data,
795-
g_imageBlock.blockdata.len);
796-
797+
798+
ret = osal_write_storage(UPLOAD_IMAGE, &g_slothdr[UPLOAD_IMAGE],
799+
offset, g_imageBlock.blockdata.data, g_imageBlock.blockdata.len);
800+
if (ret != OSAL_SUCCESS) {
801+
DPRINTF("sample_firmwaremgmt: Failed to write image block %lu to slot\n",
802+
g_imageBlock.blocknum);
803+
tlv->retval = false;
804+
g_downloadbusy = false;
805+
return;
806+
}
807+
797808
mapval ^= (1 << bit);
798809
g_slothdr[UPLOAD_IMAGE].nblkmap[word] = mapval;
799810

sample/tlvs/linux_tlvs.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -846,14 +846,25 @@ void imageBlock_post(tlvid_t tlvid, Image_Block *tlv) {
846846

847847
return;
848848
}
849+
850+
osal_basetype_t ret = OSAL_FAILURE;
851+
849852
// Write image block to slot at valid offset
850853
if (offset < OSAL_CSMP_FWMGMT_SLOTIMG_SIZE &&
851854
((offset + g_imageBlock.blockdata.len) < OSAL_CSMP_FWMGMT_SLOTIMG_SIZE)) {
852855
DPRINTF("sample_firmwaremgmt: Valid image block %u write offset=%u\n",
853856
g_imageBlock.blocknum, offset);
854-
memcpy(&g_slothdr[UPLOAD_IMAGE].image[offset], g_imageBlock.blockdata.data,
855-
g_imageBlock.blockdata.len);
856-
857+
858+
ret = osal_write_storage(UPLOAD_IMAGE, &g_slothdr[UPLOAD_IMAGE],
859+
offset, g_imageBlock.blockdata.data, g_imageBlock.blockdata.len);
860+
if (ret != OSAL_SUCCESS) {
861+
DPRINTF("sample_firmwaremgmt: Failed to write image block %lu to slot\n",
862+
g_imageBlock.blocknum);
863+
tlv->retval = false;
864+
g_downloadbusy = false;
865+
return;
866+
}
867+
857868
mapval ^= (1 << bit);
858869
g_slothdr[UPLOAD_IMAGE].nblkmap[word] = mapval;
859870

0 commit comments

Comments
 (0)