diff --git a/core/SConscript.prodtest b/core/SConscript.prodtest index 558062bd42b..9ae208b14ad 100644 --- a/core/SConscript.prodtest +++ b/core/SConscript.prodtest @@ -76,8 +76,10 @@ SOURCE_MOD += [ 'embed/util/image/image.c', 'embed/util/rsod/rsod.c', 'embed/util/scm_revision/scm_revision.c', + 'embed/rtl/cli.c', 'embed/rtl/error_handling.c', 'embed/rtl/mini_printf.c', + 'embed/rtl/strutils.c', 'vendor/micropython/lib/uzlib/adler32.c', 'vendor/micropython/lib/uzlib/crc32.c', 'vendor/micropython/lib/uzlib/tinflate.c', @@ -98,14 +100,28 @@ FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_ SOURCE_PRODTEST = [ 'embed/projects/prodtest/header.S', 'embed/projects/prodtest/main.c', - 'embed/projects/prodtest/prodtest_common.c', + 'embed/projects/prodtest/cmd/prodtest_boardloader.c', + 'embed/projects/prodtest/cmd/prodtest_bootloader.c', + 'embed/projects/prodtest/cmd/prodtest_button.c', + 'embed/projects/prodtest/cmd/prodtest_display.c', + 'embed/projects/prodtest/cmd/prodtest_prodtest.c', + 'embed/projects/prodtest/cmd/prodtest_get_cpuid.c', + 'embed/projects/prodtest/cmd/prodtest_haptic.c', + 'embed/projects/prodtest/cmd/prodtest_help.c', + 'embed/projects/prodtest/cmd/prodtest_optiga.c', + 'embed/projects/prodtest/cmd/prodtest_otp_batch.c', + 'embed/projects/prodtest/cmd/prodtest_otp_variant.c', + 'embed/projects/prodtest/cmd/prodtest_ping.c', + 'embed/projects/prodtest/cmd/prodtest_pmic.c', + 'embed/projects/prodtest/cmd/prodtest_powerctl.c', + 'embed/projects/prodtest/cmd/prodtest_reboot.c', + 'embed/projects/prodtest/cmd/prodtest_rgbled.c', + 'embed/projects/prodtest/cmd/prodtest_sdcard.c', + 'embed/projects/prodtest/cmd/prodtest_sbu.c', + 'embed/projects/prodtest/cmd/prodtest_touch.c', + 'embed/projects/prodtest/cmd/prodtest_wpc.c', ] -if 'optiga' in FEATURES_AVAILABLE: - SOURCE_PRODTEST += [ - 'embed/projects/prodtest/optiga_prodtest.c', - ] - env.Replace( CAT='cat', CP='cp', diff --git a/core/embed/io/haptic/drv2625/drv2625.c b/core/embed/io/haptic/drv2625/drv2625.c index fd1e1901508..b0697c1add4 100644 --- a/core/embed/io/haptic/drv2625/drv2625.c +++ b/core/embed/io/haptic/drv2625/drv2625.c @@ -105,7 +105,7 @@ bool haptic_init(void) { haptic_driver_t *driver = &g_haptic_driver; if (driver->initialized) { - return false; + return true; } memset(driver, 0, sizeof(haptic_driver_t)); diff --git a/core/embed/projects/prodtest/.changelog.d/4534.incompatible b/core/embed/projects/prodtest/.changelog.d/4534.incompatible new file mode 100644 index 00000000000..c2e149d6c47 --- /dev/null +++ b/core/embed/projects/prodtest/.changelog.d/4534.incompatible @@ -0,0 +1 @@ +Completely redesigned. See the updated documentation for details. diff --git a/core/embed/projects/prodtest/README.md b/core/embed/projects/prodtest/README.md index 18c6532d6ce..c3ee5202d64 100644 --- a/core/embed/projects/prodtest/README.md +++ b/core/embed/projects/prodtest/README.md @@ -1,448 +1,547 @@ # Production Test Firmware -This document outlines the protocol used during production for testing and the initial provisioning of Trezor devices. +This document outlines the production test firmware (prodtest) and its protocol. -## Commands and Responses -In the production environment, the test equipment sends single-line text commands. -These commands start with the command name and can optionally be followed by parameters separated by spaces. +The prodtest serves two primary purposes: + +* Testing and initial provisioning of Trezor devices during production. +* Device bring-up and testing during development. + +## Command Line Interface + +The prodtest includes a simple text-based command-line interface that can be controlled either by automatic test equipment in a production environment or manually via a terminal application. + +Pressing the ENTER key twice switches the interface to interactive mode, enabling basic line editing, autocomplete functionality (using the TAB key), and text coloring. + +### Commands +These commands begin with the command name and may optionally include parameters separated by spaces. Command Format: +`command ...` -`COMMAND [INARG1 [INARG2 [INARG3 ...]]]` +Example: +``` +haptic-test 500 +``` + +To retrieve a list of all available commands, type `help`. + +### Final Responses +The Trezor device responds to all commands with single-line text responses, which start with either `OK` or `ERROR`. + +An `OK` response may include additional parameters separated by spaces. The number and type of parameters depend on the specific command. Example: ``` -CPUID READ +OK 2.1.7 ``` -The Trezor device responds with single-line text responses that start with either `OK` or `ERROR`, followed by output values separated by spaces. -If the device receives an unrecognized command, it responds with the text `UNKNOWN`. +An `ERROR` response includes an error code and an optional error description enclosed in quotation marks. -Device responds with single line text response starting with words `OK` or `ERROR` optionally followed by output values delimited by spaces. -In case of unrecognized command, device responds with text `UNKNOWN`. +Example: +``` +ERROR invalid-arg "Expecting x-coordinate." +``` + +#### Predefined Error Codes: -Response Format: +While commands may define custom error codes as needed, the following are predefined: -`OK [OUTARG1 [OUTARG2 [OUTARG3 ...]]]` +* `error` - Unspecified error; additional details may be provided in the error description. +* `invalid-cmd` - The command name is invalid. +* `invalid-arg` - Invalid command argument. +* `abort` - Operation aborted by the user (e.g., pressing CTRL+C). +* `timeout` - The command execution timed out. + +### Progress response + +When a command needs to send structured data that does not fit within `OK` messages, it can use the `PROGRESS` response. A progress response line starts with `PROGRESS`, followed by any number of parameters separated by spaces. Example: ``` -OK 2F0079001951354861125762 +PROGRESS move 107 164 24824185 +PROGRESS move 107 170 24824195 +PROGRESS move 107 176 24824204 +PROGRESS move 107 180 24824213 +PROGRESS move 107 184 24824222 ``` -## List of commands +### Debug Messages -### PING -The `PING` command serves as a no-operation request, and the device responds with `OK` to acknowledge receipt. +In addition to lines beginning with `OK`, `ERROR`, or `PROGRESS`, the prodtest firmware may issue lines starting with `#`. These lines contain debug or informational traces and should be ignored by automation scripts in a production environment. Example: ``` -PING +rgbled-set 0 255 0 +# Setting the RGB LED color to [0, 255, 0]... OK ``` -### CPUID READ -The `CPUID READ` command reads a 96-bit long unique ID stored in the device's CPU. -The command always returns `OK` followed by a 24-digit hexadecimal value representing the unique ID. +## List of commands + +### help +Displays a list of available commands. The command optionally accepts a prefix to filter and display only commands starting with the specified characters. Example: ``` -CPUID READ -OK 2F0079001951354861125762 +help otp +# Available commands (filtered): +# otp-batch-write - Write the device batch info into OTP memory +# otp-batch-read - Read the device batch info from OTP memory +# otp-variant-write - Write the device variant info into OTP memory +# otp-variant-read - Read the device variant info from OTP memory +OK ``` -### BORDER -The `BORDER` command draws a single white border around the screen on a black background. This command has no input parameters and always returns `OK`. +### ping +The `ping` command serves as a no-operation request, and the device responds with `OK` to acknowledge receipt. Example: ``` -BORDER +ping OK ``` -### DISP -The `DISP` command draws vertical color bars on the screen based on a list of specified colors provided as a parameter. -Each character in the parameter represents one vertical bar and its color (R - red, B - blue, W - white, any other character - black). -The number of characters corresponds to the number of bars. - -Note: On monochromatic displays R, G, B characters are interpreted as the white color. +### reboot +This command initiates device reboot. -Example (to draw 6 vertical bars - red, black, green, black, blue and black): +Example: ``` -DISP RxGxB +reboot +OK ``` -### BUTTON -The `BUTTON` command tests the functionality of the device's buttons. -It waits for the user to press and release a specified button in a designated timeout period. +### boardloader-version +Retrieves the version of the boardloader. The command returns `OK` followed by the version in the format `..`. -The command required two input parameters: -* The first parameter specifies the expected button or combination of buttons, with possible values: LEFT, RIGHT, BOTH. -* The seconds parameter specifies the timeout duration in seconds in range 1 to 9 +Example: +``` +boardloader-version +OK 0.2.6 +``` -If the specified button or button combination is not detected within the timeout, the command will return and `ERROR TIMEOUT`. +### bootloader-version +Retrives the version of the bootlaoder. The command returns `OK` followed by the version in the format `..`. -Example (to wait for 9 seconds for the left button): +Example: ``` -BUTTON LEFT 9 -OK +bootloader-version +OK 2.1.7 ``` -### TOUCH -The `TOUCH` command tests the functionality of the display's touch screen. -It draws a filled rectangle in one of the four display quadrants and waits for user interaction. +### button-test +The `button-test` command tests the functionality of the device's hardware buttons. It waits for the user to press and release a specified button in a designated timeout period. -The command requires two input parameters: +`button-test