1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-26 22:52:34 +02:00

serprog: Add support for multiple SPI chip selects

Tested with an EliteBook 8560w, Pi Pico, and my serprog firmware:
https://codeberg.org/Riku_V/pico-serprog/

As seen on Flashprog: https://review.sourcearcade.org/c/flashprog/+/51

Change-Id: If8052bc6f5c314dcc493bc083bb8270723efaae7
Signed-off-by: Riku Viitanen <riku.viitanen@protonmail.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/80498
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
This commit is contained in:
Riku Viitanen 2024-01-15 19:15:49 +02:00 committed by Anastasia Klimchuk
parent 6d128a4fff
commit e8c350f55e
3 changed files with 39 additions and 1 deletions

View File

@ -35,6 +35,7 @@ COMMAND Description Parameters Return Value
+ slen bytes of data
0x14 Set SPI clock frequency in Hz 32-bit requested frequency ACK + 32-bit set frequency / NAK
0x15 Toggle flash chip pin drivers 8-bit (0 disable, else enable) ACK / NAK
0x16 Set SPI Chip Select 8-bit ACK / NAK
0x?? unimplemented command - invalid.
@ -89,6 +90,9 @@ Additional information of the above commands:
remain attached to the flash chip even when the board is running. The user is responsible to
NOT connect VCC and other permanently externally driven signals to the programmer as needed.
If the value is 0, then the drivers should be disabled, otherwise they should be enabled.
0x16 (S_SPI_CS):
Set which SPI Chip Select pin to use. This operation is immediate,
meaning it doesn't use the operation buffer.
About mandatory commands:
The only truly mandatory commands for any device are 0x00, 0x01, 0x02 and 0x10,
but one can't really do anything with these commands.

View File

@ -741,6 +741,14 @@ Example that sets the frequency to 2 MHz::
flashrom -p serprog:dev=/dev/device:baud,spispeed=2M
Optional ``cs`` parameter can be used to switch which chip select number is used. This allows connecting multiple
chips at once and selecting which one to flash by software means (rather than rewiring)::
flashrom -p serprog:dev=/dev/device:baud,cs=0
The particular programmer implementation needs to support this feature, for it to work. If the requested chip
select isn't available, flashrom will fail safely.
More information about serprog is available in **serprog-protocol.txt** in the source distribution.

View File

@ -3,6 +3,7 @@
*
* Copyright (C) 2009, 2011 Urja Rannikko <urjaman@gmail.com>
* Copyright (C) 2009 Carl-Daniel Hailfinger
* Copyright (C) 2024 Riku Viitanen <riku.viitanen@protonmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -63,6 +64,7 @@
#define S_CMD_O_SPIOP 0x13 /* Perform SPI operation. */
#define S_CMD_S_SPI_FREQ 0x14 /* Set SPI clock frequency */
#define S_CMD_S_PIN_STATE 0x15 /* Enable/disable output drivers */
#define S_CMD_S_SPI_CS 0x16 /* Set SPI chip select to use */
#define MSGHEADER "serprog: "
@ -742,7 +744,7 @@ static int serprog_init(const struct programmer_cfg *cfg)
/* Check for the minimum operational set of commands. */
if (serprog_buses_supported & BUS_SPI) {
uint8_t bt = BUS_SPI;
char *spispeed;
char *spispeed, *cs;
if (sp_check_commandavail(S_CMD_O_SPIOP) == 0) {
msg_perr("Error: SPI operation not supported while the "
"bustype is SPI\n");
@ -822,6 +824,30 @@ static int serprog_init(const struct programmer_cfg *cfg)
}
}
free(spispeed);
cs = extract_programmer_param_str(cfg, "cs");
if (cs && strlen(cs)) {
char *endptr = NULL;
errno = 0;
unsigned long cs_num = strtoul(cs, &endptr, 0);
if (errno || *endptr || cs_num > 255) {
msg_perr("Error: Invalid chip select requested! "
"Only 0-255 are valid.\n");
free(cs);
goto init_err_cleanup_exit;
}
free(cs);
if (!sp_check_commandavail(S_CMD_S_SPI_CS)) {
msg_perr("Error: Setting SPI chip select is not supported!\n");
goto init_err_cleanup_exit;
}
msg_pdbg(MSGHEADER "Requested to use chip select %lu.\n", cs_num);
uint8_t cs_num8 = cs_num;
if (sp_docommand(S_CMD_S_SPI_CS, 1, &cs_num8, 0, NULL)) {
msg_perr("Error: Chip select %u not supported "
"by programmer!\n", cs_num8);
goto init_err_cleanup_exit;
}
}
bt = serprog_buses_supported;
if (sp_docommand(S_CMD_S_BUSTYPE, 1, &bt, 0, NULL))
goto init_err_cleanup_exit;