Skip to content

Commit

Permalink
fixup! feat(prodtest): refactor and improve prodtest
Browse files Browse the repository at this point in the history
  • Loading branch information
cepetr committed Jan 28, 2025
1 parent 2de9964 commit e79acab
Show file tree
Hide file tree
Showing 22 changed files with 249 additions and 113 deletions.
3 changes: 2 additions & 1 deletion core/embed/projects/prodtest/cmd/prodtest_boardloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ static void prodtest_boardloader_version(cli_t* cli) {
PRODTEST_CLI_CMD(
.name = "boardloader-version",
.func = prodtest_boardloader_version,
.info = "Retrieve the boardloader version"
.info = "Retrieve the boardloader version",
.args = ""
);
3 changes: 2 additions & 1 deletion core/embed/projects/prodtest/cmd/prodtest_bootloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ static void prodtest_bootloader_version(cli_t *cli) {
PRODTEST_CLI_CMD(
.name = "bootloader-version",
.func = prodtest_bootloader_version,
.info = "Retrieve the bootloader version"
.info = "Retrieve the bootloader version",
.args = ""
);
8 changes: 5 additions & 3 deletions core/embed/projects/prodtest/cmd/prodtest_button.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static void test_button_combination(cli_t* cli, uint32_t timeout, button_t btn1,
}

static void prodtest_button_test(cli_t* cli) {
const char* button = cli_arg(cli, 0);
const char* button = cli_arg(cli, "button");
int btn1 = -1;
int btn2 = -1;

Expand All @@ -113,11 +113,12 @@ static void prodtest_button_test(cli_t* cli) {
} else {
cli_error_arg(cli,
"Expecting button name - left, right, left+right or power.");
return;
}

uint32_t timeout = 0;

if (!cli_arg_uint32(cli, 1, &timeout)) {
if (!cli_arg_uint32(cli, "timeout", &timeout)) {
cli_error_arg(cli, "Expecting timeout in milliseconds.");
return;
}
Expand All @@ -139,7 +140,8 @@ static void prodtest_button_test(cli_t* cli) {
PRODTEST_CLI_CMD(
.name = "button-test",
.func = prodtest_button_test,
.info = "Test the hardware buttons"
.info = "Test the hardware buttons",
.args = "<button> <timeout>"
);

#endif // USE_BUTTON
15 changes: 9 additions & 6 deletions core/embed/projects/prodtest/cmd/prodtest_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static void prodtest_display_border(cli_t* cli) {
static void prodtest_display_bars(cli_t* cli) {
gfx_clear();

const char* colors = cli_arg(cli, 0);
const char* colors = cli_arg(cli, "colors");
size_t color_count = strlen(colors);

if (cli_arg_count(cli) > 1) {
Expand Down Expand Up @@ -90,7 +90,7 @@ static void prodtest_display_bars(cli_t* cli) {
}

if (strlen(colors) == 0 || invalid_color) {
cli_trace(cli, "Expecting valid color pattern (RGBW characters).");
cli_trace(cli, "Not valid color pattern (RGBW characters expected).");
}

display_refresh();
Expand All @@ -101,7 +101,7 @@ static void prodtest_display_bars(cli_t* cli) {
static void prodtest_display_set_backlight(cli_t* cli) {
uint32_t level = 0;

if (!cli_arg_uint32(cli, 0, &level) || level > 255) {
if (!cli_arg_uint32(cli, "level", &level) || level > 255) {
cli_error_arg(cli, "Expecting backlig level in range 0-255 (100%%).");
return;
}
Expand All @@ -122,17 +122,20 @@ static void prodtest_display_set_backlight(cli_t* cli) {
PRODTEST_CLI_CMD(
.name = "display-border",
.func = prodtest_display_border,
.info = "Display a border around the screen"
.info = "Display a border around the screen",
.args = ""
);

PRODTEST_CLI_CMD(
.name = "display-bars",
.func = prodtest_display_bars,
.info = "Display vertical bars in different colors"
.info = "Display vertical bars in different colors",
.args = "<colors>"
);

PRODTEST_CLI_CMD(
.name = "display-set-backlight",
.func = prodtest_display_set_backlight,
.info = "Set the display backlight level"
.info = "Set the display backlight level",
.args = "<level>"
);
3 changes: 2 additions & 1 deletion core/embed/projects/prodtest/cmd/prodtest_get_cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ static void prodtest_get_cpuid(cli_t* cli) {
PRODTEST_CLI_CMD(
.name = "get-cpuid",
.func = prodtest_get_cpuid,
.info = "Retrieve unique CPU ID"
.info = "Retrieve unique CPU ID",
.args = ""
);


5 changes: 3 additions & 2 deletions core/embed/projects/prodtest/cmd/prodtest_haptic.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
static void prodtest_haptic_test(cli_t* cli) {
uint32_t duration = 0; // ms

if (!cli_arg_uint32(cli, 0, &duration) || duration > 5000) {
if (!cli_arg_uint32(cli, "duration", &duration) || duration > 5000) {
cli_error_arg(cli, "Expecting time in milliseconds in range 0-5000.");
return;
}
Expand Down Expand Up @@ -59,7 +59,8 @@ static void prodtest_haptic_test(cli_t* cli) {
PRODTEST_CLI_CMD(
.name = "haptic-test",
.func = prodtest_haptic_test,
.info = "Test the haptic feedback actuator"
.info = "Test the haptic feedback actuator",
.args = "<duration>"
);

#endif // USE_HAPTIC
5 changes: 3 additions & 2 deletions core/embed/projects/prodtest/cmd/prodtest_help.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <rtl/cli.h>

static void prodtest_help(cli_t* cli) {
const char* prefix = cli_arg(cli, 0);
const char* prefix = cli_arg(cli, "prefix");
size_t prefix_len = strlen(prefix);

if (cli_arg_count(cli) > 1) {
Expand Down Expand Up @@ -56,5 +56,6 @@ static void prodtest_help(cli_t* cli) {
PRODTEST_CLI_CMD(
.name = "help",
.func = prodtest_help,
.info = "Dsiplay the list of available commands"
.info = "Dsiplay the list of available commands",
.args = "[<prefix>]"
);
37 changes: 24 additions & 13 deletions core/embed/projects/prodtest/cmd/prodtest_optiga.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ static void cert_write(cli_t* cli, uint16_t oid) {
size_t len = 0;
uint8_t data_bytes[OPTIGA_MAX_CERT_SIZE];

if (!cli_arg_hex(cli, 0, data_bytes, sizeof(data_bytes), &len)) {
if (!cli_arg_hex(cli, "hex-data", data_bytes, sizeof(data_bytes), &len)) {
if (len == sizeof(data_bytes)) {
cli_error(cli, CLI_ERROR, "Certificate too long.");
} else {
Expand Down Expand Up @@ -544,7 +544,7 @@ static void prodtest_optiga_keyfido_write(cli_t* cli) {
uint8_t data_bytes[EXPECTED_SIZE];
size_t len = 0;

if (!cli_arg_hex(cli, 0, data_bytes, sizeof(data_bytes), &len)) {
if (!cli_arg_hex(cli, "hex-data", data_bytes, sizeof(data_bytes), &len)) {
if (len == sizeof(data_bytes)) {
cli_error(cli, CLI_ERROR, "Key too long.");
} else {
Expand Down Expand Up @@ -956,67 +956,78 @@ static void prodtest_optiga_keyfido_read(cli_t* cli) {
PRODTEST_CLI_CMD(
.name = "optiga-id-read",
.func = prodtest_optiga_id_read,
.info = "Retrieve the unique ID of the Optiga chip"
.info = "Retrieve the unique ID of the Optiga chip",
.args = ""
);

PRODTEST_CLI_CMD(
.name = "optiga-certinf-read",
.func = prodtest_optiga_certinf_read,
.info = "Read the X.509 certificate issued by Infineon"
.info = "Read the X.509 certificate issued by Infineon",
.args = ""
);

PRODTEST_CLI_CMD(
.name = "optiga-certdev-read",
.func = prodtest_optiga_certdev_read,
.info = "Read the device's X.509 certificate"
.info = "Read the device's X.509 certificate",
.args = ""
);

PRODTEST_CLI_CMD(
.name = "optiga-certdev-write",
.func = prodtest_optiga_certdev_write,
.info = "Write the device's X.509 certificate"
.info = "Write the device's X.509 certificate",
.args = "<hex-data>"
);

PRODTEST_CLI_CMD(
.name = "optiga-certfido-read",
.func = prodtest_optiga_certfido_read,
.info = "Read the X.509 certificate for the FIDO key"
.info = "Read the X.509 certificate for the FIDO key",
.args = ""
);

PRODTEST_CLI_CMD(
.name = "optiga-certfido-write",
.func = prodtest_optiga_certfido_write,
.info = "Write the X.509 certificate for the FIDO key"
.info = "Write the X.509 certificate for the FIDO key",
.args = "<hex-data>"
);

PRODTEST_CLI_CMD(
.name = "optiga-keyfido-read",
.func = prodtest_optiga_keyfido_read,
.info = "Read the x-coordinate of the FIDO public key."
.info = "Read the x-coordinate of the FIDO public key.",
.args = ""
);

PRODTEST_CLI_CMD(
.name = "optiga-keyfido-write",
.func = prodtest_optiga_keyfido_write,
.info = "Write the FIDO private key"
.info = "Write the FIDO private key",
.args = "<hex-data>"
);

PRODTEST_CLI_CMD(
.name = "optiga-lock",
.func = prodtest_optiga_lock,
.info = "Lock Optiga's data objects containing provisioning data"
.info = "Lock Optiga's data objects containing provisioning data",
.args = ""
);

PRODTEST_CLI_CMD(
.name = "optiga-lock-check",
.func = prodtest_optiga_lock_check,
.info = "Check whether Optiga's data objects are locked"
.info = "Check whether Optiga's data objects are locked",
.args = ""
);

PRODTEST_CLI_CMD(
.name = "optiga-counter-read",
.func = prodtest_optiga_counter_read,
.info = "Read the Optiga security event counter"
.info = "Read the Optiga security event counter",
.args = ""
);

#endif // USE_OPTIGA
12 changes: 7 additions & 5 deletions core/embed/projects/prodtest/cmd/prodtest_otp_batch.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static void prodtest_otp_batch_read(cli_t* cli) {
}

static void prodtest_otp_batch_write(cli_t* cli) {
const char* data = cli_arg(cli, 0);
const char* data = cli_arg(cli, "text");

if (strlen(data) == 0 || strlen(data) > FLASH_OTP_BLOCK_SIZE - 1) {
cli_error_arg(cli, "Expecting text (up to 31 characters).");
Expand All @@ -77,8 +77,8 @@ static void prodtest_otp_batch_write(cli_t* cli) {
bool dry_run = true;
#endif

if (cli_is_arg(cli, 1)) {
const char* option = cli_arg(cli, 1);
if (cli_has_nth_arg(cli, 1)) {
const char* option = cli_nth_arg(cli, 1);
if (strcmp(option, "--execute") == 0) {
dry_run = false;
} else if (strcmp(option, "--dry-run") == 0) {
Expand Down Expand Up @@ -145,11 +145,13 @@ static void prodtest_otp_batch_write(cli_t* cli) {
PRODTEST_CLI_CMD(
.name = "otp-batch-read",
.func = prodtest_otp_batch_read,
.info = "Read the device batch info from OTP memory"
.info = "Read the device batch info from OTP memory",
.args = ""
);

PRODTEST_CLI_CMD(
.name = "otp-batch-write",
.func = prodtest_otp_batch_write,
.info = "Write the device batch info into OTP memory"
.info = "Write the device batch info into OTP memory",
.args = "<text> [--execute | --dry-run]"
);
8 changes: 5 additions & 3 deletions core/embed/projects/prodtest/cmd/prodtest_otp_variant.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static void prodtest_otp_variant_write(cli_t* cli) {
block[val_count++] = 0x01; // Always 1

while (arg_idx < cli_arg_count(cli)) {
const char* arg = cli_arg(cli, arg_idx++);
const char* arg = cli_nth_arg(cli, arg_idx++);
uint32_t val = 0;

if (strcmp(arg, "--execute") == 0) {
Expand Down Expand Up @@ -167,11 +167,13 @@ static void prodtest_otp_variant_write(cli_t* cli) {
PRODTEST_CLI_CMD(
.name = "otp-variant-read",
.func = prodtest_otp_variant_read,
.info = "Read the device variant info from OTP memory"
.info = "Read the device variant info from OTP memory",
.args = ""
);

PRODTEST_CLI_CMD(
.name = "otp-variant-write",
.func = prodtest_otp_variant_write,
.info = "Write the device variant info into OTP memory"
.info = "Write the device variant info into OTP memory",
.args = "<values...> [--execute | --dry-run]"
);
3 changes: 2 additions & 1 deletion core/embed/projects/prodtest/cmd/prodtest_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ static void prodtest_ping(cli_t* cli) {
PRODTEST_CLI_CMD(
.name = "ping",
.func = prodtest_ping,
.info = "Send a ping to the device"
.info = "Send a ping to the device",
.args = ""
);
Loading

0 comments on commit e79acab

Please sign in to comment.