diff --git a/core/SConscript.prodtest b/core/SConscript.prodtest index 558062bd42..9ae208b14a 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 fd1e190150..b0697c1add 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 0000000000..c2e149d6c4 --- /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 18c6532d6c..c3ee5202d6 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 [INARG1 [INARG2 [INARG3 ...]]]` +`command ...` Example: ``` -CPUID READ +haptic-test 500 ``` -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`. +To retrieve a list of all available commands, type `help`. -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`. +### Final Responses +The Trezor device responds to all commands with single-line text responses, which start with either `OK` or `ERROR`. -Response Format: - -`OK [OUTARG1 [OUTARG2 [OUTARG3 ...]]]` +An `OK` response may include additional parameters separated by spaces. The number and type of parameters depend on the specific command. Example: ``` -OK 2F0079001951354861125762 +OK 2.1.7 +``` + +An `ERROR` response includes an error code and an optional error description enclosed in quotation marks. + +Example: +``` +ERROR invalid-arg "Expecting x-coordinate." +``` + +#### Predefined Error Codes: + +While commands may define custom error codes as needed, the following are predefined: + +* `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: +``` +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 +``` + +### Debug Messages + +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: +``` +rgbled-set 0 255 0 +# Setting the RGB LED color to [0, 255, 0]... +OK ``` ## List of commands -### PING -The `PING` command serves as a no-operation request, and the device responds with `OK` to acknowledge receipt. +### 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: ``` -PING +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 ``` -### 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. +### ping +The `ping` command serves as a no-operation request, and the device responds with `OK` to acknowledge receipt. Example: ``` -CPUID READ -OK 2F0079001951354861125762 -``` - -### 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`. - -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. - -Example (to draw 6 vertical bars - red, black, green, black, blue and black): -``` -DISP RxGxB -``` - -### 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. - -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 - -If the specified button or button combination is not detected within the timeout, the command will return and `ERROR TIMEOUT`. - -Example (to wait for 9 seconds for the left button): -``` -BUTTON LEFT 9 -OK -``` - -### 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. - -The command requires two input parameters: - -* The first parameter, which should be a value between 0 and 3, determines the quadrant where the rectangle will be drawn. -* The second parameter, a value between 1 and 9, represents the timeout in seconds. - -If the display is not touched within the specified timeout, the command will return an `ERROR TIMEOUT`. - -The command does not check whether the touch point lies within the quadrant or not. It only returns the x and y coordinate of the touch point. - -Example (to draw a rectangle in the top-left quadrant and wait for 9 seconds for touch input): -``` -TOUCH 09 -OK 50 90 -``` - - -### TOUCH_CUSTOM -The `TOUCH_CUSTOM` command tests the functionality of the display's touch screen. -It draws a filled rectangle on custom coordinates and waits for user interaction. - -The command requires five input parameters: - -* X position of the top-left corner of the rectangle -* Y position of the top-left corner of the rectangle -* Width of the rectangle -* Height of the rectangle -* The timeout in seconds - -If the display is not touched within the specified timeout, the command will return an `ERROR TIMEOUT`. - -The device report touch events, coordinates and timestamps (in ms), correctness of the touch point is not checked and is left to the test equipment. - -The test ends with first lift-up event. - -Example (to draw a 100x100 rectangle in the top-left (10,10) position and wait for 15 seconds for touch input): -``` -TOUCH_CUSTOM 10 10 100 100 15 -TOUCH D 69 35 357300 -TOUCH U 69 35 357328 -OK -``` - -### TOUCH_IDLE -The `TOUCH_IDLE` command tests the functionality of the display's touch screen. -It waits for a specific time period without any touch input. - -The command requires one input parameter: -* The timeout in seconds - -If a touch activity is detected within the specified timeout, the command will return an `ERROR TOUCH DETECTED`. - -Example - wait ten seconds for no touch input: -``` -TOUCH_IDLE 10 -OK -``` - -### TOUCH_POWER -The `TOUCH_POWER` command tests the functionality of touch layer power supply - -The command requires one input parameter: -* The timeout in milliseconds - -The powers up the touch layer and waits for a specific time period so that measurement can be done by test equipment. - -Example - wait ten milliseconds for touch power measurement: -``` -TOUCH_POWER 10 -OK -``` - -### SENS -The `SENS` command is used to evaluating the touch screen sensitivity. -It draws a filled box around the touch coordinates. -It takes one input parameter, a sensitivity, a decimal value representing sensitivity. -Please note that the sensitivity value is model-dependent. - -It's important to mention that this command does not return any output. -A device restart is required to stop this operation. +### reboot +This command initiates device reboot. Example: ``` -SENS 12 -``` - -### TOUCH VERSION -Allows you to read the version of the touch screen controller, if its supported by the device. -The command returns `OK` followed by the version number. - -Example: -``` -TOUCH VERSION -OK 167 -``` - -### PWM -The `PWM` command sets the display backlight using PWM (Pulse Width Modulation). -This command takes one input parameter, a decimal value between 0 to 255, and adjusts the PWM output to control the display LED backlight. - -Example:: -``` -DISP 128 +reboot OK ``` -### SD -The `SD` command initiates a simple test of the SD card. -The test includes writing and reading back a few blocks of data and comparing them for equality. - -Possible error return codes are: - -- `ERROR NOCARD` - Indicates that no SD card is present -- `ERROR sdcard_write_blocks (n)` - Indicates a write failure to the N-th block -- `ERROR sdcard_read_blocks (n)` - Indicates a read failure from the N-th block -- `ERROR DATA MISMATCH` - Indicates a mismatch between the read data and the written data -- `OK` - Indicates that the test has passed successfully - -Note: the command returns `UNKNOWN` for models without the SD card support +### boardloader-version +Retrieves the version of the boardloader. The command returns `OK` followed by the version in the format `..`. Example: ``` -SD -OK -``` - -### SBU -The `SBU` command allows you to set the states of SBU1 and SBU2 pins. -It takes one input parameter, representing the state of both pins (00, 01, 10 or 11), and sets the corresponding output pins accordingly. - -Example: -``` -// sets SBU1 <- 1, SBU2 <- 0 - -SBU 10 -OK -``` - - -### HAPTIC -The `HAPTIC` command allows you to test the functionality of the device's haptic driver. -It takes one input parameter, representing the duration of the vibration in milliseconds. -The device only vibrates if there is motor connected to the haptic driver, otherwise the effect needs to be -measured by an oscilloscope. - -Example: -``` -// runs the driver for 3000 ms - -HAPTIC 3000 -OK -``` - -### RGB_LED -The `RGB_LED` command allows you to test the functionality of the device's RGB LED. -It takes three input parameters, representing the intensity of the red, green, and blue color components. -Each component is a decimal value between 0 and 255. - -Example: -``` -// sets the RGB LED to red - -RGB_LED 255 0 0 -OK -``` - -### OTP READ -The `OTP READ` command is utilized to retrieve a string parameter from the device's OTP memory. -This string typically contains information identifying the model and production batch of the device. -The command always returns OK followed by the read value. -If the OTP memory has not been written yet, it returns a special response: OK (null). - -Example: -``` -OTP READ -OK (null) -``` - -### OTP WRITE -The `OTP WRITE` command enables you to store a string parameter (which can be used to identify the model and production batch, for instance) into the device's OTP memory. -The parameter can be up to 31 characters in length. - -The standard format is `-`, where YYMMDD represents the provisioning date. In case of Model T the `internal_model` is `TREZOR2`. - -Example: -``` -OTP WRITE T2B1-231231 -OK -``` - -### VARIANT -The `VARIANT` command writes up to 31 decimal values (representing device variant options), each ranging from 0 to 255, and delimited by spaces, into the OTP memory. This command should be called after the `LOCK` command was successfully executed. - -The standard format is `VARIANT `. - -Example (to write 3 bytes into OTP memory): -``` -VARIANT 3 0 2 -``` - -### VARIANT READ -The `VARIANT READ` command allows you to read 32 bytes of stored variant data (representing device variant options), each ranging from 0 to 255, and delimited by spaces. The first byte is the format version, followed by the bytes written using the VARIANT command and padded with null bytes. - -Example: -``` -VARIANT READ -OK 1 3 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -``` - -### FIRMWARE VERSION -Returns the version of the prodtest firmware. -The command returns `OK` followed by the version in the format `..`. - -Example: -``` -FIRMWARE VERSION +boardloader-version OK 0.2.6 ``` -### BOOTLOADER VERSION -Returns the version of the bootlaoder. -The command returns `OK` followed by the version in the format `..`. +### bootloader-version +Retrives the version of the bootlaoder. The command returns `OK` followed by the version in the format `..`. Example: ``` -BOOTLOADER VERSION +bootloader-version OK 2.1.7 ``` -### BOARDLOADER VERSION -Returns the version of the boardloader. +### 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. + +`button-test