1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-04-16 07:15:47 +00:00

feat(core): Update stwlc38 patching cut selection + new stwlc38 FW patch and configs [no changelog]

This commit is contained in:
kopecdav 2025-04-04 10:36:48 +02:00 committed by kopecdav
parent 3db788d80a
commit 56bad5bd3a
8 changed files with 2450 additions and 1119 deletions

View File

@ -216,6 +216,22 @@ static void prodtest_wpc_update(cli_t* cli) {
cli_trace(cli, "Updating STWLC38...");
stwlc38_chip_info_t chip_info;
if (!stwlc38_read_chip_info(&chip_info)) {
cli_error(cli, CLI_ERROR, "Cannot read STWLC38 info.");
return;
}
if (chip_info.chip_rev == STWLC38_CUT_1_2) {
cli_trace(cli, "STWLC38 chip revision 1.2");
} else if (chip_info.chip_rev == STWLC38_CUT_1_3) {
cli_trace(cli, "STWLC38 chip revision 1.3");
} else {
cli_error(cli, CLI_ERROR, "Unknown chip revision, update aborted.");
return;
}
// Update STWLC38 firmware and configuration
uint32_t update_time = systick_ms();
bool status = stwlc38_patch_and_config();
update_time = systick_ms() - update_time;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,51 @@
/**
******************************************************************************
* @brief : This is auto-generated header file which contains patch and
* configuration data to be programmed into chip.
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
const uint8_t cfg_data_cut_1_2[] = {
0x7C, 0x1D, 0x00, 0x00, 0xEF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0xC8, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00, 0x46, 0x01, 0x00,
0x63, 0x00, 0x01, 0x0D, 0x06, 0x02, 0x00, 0xFF, 0xC3, 0x0F, 0x05, 0x3F,
0x14, 0x0C, 0x28, 0x1E, 0x50, 0x46, 0x05, 0x01, 0x82, 0x82, 0x82, 0x82,
0x40, 0x02, 0x02, 0x02, 0x02, 0x50, 0x07, 0x06, 0x12, 0x00, 0x2D, 0x00,
0x90, 0x00, 0x00, 0x40, 0x23, 0x32, 0x14, 0x2F, 0x41, 0x45, 0x55, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x26, 0x40, 0x5B, 0x60, 0x56, 0xBC,
0xB4, 0x3C, 0x08, 0x08, 0x14, 0x32, 0x46, 0x02, 0x02, 0x02, 0x03, 0x00,
0x14, 0x05, 0x46, 0xFF, 0x00, 0x0A, 0x00, 0x00, 0x09, 0x84, 0x03, 0x00,
0x01, 0x00, 0x01, 0x00, 0x09, 0x00, 0x03, 0x00, 0x7E, 0x7D, 0xA5, 0x0A,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD6, 0x06, 0x52, 0x03, 0x00, 0x19,
0x00, 0x00, 0x07, 0x19, 0x11, 0x00, 0x0B, 0x00, 0x16, 0x11, 0x22, 0x33,
0x44, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x05, 0x1E, 0x00,
0x12, 0x00, 0x1E, 0x3D, 0x5D, 0x54, 0x8A, 0xB7, 0x9C, 0x14, 0x8E, 0x10,
0x1E, 0x03, 0x03, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E,
0x00, 0x01, 0x64, 0x00, 0xC1, 0x00, 0x00, 0x00, 0xF0, 0x28, 0x0E, 0x05,
0xD4, 0x00, 0x28, 0x00, 0x00, 0x01, 0x3F, 0x03, 0x00, 0x00, 0x00, 0x41,
0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC1, 0x00,
0x22, 0xC2, 0x05, 0x06, 0x09, 0x0D, 0x03, 0x1E, 0x96, 0x01, 0x03, 0x2D,
0x00, 0x01, 0x00, 0x40, 0x00, 0x13, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7C, 0x63, 0x20, 0x32, 0x5F, 0xFF, 0x03, 0x00, 0x22, 0x24, 0xDB, 0x1A,
0xF6, 0x20, 0x32, 0x30, 0x32, 0x32, 0x50, 0x70, 0x14, 0x0C, 0x55, 0xA3,
0x00, 0x03, 0x1E, 0xC8, 0xA5, 0x0F, 0x14, 0x1E, 0x32, 0x32, 0x19, 0x28,
0x37, 0x02, 0x00, 0x0A, 0x1E, 0x1E, 0x0C, 0x00, 0x00, 0x00, 0x18, 0x00,
0xFF, 0x50, 0x38, 0x00, 0x0F, 0x2C, 0x51, 0x64, 0x04, 0x3E, 0x0A, 0x53,
0x0A, 0x66, 0x00, 0x00, 0x11, 0x2E, 0x53, 0x7B, 0xB2, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0C, 0x14, 0x19, 0x18, 0x19, 0x16, 0xA2, 0x00, 0x55,
0x1A, 0x07, 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0xC8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE4, 0x17, 0x63, 0x7B,
};

View File

@ -0,0 +1,51 @@
/**
******************************************************************************
* @brief : This is auto-generated header file which contains patch and
* configuration data to be programmed into chip.
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
const uint8_t cfg_data_cut_1_3[] = {
0x7C, 0x1D, 0x00, 0x00, 0xEF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0xC8, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00, 0x46, 0x01, 0x00,
0x63, 0x00, 0x01, 0x0D, 0x06, 0x02, 0x00, 0xFF, 0x83, 0x0F, 0x05, 0x3F,
0x14, 0x0C, 0x28, 0x1E, 0x50, 0x46, 0x05, 0x01, 0x82, 0x82, 0x82, 0x82,
0x40, 0x42, 0x42, 0x42, 0x42, 0x50, 0x07, 0x06, 0x12, 0x00, 0x2D, 0x00,
0x90, 0x00, 0x00, 0x40, 0x23, 0x32, 0x14, 0x2F, 0x41, 0x45, 0x55, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x26, 0x40, 0x5B, 0x60, 0x56, 0xBC,
0xB4, 0x3C, 0x08, 0x08, 0x14, 0x32, 0x46, 0x02, 0x02, 0x02, 0x03, 0x00,
0x14, 0x05, 0x46, 0xFF, 0x00, 0x0A, 0x00, 0x00, 0x09, 0x84, 0x03, 0x00,
0x01, 0x00, 0x01, 0x00, 0x09, 0x00, 0x03, 0x00, 0x7E, 0x7D, 0xA5, 0x0A,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD6, 0x06, 0x52, 0x03, 0x00, 0x19,
0x00, 0x00, 0x07, 0x19, 0x11, 0x00, 0x0B, 0x00, 0x16, 0x11, 0x22, 0x33,
0x44, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x05, 0x1E, 0x00,
0x12, 0x00, 0x1E, 0x3D, 0x5D, 0x54, 0x8A, 0xB7, 0x9C, 0x14, 0x8E, 0x10,
0x1E, 0x03, 0x03, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E,
0x00, 0x01, 0x64, 0x00, 0xC1, 0x00, 0x00, 0x00, 0xF0, 0x28, 0x0E, 0x05,
0xD4, 0x00, 0x28, 0x00, 0x00, 0x01, 0x3F, 0x03, 0x00, 0x00, 0x00, 0x41,
0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC1, 0x00,
0x22, 0xC2, 0x05, 0x06, 0x09, 0x0D, 0x03, 0x1E, 0x96, 0x01, 0x03, 0x2D,
0x00, 0x01, 0x00, 0x40, 0x00, 0x13, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7C, 0x63, 0x20, 0x32, 0x5F, 0xFF, 0x03, 0x00, 0x22, 0x24, 0xDB, 0x1A,
0xF6, 0x20, 0x32, 0x30, 0x32, 0x32, 0x50, 0x70, 0x14, 0x0C, 0x55, 0xA3,
0x00, 0x03, 0x1E, 0xC8, 0xA5, 0x0F, 0x14, 0x1E, 0x32, 0x32, 0x19, 0x28,
0x37, 0x02, 0x00, 0x0A, 0x1E, 0x1E, 0x0C, 0x00, 0x00, 0x00, 0x18, 0x00,
0xFF, 0x50, 0x38, 0x00, 0x0F, 0x2C, 0x51, 0x64, 0x04, 0x3E, 0x0A, 0x53,
0x0A, 0x66, 0x00, 0x00, 0x11, 0x2E, 0x53, 0x7B, 0xB2, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0C, 0x14, 0x19, 0x18, 0x19, 0x16, 0xA2, 0x00, 0x55,
0x1A, 0x07, 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0x7D, 0xC8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0xF6, 0x2D, 0x74,
};

File diff suppressed because it is too large Load Diff

View File

@ -27,6 +27,12 @@ typedef enum {
OP_MODE_TX = 3,
} stwlc38_op_mode_t;
typedef enum {
STWLC38_UNKNOWN_CHIP_REV = 0,
STWLC38_CUT_1_2 = 0x3,
STWLC38_CUT_1_3 = 0x4,
} stwlc38_chip_rev_t;
typedef struct {
uint16_t chip_id; // Chip ID
uint8_t chip_rev; // Chip Revision

View File

@ -75,6 +75,7 @@
// FW Registers
#define STWLC38_FWREG_CHIP_ID_REG 0x0000U
#define STWLC38_FWREG_CHIP_REV_REG 0x0002U
#define STWLC38_FWREG_OP_MODE_REG 0x000EU
#define STWLC38_FWREG_DEVICE_ID_REG 0x0010U
#define STWLC38_FWREG_SYS_CMD_REG 0x0020U

View File

@ -27,7 +27,7 @@
#include <sys/systick.h>
#include <sys/systimer.h>
#include "nvm_data.h"
#include "nvm_data_fw_patch_v4.h"
#include "stwlc38.h"
#include "stwlc38_defs.h"
#include "stwlc38_internal.h"
@ -69,6 +69,10 @@ bool stwlc38_patch_and_config() {
return false;
}
uint8_t chip_rev;
status = stwlc38_read_fw_register(drv->i2c_bus, STWLC38_FWREG_CHIP_REV_REG,
&chip_rev);
// Reset and disable NVM loading
status =
stwlc38_write_fw_register(drv->i2c_bus, STWLC38_FWREG_SYS_CMD_REG, 0x40);
@ -96,6 +100,16 @@ bool stwlc38_patch_and_config() {
return false;
}
const uint8_t *config_data;
if (chip_rev == STWLC38_CUT_1_2) {
config_data = cfg_data_cut_1_2;
} else if (chip_rev == STWLC38_CUT_1_3) {
config_data = cfg_data_cut_1_3;
} else {
// Unknown chip revision, patch and config cannot be written.
return false;
}
// Write patch to NVM
status = stwlc38_nvm_write_bulk(drv->i2c_bus, patch_data, NVM_PATCH_SIZE,
STWLC38_NVM_PATCH_START_SECTOR_INDEX);
@ -103,8 +117,7 @@ bool stwlc38_patch_and_config() {
return false;
}
// Write config to NVM
status = stwlc38_nvm_write_bulk(drv->i2c_bus, cfg_data, NVM_CFG_SIZE,
status = stwlc38_nvm_write_bulk(drv->i2c_bus, config_data, NVM_CFG_SIZE,
STWLC38_NVM_CFG_START_SECTOR_INDEX);
if (status != I2C_STATUS_OK) {
return false;