Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSAL APIs to read/write firmware #27

Draft
wants to merge 2 commits into
base: osal
Choose a base branch
from
Draft

OSAL APIs to read/write firmware #27

wants to merge 2 commits into from

Conversation

manojnacsl
Copy link
Collaborator

@manojnacsl manojnacsl commented Dec 12, 2024

Proposed OSAL APIs to read/write firmware

/****************************************************************************
 * @fn   osal_read_firmware
 *
 * @brief read firmware image from storage(file/flash)
 *
 * input parameters
 *  @param[in] slotid indicating RUN/UPLOAD/BACKUP slot
 *  @param[in] pointer to _Csmp_Slothdr slot structure
 *  @param[in] size of _Csmp_Slothdr slot structure
 *
 * output parameters
 * @return returns 0 on success and -1 on error
 *****************************************************************************/
osal_basetype_t osal_read_firmware(uint8_t slotid, void* slot, uint32_t size);

/****************************************************************************
 * @fn   osal_write_firmware
 *
 * @brief write firmware image to storage(file/flash)
 *
 * input parameters
 *  @param[in] slotid indicating RUN/UPLOAD/BACKUP slot
 *  @param[in] pointer to _Csmp_Slothdr slot structure
 *  @param[in] size of _Csmp_Slothdr slot structure
 *
 * output parameters
 * @return returns 0 on success and -1 on error
 *****************************************************************************/
osal_basetype_t osal_write_firmware(uint8_t slotid, void* slot, uint32_t size);

@manojnacsl manojnacsl self-assigned this Dec 12, 2024
@manojnacsl manojnacsl marked this pull request as draft December 12, 2024 15:41
@ismilak
Copy link
Collaborator

ismilak commented Dec 16, 2024

Hi @manojnacsl !
I tested all the platforms and there are build issues for all of them. The main target linux platform doesn't work neither.
I note that there was an other error introduced by previous PR (osal/HEAD~1)

My current errors are from the linux build:

$ ./build.sh linux
....

./osal/linux/osal_linux.c:432:10: error: use of undeclared identifier 'RUN_IMAGE'
    case RUN_IMAGE:
         ^
./osal/linux/osal_linux.c:435:10: error: use of undeclared identifier 'UPLOAD_IMAGE'
    case UPLOAD_IMAGE:
         ^
./osal/linux/osal_linux.c:438:10: error: use of undeclared identifier 'BACKUP_IMAGE'
    case BACKUP_IMAGE:
         ^
./osal/linux/osal_linux.c:466:10: error: use of undeclared identifier 'RUN_IMAGE'
    case RUN_IMAGE:
         ^
./osal/linux/osal_linux.c:469:10: error: use of undeclared identifier 'UPLOAD_IMAGE'
    case UPLOAD_IMAGE:
         ^
./osal/linux/osal_linux.c:476:46: error: member reference base type 'void' is not a structure or union
      bytes = fwrite((uint8_t*) &slot[slotid].image, sizeof(uint8_t), slot[slotid].filesize, file);
                                 ~~~~~~~~~~~~^~~~~~
./osal/linux/osal_linux.c:476:83: error: member reference base type 'void' is not a structure or union
      bytes = fwrite((uint8_t*) &slot[slotid].image, sizeof(uint8_t), slot[slotid].filesize, file);
                                                                      ~~~~~~~~~~~~^~~~~~~~~
./osal/linux/osal_linux.c:482:10: error: use of undeclared identifier 'BACKUP_IMAGE'
    case BACKUP_IMAGE:

@manojnacsl
Copy link
Collaborator Author

Hi @manojnacsl ! I tested all the platforms and there are build issues for all of them. The main target linux platform doesn't work neither. I note that there was an other error introduced by previous PR (osal/HEAD~1)

My current errors are from the linux build:

$ ./build.sh linux
....

./osal/linux/osal_linux.c:432:10: error: use of undeclared identifier 'RUN_IMAGE'
    case RUN_IMAGE:
         ^
./osal/linux/osal_linux.c:435:10: error: use of undeclared identifier 'UPLOAD_IMAGE'
    case UPLOAD_IMAGE:
         ^
./osal/linux/osal_linux.c:438:10: error: use of undeclared identifier 'BACKUP_IMAGE'
    case BACKUP_IMAGE:
         ^
./osal/linux/osal_linux.c:466:10: error: use of undeclared identifier 'RUN_IMAGE'
    case RUN_IMAGE:
         ^
./osal/linux/osal_linux.c:469:10: error: use of undeclared identifier 'UPLOAD_IMAGE'
    case UPLOAD_IMAGE:
         ^
./osal/linux/osal_linux.c:476:46: error: member reference base type 'void' is not a structure or union
      bytes = fwrite((uint8_t*) &slot[slotid].image, sizeof(uint8_t), slot[slotid].filesize, file);
                                 ~~~~~~~~~~~~^~~~~~
./osal/linux/osal_linux.c:476:83: error: member reference base type 'void' is not a structure or union
      bytes = fwrite((uint8_t*) &slot[slotid].image, sizeof(uint8_t), slot[slotid].filesize, file);
                                                                      ~~~~~~~~~~~~^~~~~~~~~
./osal/linux/osal_linux.c:482:10: error: use of undeclared identifier 'BACKUP_IMAGE'
    case BACKUP_IMAGE:

@ismilak
Please note this is a draft PR opened to primarily discuss on the proposal for Firmware read/write OSAL APIs. This is not the final change, but interim changes to conclude on the OSAL APIs.
Let's focus to finalize on the OSAL APIs (while we can fix the build errors as well in parallel)

Regarding the earlier build errors for FreeRTOS/EFR32, as informed in the previous call - our intent was to only add the platform agnostic CSMP encode/decode changes for FreeRTOS/EFR32 in the interest of time - there could be trivial build errors on these platforms which could be addressed during integration. Linux taget built fine and was used for manual testing.

FILE *file = NULL;

switch(slotid) {
case RUN_IMAGE:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the enumeration be in osal.h? It will be required for other platforms too. If csmp_info is a library header, the enumeration should be moved into osal.h

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, the slots are owned by the osal an consumed by the csmp agent library

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ismilak @silabs-ThibautC - thanks for your feedback. Sounds good, I'll move the declaration of xxx_IMAGE enum and _Csmp_Slothdr to osal.h and accordingly update the API signature.

* @brief read firmware image from storage(file/flash)
*
* input parameters
* @param[in] slotid indicating RUN/UPLOAD/BACKUP slot
Copy link
Collaborator

@ismilak ismilak Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My recommendations for the new APIs:

  • slotid type should be osal_basetype_t to be consistent
  • _Csmp_Slothdr can be defined in osal_platform_types.h. In this case it can be portable for different platforms, using void* to access raw data is not a "safe" solution. Using appropriate type has more benefits.
  • size should be osal_ssize_t or we can introduce a new unsigned size type (this argument is not required if the slot hdr is defined in osal_platform_types.h )

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ismilak - thanks for your feedback. Sounds good, I'll move the declaration of xxx_IMAGE enum and _Csmp_Slothdr to osal.h and accordingly update the API signature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants