mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-31 02:48:44 +00:00
feat(core/prodtest): add pm-new-soc-estimate command.
[no changelog]
This commit is contained in:
parent
d6e0a02ac7
commit
d0c1458a19
@ -712,6 +712,16 @@ optiga-counter-read
|
||||
OK 0E
|
||||
```
|
||||
|
||||
### pm-new-soc-estimate
|
||||
Erase power manager recovery data from the backup RAM and immediately reboot the device to run new battery SoC estimate.
|
||||
|
||||
Example:
|
||||
```
|
||||
pm-new-soc-estimate
|
||||
# Erasing backup RAM and rebooting...
|
||||
OK
|
||||
```
|
||||
|
||||
### pm-set-soc-limit
|
||||
Sets the battery state of charge (SOC) limit. The SOC limit is a percentage value between 10 and 100.
|
||||
|
||||
|
@ -27,6 +27,8 @@
|
||||
#include <rtl/mini_printf.h>
|
||||
#include <rtl/unit_test.h>
|
||||
#include <rust_ui_prodtest.h>
|
||||
#include <sys/backup_ram.h>
|
||||
#include <sys/bootutils.h>
|
||||
#include <sys/power_manager.h>
|
||||
#include <sys/rtc.h>
|
||||
#include <sys/systick.h>
|
||||
@ -410,6 +412,30 @@ void prodtest_pm_set_soc_limit(cli_t* cli) {
|
||||
cli_ok(cli, "");
|
||||
}
|
||||
|
||||
void prodtest_pm_new_soc_estimate(cli_t* cli) {
|
||||
if (cli_arg_count(cli) > 0) {
|
||||
cli_error_arg_count(cli);
|
||||
return;
|
||||
}
|
||||
|
||||
// Run new battery SoC initialization by erasing the recovery data from
|
||||
// backup RAM followed by forced imediate reboot.
|
||||
|
||||
cli_trace(cli, "Erasing backup RAM and rebooting...");
|
||||
cli_ok(cli, "");
|
||||
systick_delay_ms(100);
|
||||
|
||||
// Deinitialize power manager so the monitor stop feeding the recovery data
|
||||
// to backup RAM.
|
||||
pm_deinit();
|
||||
|
||||
// Erase PM recovery data from backup RAM
|
||||
backup_ram_erase_item(BACKUP_RAM_KEY_PM_RECOVERY);
|
||||
reboot_device();
|
||||
|
||||
cli_error(cli, CLI_ERROR, "failed to reboot");
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
|
||||
PRODTEST_CLI_CMD(
|
||||
@ -475,4 +501,11 @@ PRODTEST_CLI_CMD(
|
||||
.args = "<limit>"
|
||||
);
|
||||
|
||||
PRODTEST_CLI_CMD(
|
||||
.name = "pm-new-soc-estimate",
|
||||
.func = prodtest_pm_new_soc_estimate,
|
||||
.info = "Run new battery SoC initialization",
|
||||
.args = ""
|
||||
);
|
||||
|
||||
#endif /* USE_POWER_MANAGER */
|
||||
|
@ -54,6 +54,17 @@ void backup_ram_deinit(void);
|
||||
|
||||
bool backup_ram_erase(void);
|
||||
|
||||
/**
|
||||
* @brief Erases a single item in backup RAM by its key.
|
||||
*
|
||||
* If the item with the given key does not exist, the function does nothing.
|
||||
*
|
||||
* @param key Key of the item to erase
|
||||
*
|
||||
* @return true if the operation was successful, false otherwise.
|
||||
*/
|
||||
bool backup_ram_erase_item(uint16_t key);
|
||||
|
||||
#define BACKUP_RAM_INVALID_KEY 0xFFFF
|
||||
|
||||
/**
|
||||
|
@ -354,6 +354,21 @@ uint16_t backup_ram_search(uint16_t min_key) {
|
||||
return key;
|
||||
}
|
||||
|
||||
bool backup_ram_erase_item(uint16_t key) {
|
||||
backup_ram_driver_t* drv = &g_backup_ram_driver;
|
||||
|
||||
if (!drv->initialized) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Writing NULL data will just remove the item with the given key
|
||||
irq_key_t irq_key = irq_lock();
|
||||
bool status = backup_ram_write(key, NULL, 0);
|
||||
irq_unlock(irq_key);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
bool backup_ram_read(uint16_t key, void* buffer, size_t buffer_size,
|
||||
size_t* data_size) {
|
||||
bool success = false;
|
||||
|
Loading…
Reference in New Issue
Block a user