Skip to content

Commit a60e1bc

Browse files
authored
Minor fix and improvements (#69)
* fix: device presist data use proper uicr api * fix: minor typo * optim: uicr customer api support larger length --------- Signed-off-by: Adam BZH <adam@onekey.so>
1 parent 7055a1e commit a60e1bc

4 files changed

Lines changed: 13 additions & 8 deletions

File tree

app/device_config.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ deviceCfg_t* deviceConfig_p = NULL;
2828
// UICR 31 is used for battery profile flag
2929
uint32_t devicePresistence_get_battery_profile_flag(void)
3030
{
31-
return NRF_UICR->CUSTOMER[31];
31+
uint32_t flag = 0xFFFFFFFF;
32+
uicr_get_customer(31 * sizeof(uint32_t), &flag, sizeof(uint32_t));
33+
return flag;
3234
}
3335
bool devicePresistence_set_battery_profile_flag(uint32_t flag)
3436
{
35-
return uicr_write((uint32_t)(&(NRF_UICR->CUSTOMER[31])), &flag, 1);
37+
if ( !uicr_update_customer(31 * sizeof(uint32_t), &flag, sizeof(uint32_t)) )
38+
return false;
39+
NVIC_SystemReset();
40+
return true; // should never reach here
3641
}
3742

3843
// ======================
@@ -125,7 +130,7 @@ bool deviceCfg_keystore_restore_from_uicr(deviceCfg_keystore_t* keystore)
125130
if ( !is_uicr_keystore_valid )
126131
return false;
127132

128-
// if uicr copy invalid, no flag check, restore only
133+
// if flash copy invalid, no flag check, restore only
129134
if ( is_uicr_keystore_valid && !is_flash_keystore_valid )
130135
memcpy(keystore, &keystore_uicr, sizeof(deviceCfg_keystore_t));
131136

drivers/nrf_uicr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ bool uicr_update_bootloader_addr(uint32_t bootloader_addr)
9393
return true; // remember to reboot !
9494
}
9595

96-
bool uicr_update_customer(uint8_t offset, void* data, uint8_t len)
96+
bool uicr_update_customer(uint8_t offset, void* data, uint32_t len)
9797
{
9898
if ( (offset % sizeof(uint32_t)) != 0 || (len % sizeof(uint32_t)) != 0 )
9999
return false;
@@ -116,7 +116,7 @@ bool uicr_update_customer(uint8_t offset, void* data, uint8_t len)
116116
return true; // remember to reboot !
117117
}
118118

119-
bool uicr_get_customer(uint8_t offset, void* data, uint8_t len)
119+
bool uicr_get_customer(uint8_t offset, void* data, uint32_t len)
120120
{
121121
if ( (offset % sizeof(uint32_t)) != 0 || (len % sizeof(uint32_t)) != 0 )
122122
return false;

drivers/nrf_uicr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bool uicr_check_blank(uint32_t addr, uint32_t len_word);
1414
bool uicr_write(uint32_t addr, void* data, uint32_t len_word);
1515
bool uicr_read(uint32_t addr, void* data, uint32_t len_word);
1616
bool uicr_update_bootloader_addr(uint32_t bootloader_addr);
17-
bool uicr_update_customer(uint8_t offset, void* data, uint8_t len);
18-
bool uicr_get_customer(uint8_t offset, void* data, uint8_t len);
17+
bool uicr_update_customer(uint8_t offset, void* data, uint32_t len);
18+
bool uicr_get_customer(uint8_t offset, void* data, uint32_t len);
1919

2020
#endif //_NRF_UICR_

drivers/pmu/axp2101.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static bool axp2101_config_battery_param(void)
4646
// battery param -> BROM
4747
uint32_t bat_flag = devicePresistence_get_battery_profile_flag();
4848
if (
49-
bat_flag != AXP2101_BROM_VARIANT_JSEL && ///
49+
bat_flag != AXP2101_BROM_VARIANT_JSEL && //
5050
bat_flag != AXP2101_BROM_VARIANT_STML //
5151
)
5252
{

0 commit comments

Comments
 (0)