flash/jtagspi: sending command and setting parameters without probing. 32/7432/5
authorDaniel Anselmi <danselmi@gmx.ch>
Tue, 21 Mar 2023 22:23:12 +0000 (23:23 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 27 May 2023 06:44:31 +0000 (06:44 +0000)
Change-Id: I6b9d90265ca5112b9ab2aae97bb4c6cf3ebc4112
Signed-off-by: Daniel Anselmi <danselmi@gmx.ch>
Reviewed-on: https://review.openocd.org/c/openocd/+/7432
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
src/flash/nor/core.h
src/flash/nor/jtagspi.c
src/flash/nor/tcl.c
tcl/cpld/jtagspi.cfg

index 8c26ba0126b93d2422ef7d0e5f5bd039b3a012cc..80911f799c6510e85762ae47190f4d89d2fdb18d 100644 (file)
@@ -252,6 +252,19 @@ int get_flash_bank_by_num(unsigned int num, struct flash_bank **bank);
  */
 COMMAND_HELPER(flash_command_get_bank, unsigned name_index,
                struct flash_bank **bank);
+/**
+ * Retrieves @a bank from a command argument, reporting errors parsing
+ * the bank identifier or retrieving the specified bank.  The bank
+ * may be identified by its bank number or by @c name.instance, where
+ * @a instance is driver-specific.
+ * @param name_index The index to the string in args containing the
+ * bank identifier.
+ * @param bank On output, contains a pointer to the bank or NULL.
+ * @param do_probe Does auto-probing when set, otherwise without probing.
+ * @returns ERROR_OK on success, or an error indicating the problem.
+ */
+COMMAND_HELPER(flash_command_get_bank_probe_optional, unsigned int name_index,
+               struct flash_bank **bank, bool do_probe);
 /**
  * Returns the flash bank like get_flash_bank_by_num(), without probing.
  * @param num The flash bank number.
index 0047d22bb7df01950f171382417d98decc74bd5c..866548a7e0148b44c71d5d5e0622145b37a6b6d3 100644 (file)
@@ -41,7 +41,11 @@ FLASH_BANK_COMMAND_HANDLER(jtagspi_flash_bank_command)
        bank->sectors = NULL;
        bank->driver_priv = info;
 
-       info->tap = NULL;
+       if (!bank->target->tap) {
+               LOG_ERROR("Target has no JTAG tap");
+               return ERROR_FAIL;
+       }
+       info->tap = bank->target->tap;
        info->probed = false;
        COMMAND_PARSE_NUMBER(u32, CMD_ARGV[6], info->ir);
 
@@ -161,7 +165,12 @@ COMMAND_HANDLER(jtagspi_handle_set)
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
-       retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
+       /* calling flash_command_get_bank without probing because handle_set is used
+          to set device parameters if not autodetected. So probing would fail
+          anyhow.
+       */
+       retval = CALL_COMMAND_HANDLER(flash_command_get_bank_probe_optional, 0,
+               &bank, false);
        if (ERROR_OK != retval)
                return retval;
        info = bank->driver_priv;
@@ -312,7 +321,13 @@ COMMAND_HANDLER(jtagspi_handle_cmd)
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
-       retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
+       /* calling flash_command_get_bank without probing because we like to be
+          able to send commands before auto-probing occurred. For example sending
+          "release from power down" is needed before probing when flash is in
+          power down mode.
+        */
+       retval = CALL_COMMAND_HANDLER(flash_command_get_bank_probe_optional, 0,
+                                                               &bank, false);
        if (ERROR_OK != retval)
                return retval;
 
@@ -381,12 +396,6 @@ static int jtagspi_probe(struct flash_bank *bank)
        }
        info->probed = false;
 
-       if (!bank->target->tap) {
-               LOG_ERROR("Target has no JTAG tap");
-               return ERROR_FAIL;
-       }
-       info->tap = bank->target->tap;
-
        jtagspi_cmd(bank, SPIFLASH_READ_ID, NULL, 0, in_buf, -3);
        /* the table in spi.c has the manufacturer byte (first) as the lsb */
        id = le_to_h_u24(in_buf);
index 22c1710adc99a7acb4542061774f3944f49ee9ff..720fb60a1b520c953f83049ea35245da0b866ca2 100644 (file)
@@ -19,7 +19,7 @@
  * Implements Tcl commands used to access NOR flash facilities.
  */
 
-static COMMAND_HELPER(flash_command_get_bank_maybe_probe, unsigned name_index,
+COMMAND_HELPER(flash_command_get_bank_probe_optional, unsigned int name_index,
               struct flash_bank **bank, bool do_probe)
 {
        const char *name = CMD_ARGV[name_index];
@@ -51,7 +51,7 @@ static COMMAND_HELPER(flash_command_get_bank_maybe_probe, unsigned name_index,
 COMMAND_HELPER(flash_command_get_bank, unsigned name_index,
        struct flash_bank **bank)
 {
-       return CALL_COMMAND_HANDLER(flash_command_get_bank_maybe_probe,
+       return CALL_COMMAND_HANDLER(flash_command_get_bank_probe_optional,
                                    name_index, bank, true);
 }
 
@@ -157,7 +157,7 @@ COMMAND_HANDLER(handle_flash_probe_command)
        if (CMD_ARGC != 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       retval = CALL_COMMAND_HANDLER(flash_command_get_bank_maybe_probe, 0, &p, false);
+       retval = CALL_COMMAND_HANDLER(flash_command_get_bank_probe_optional, 0, &p, false);
        if (retval != ERROR_OK)
                return retval;
 
index 7071e5e34041888ecadd7779d342510ad0baa80e..4c84792fe11bdd68cedb2ac54ffc0840b37845e1 100644 (file)
@@ -23,11 +23,21 @@ if { [info exists FLASHNAME] } {
 target create $_TARGETNAME testee -chain-position $_CHIPNAME.tap
 flash bank $_FLASHNAME jtagspi 0 0 0 0 $_TARGETNAME $_JTAGSPI_IR
 
-proc jtagspi_init {chain_id proxy_bit} {
+# initialize jtagspi flash
+# chain_id: identifier of pld (you can get a list with 'pld devices')
+# proxy_bit: file with bitstream connecting JTAG and SPI interface in the PLD.
+# release_from_pwr_down_cmd: optional, command sent to spi flash before probing.
+#                            ex: 0xAB to release from power-dowm.
+#                            Just omit it to not send a command.
+
+proc jtagspi_init {chain_id proxy_bit {release_from_pwr_down_cmd -1}} {
        # load proxy bitstream $proxy_bit and probe spi flash
        global _FLASHNAME
        pld load $chain_id $proxy_bit
        reset halt
+       if {$release_from_pwr_down_cmd != -1} {
+               jtagspi cmd $_FLASHNAME 0 $release_from_pwr_down_cmd
+       }
        flash probe $_FLASHNAME
 }
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)