Nico Huber submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Nico Huber: Looks good to me, approved Angel Pons: Looks good to me, approved
ichspi: Extract handling programmer param into a function

Extract processing of ich_spi_mode into a separate function which
is called from init_ich_default. This makes init_ich_default more
readable and avoids one local variable.

BUG=b:204488958
TEST=Check that the following scenarios still behave properly:
1) probe-read-verify-erase section-write-reboot
on Intel octopus board with GD25LQ128C/GD25LQ128D/GD25LQ128E
2) probe and read on Panther Point (7 series PCH)

Change-Id: I20e2379a6fd58c9346f0a2d6daf2b8decf1f6976
Tested-by: Anastasia Klimchuk <aklm@chromium.org>
Tested-by: Nico Huber <nico.h@gmx.de>
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/58736
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Nico Huber <nico.h@gmx.de>
---
M ichspi.c
1 file changed, 37 insertions(+), 27 deletions(-)

diff --git a/ichspi.c b/ichspi.c
index 09a0755..5d18b37 100644
--- a/ichspi.c
+++ b/ichspi.c
@@ -1752,20 +1752,48 @@
return 0;
}

+enum ich_spi_mode {
+ ich_auto,
+ ich_hwseq,
+ ich_swseq
+};
+
+static int get_ich_spi_mode_param(enum ich_spi_mode *ich_spi_mode)
+{
+ char *const arg = extract_programmer_param("ich_spi_mode");
+ if (arg && !strcmp(arg, "hwseq")) {
+ *ich_spi_mode = ich_hwseq;
+ msg_pspew("user selected hwseq\n");
+ } else if (arg && !strcmp(arg, "swseq")) {
+ *ich_spi_mode = ich_swseq;
+ msg_pspew("user selected swseq\n");
+ } else if (arg && !strcmp(arg, "auto")) {
+ msg_pspew("user selected auto\n");
+ *ich_spi_mode = ich_auto;
+ } else if (arg && !strlen(arg)) {
+ msg_perr("Missing argument for ich_spi_mode.\n");
+ free(arg);
+ return ERROR_FATAL;
+ } else if (arg) {
+ msg_perr("Unknown argument for ich_spi_mode: %s\n", arg);
+ free(arg);
+ return ERROR_FATAL;
+ }
+ free(arg);
+
+ return 0;
+}
+
+
static int init_ich_default(void *spibar, enum ich_chipset ich_gen)
{
unsigned int i;
uint16_t tmp2;
uint32_t tmp;
- char *arg;
int ich_spi_rw_restricted = 0;
int desc_valid = 0;
struct ich_descriptors desc = { 0 };
- enum ich_spi_mode {
- ich_auto,
- ich_hwseq,
- ich_swseq
- } ich_spi_mode = ich_auto;
+ enum ich_spi_mode ich_spi_mode = ich_auto;
size_t num_freg, num_pr, reg_pr0;

/* Moving registers / bits */
@@ -1818,27 +1846,9 @@
break;
}

- arg = extract_programmer_param("ich_spi_mode");
- if (arg && !strcmp(arg, "hwseq")) {
- ich_spi_mode = ich_hwseq;
- msg_pspew("user selected hwseq\n");
- } else if (arg && !strcmp(arg, "swseq")) {
- ich_spi_mode = ich_swseq;
- msg_pspew("user selected swseq\n");
- } else if (arg && !strcmp(arg, "auto")) {
- msg_pspew("user selected auto\n");
- ich_spi_mode = ich_auto;
- } else if (arg && !strlen(arg)) {
- msg_perr("Missing argument for ich_spi_mode.\n");
- free(arg);
- return ERROR_FATAL;
- } else if (arg) {
- msg_perr("Unknown argument for ich_spi_mode: %s\n",
- arg);
- free(arg);
- return ERROR_FATAL;
- }
- free(arg);
+ int ret = get_ich_spi_mode_param(&ich_spi_mode);
+ if (ret)
+ return ret;

tmp2 = mmio_readw(spibar + ICH9_REG_HSFS);
msg_pdbg("0x04: 0x%04x (HSFS)\n", tmp2);

7 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one.

To view, visit change 58736. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I20e2379a6fd58c9346f0a2d6daf2b8decf1f6976
Gerrit-Change-Number: 58736
Gerrit-PatchSet: 11
Gerrit-Owner: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: Nikolai Artemiev <nartemiev@google.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Felix Singer <felixsinger@posteo.net>
Gerrit-CC: Paul Menzel <paulepanter@mailbox.org>
Gerrit-MessageType: merged