mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 15:12:36 +02:00
pony_spi.c: Extract out get_params to simplify init
In light of `commit caa0335114a81`, extract out the get_param logic to its own function to simplify the number of cleanup paths. BUG=none TEST=builds Change-Id: I364febc05c870683cbad114583762b0c006f4bac Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/63130 Reviewed-by: Felix Singer <felixsinger@posteo.net> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
7b4c4f3611
commit
cfca851120
98
pony_spi.c
98
pony_spi.c
@ -120,18 +120,68 @@ static int pony_spi_shutdown(void *data)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int get_params(enum pony_type *type, int *have_device)
|
||||||
|
{
|
||||||
|
char *arg = NULL;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
/* defaults */
|
||||||
|
*type = TYPE_SI_PROG;
|
||||||
|
*have_device = 0;
|
||||||
|
|
||||||
|
/* The parameter is in format "dev=/dev/device,type=serbang" */
|
||||||
|
arg = extract_programmer_param("dev");
|
||||||
|
if (arg && strlen(arg)) {
|
||||||
|
sp_fd = sp_openserport(arg, 9600);
|
||||||
|
if (sp_fd == SER_INV_FD)
|
||||||
|
ret = 1;
|
||||||
|
else
|
||||||
|
(*have_device)++;
|
||||||
|
}
|
||||||
|
free(arg);
|
||||||
|
|
||||||
|
arg = extract_programmer_param("type");
|
||||||
|
if (arg && !strcasecmp(arg, "serbang")) {
|
||||||
|
*type = TYPE_SERBANG;
|
||||||
|
} else if (arg && !strcasecmp(arg, "si_prog")) {
|
||||||
|
*type = TYPE_SI_PROG;
|
||||||
|
} else if (arg && !strcasecmp( arg, "ajawe")) {
|
||||||
|
*type = TYPE_AJAWE;
|
||||||
|
} else if (arg && !strlen(arg)) {
|
||||||
|
msg_perr("Error: Missing argument for programmer type.\n");
|
||||||
|
ret = 1;
|
||||||
|
} else if (arg) {
|
||||||
|
msg_perr("Error: Invalid programmer type specified.\n");
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
free(arg);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int pony_spi_init(void)
|
static int pony_spi_init(void)
|
||||||
{
|
{
|
||||||
int i, data_out;
|
int i, data_out;
|
||||||
char *arg = NULL;
|
enum pony_type type;
|
||||||
enum pony_type type = TYPE_SI_PROG;
|
|
||||||
const char *name;
|
const char *name;
|
||||||
int have_device = 0;
|
int have_device;
|
||||||
int have_prog = 0;
|
int have_prog = 0;
|
||||||
|
|
||||||
|
if (get_params(&type, &have_device)) {
|
||||||
|
serialport_shutdown(NULL);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!have_device) {
|
||||||
|
msg_perr("Error: No valid device specified.\n"
|
||||||
|
"Use flashrom -p pony_spi:dev=/dev/device[,type=name]\n");
|
||||||
|
serialport_shutdown(NULL);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
struct pony_spi_data *data = calloc(1, sizeof(*data));
|
struct pony_spi_data *data = calloc(1, sizeof(*data));
|
||||||
if (!data) {
|
if (!data) {
|
||||||
msg_perr("Unable to allocate space for SPI master data\n");
|
msg_perr("Unable to allocate space for SPI master data\n");
|
||||||
|
serialport_shutdown(NULL);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
data->negate_cs = 1;
|
data->negate_cs = 1;
|
||||||
@ -139,50 +189,12 @@ static int pony_spi_init(void)
|
|||||||
data->negate_mosi = 0;
|
data->negate_mosi = 0;
|
||||||
data->negate_miso = 0;
|
data->negate_miso = 0;
|
||||||
|
|
||||||
/* The parameter is in format "dev=/dev/device,type=serbang" */
|
if (register_shutdown(pony_spi_shutdown, data) != 0) {
|
||||||
arg = extract_programmer_param("dev");
|
|
||||||
if (arg && strlen(arg)) {
|
|
||||||
sp_fd = sp_openserport(arg, 9600);
|
|
||||||
if (sp_fd == SER_INV_FD) {
|
|
||||||
free(arg);
|
|
||||||
free(data);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (register_shutdown(pony_spi_shutdown, data) != 0) {
|
|
||||||
free(arg);
|
|
||||||
free(data);
|
|
||||||
serialport_shutdown(NULL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
have_device++;
|
|
||||||
}
|
|
||||||
free(arg);
|
|
||||||
|
|
||||||
if (!have_device) {
|
|
||||||
msg_perr("Error: No valid device specified.\n"
|
|
||||||
"Use flashrom -p pony_spi:dev=/dev/device[,type=name]\n");
|
|
||||||
free(data);
|
free(data);
|
||||||
|
serialport_shutdown(NULL);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
arg = extract_programmer_param("type");
|
|
||||||
if (arg && !strcasecmp(arg, "serbang")) {
|
|
||||||
type = TYPE_SERBANG;
|
|
||||||
} else if (arg && !strcasecmp(arg, "si_prog")) {
|
|
||||||
type = TYPE_SI_PROG;
|
|
||||||
} else if (arg && !strcasecmp( arg, "ajawe")) {
|
|
||||||
type = TYPE_AJAWE;
|
|
||||||
} else if (arg && !strlen(arg)) {
|
|
||||||
msg_perr("Error: Missing argument for programmer type.\n");
|
|
||||||
free(arg);
|
|
||||||
return 1;
|
|
||||||
} else if (arg){
|
|
||||||
msg_perr("Error: Invalid programmer type specified.\n");
|
|
||||||
free(arg);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
free(arg);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Configure the serial port pins, depending on the used programmer.
|
* Configure the serial port pins, depending on the used programmer.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user