How to distinguish 1st boot from 2nd or later boot after finishing OTA update
02/45/2020 | 06:21 AM
Hi,
With BGM123, I want my own application to distinguish 1st boot from 2nd or later boot after finishing OTA update so that BGM123 application can automatically start advertising only initial boot just after OTA update. What is the easiest way for my application main to get this kind of flag?
Is there any tailored/dedicated flag in order for application to detect whether the boot is 1st or not? Any recommendations to meet this requirement if you do NOT have any prearranged mechanism for this?
Regards,
Hayashi
Bluetooth Low Energy
Discussion Forums
Unanswered
Hi,
you can use the Persistent Storage to store a flag, set it to true at the first boot, and check it at each startup. When an OTA is initiated, you can clear it before resetting to OTA mode.
For PS Key usage check the Persistent Store chapter in Bluetooth Smart API Reference manual.
What is the default values in Persistent Storage just after erasing the PS Key area?
I tried to follow KBA_BT_0309 to load a default flag from PS Key, but it fails with ps_load_object / gecko_cmd_flash_ps_load returning 0x502 which seems like meaning ps_key_not_found.
Does it mean gecko_cmd_flash_ps_load always fails until any values are written in PS Key by gecko_cmd_flash_ps_save?
If so, how can we set the default value just after our device with BGM123 is manufactured with our default firmware? Is it possible to flash PS key area by Simplicity Commander?
uint8_t val;
uint16_t result;
gecko_cmd_flash_ps_erase(0x4000); // erase the value
result = ps_load_object(0x4000, &val, sizeof(val));
if(result == 0) {
// value was loaded OK
print("val=%X\n", val);
} else {
// value not OK (either not stored in PS or length of the data does not match the expected value)
print("Failed to load val w/ err 0x%X\n", result);
}
Regards,
Hayashi
0
Hi,
yes, the ps_load will fail if the used key is not defined earlier. In the application at startup, when the ps_key not found error is thrown, than it means that it was not defined earlier. In this case you can create and set your flag.
After an OTA update the PS key will remind there, so this should happen only once, at the very first startup. Note, that the value will also remain the same after the update, so you have to take care to change it before the OTA starts.
Thanks for your feedback. Is it possible for Simplicity Commander to revert the PS key to "not-defined" state for a test purpose?
Which absolute address does the PS key=0x4000 actually indicate?
Regards,
Hayashi
0
Hi,
sorry for the late reply!
The PSKeys do not have a fixed address, because the wear leveling algorithm can change the location anytime to preserve the flash.
From the Simplicity commander you can erase flash sections, but only page-wise, so if you do that, than any other values stored in the flash will be also lost.
How to distinguish 1st boot from 2nd or later boot after finishing OTA update
Hi,
With BGM123, I want my own application to distinguish 1st boot from 2nd or later boot after finishing OTA update so that BGM123 application can automatically start advertising only initial boot just after OTA update. What is the easiest way for my application main to get this kind of flag?
Is there any tailored/dedicated flag in order for application to detect whether the boot is 1st or not? Any recommendations to meet this requirement if you do NOT have any prearranged mechanism for this?
Regards,
Hayashi
Hi,
you can use the Persistent Storage to store a flag, set it to true at the first boot, and check it at each startup. When an OTA is initiated, you can clear it before resetting to OTA mode.
For PS Key usage check the Persistent Store chapter in Bluetooth Smart API Reference manual.
Hope it helps,
Balázs
Hi baleidec,
What is the default values in Persistent Storage just after erasing the PS Key area?
I tried to follow KBA_BT_0309 to load a default flag from PS Key, but it fails with ps_load_object / gecko_cmd_flash_ps_load returning 0x502 which seems like meaning ps_key_not_found.
Does it mean gecko_cmd_flash_ps_load always fails until any values are written in PS Key by gecko_cmd_flash_ps_save?
If so, how can we set the default value just after our device with BGM123 is manufactured with our default firmware? Is it possible to flash PS key area by Simplicity Commander?
Regards,
Hayashi
Hi,
yes, the ps_load will fail if the used key is not defined earlier. In the application at startup, when the ps_key not found error is thrown, than it means that it was not defined earlier. In this case you can create and set your flag.
After an OTA update the PS key will remind there, so this should happen only once, at the very first startup. Note, that the value will also remain the same after the update, so you have to take care to change it before the OTA starts.
Best regards,
Balázs
Hi baleidec,
Thanks for your feedback. Is it possible for Simplicity Commander to revert the PS key to "not-defined" state for a test purpose?
Which absolute address does the PS key=0x4000 actually indicate?
Regards,
Hayashi
Hi,
sorry for the late reply!
The PSKeys do not have a fixed address, because the wear leveling algorithm can change the location anytime to preserve the flash.
From the Simplicity commander you can erase flash sections, but only page-wise, so if you do that, than any other values stored in the flash will be also lost.
Best regards,
Balázs