Convert to non-recursive make
[openocd.git] / src / flash / nand / arm_io.c
index cf494766dddb46744e7db6f92a2ac482adbe24d1..e319f9585241f95e2ee1781e4ed9335a92303bab 100644 (file)
@@ -15,9 +15,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the
- * Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -28,6 +26,7 @@
 #include "arm_io.h"
 #include <helper/binarybuffer.h>
 #include <target/arm.h>
+#include <target/armv7m.h>
 #include <target/algorithm.h>
 
 /**
@@ -47,7 +46,6 @@ static int arm_code_to_working_area(struct target *target,
        unsigned additional, struct working_area **area)
 {
        uint8_t code_buf[code_size];
-       unsigned i;
        int retval;
        unsigned size = code_size + additional;
 
@@ -66,8 +64,7 @@ static int arm_code_to_working_area(struct target *target,
        }
 
        /* buffer code in target endianness */
-       for (i = 0; i < code_size / 4; i++)
-               target_buffer_set_u32(target, code_buf + i * 4, code[i]);
+       target_buffer_set_u32_array(target, code_buf, code_size / 4, code);
 
        /* copy code to work area */
        retval = target_write_memory(target, (*area)->address,
@@ -78,14 +75,13 @@ static int arm_code_to_working_area(struct target *target,
 
 /**
  * ARM-specific bulk write from buffer to address of 8-bit wide NAND.
- * For now this only supports ARMv4 and ARMv5 cores.
+ * For now this supports ARMv4,ARMv5 and ARMv7-M cores.
  *
  * Enhancements to target_run_algorithm() could enable:
  *   - ARMv6 and ARMv7 cores in ARM mode
  *
  * Different code fragments could handle:
- *   - Thumb2 cores like Cortex-M (needs different byteswapping)
- *   - 16-bit wide data (needs different setup too)
+ *   - 16-bit wide data (needs different setup)
  *
  * @param nand Pointer to the arm_nand_data struct that defines the I/O
  * @param data Pointer to the data to be copied to flash
@@ -95,7 +91,9 @@ static int arm_code_to_working_area(struct target *target,
 int arm_nandwrite(struct arm_nand_data *nand, uint8_t *data, int size)
 {
        struct target *target = nand->target;
-       struct arm_algorithm algo;
+       struct arm_algorithm armv4_5_algo;
+       struct armv7m_algorithm armv7m_algo;
+       void *arm_algo;
        struct arm *arm = target->arch_info;
        struct reg_param reg_params[3];
        uint32_t target_buf;
@@ -107,7 +105,7 @@ int arm_nandwrite(struct arm_nand_data *nand, uint8_t *data, int size)
         *  r1  buffer address
         *  r2  buffer length
         */
-       static const uint32_t code[] = {
+       static const uint32_t code_armv4_5[] = {
                0xe4d13001,     /* s: ldrb  r3, [r1], #1 */
                0xe5c03000,     /*    strb  r3, [r0]     */
                0xe2522001,     /*    subs  r2, r2, #1   */
@@ -117,8 +115,41 @@ int arm_nandwrite(struct arm_nand_data *nand, uint8_t *data, int size)
                0xe1200070,     /* e: bkpt  #0           */
        };
 
+       /* Inputs:
+        *  r0  NAND data address (byte wide)
+        *  r1  buffer address
+        *  r2  buffer length
+        *
+        * see contrib/loaders/flash/armv7m_io.s for src
+        */
+       static const uint32_t code_armv7m[] = {
+               0x3b01f811,
+               0x3a017003,
+               0xaffaf47f,
+               0xbf00be00,
+       };
+
+       int target_code_size = 0;
+       const uint32_t *target_code_src = NULL;
+
+       /* set up algorithm */
+       if (is_armv7m(target_to_armv7m(target))) {  /* armv7m target */
+               armv7m_algo.common_magic = ARMV7M_COMMON_MAGIC;
+               armv7m_algo.core_mode = ARM_MODE_THREAD;
+               arm_algo = &armv7m_algo;
+               target_code_size = sizeof(code_armv7m);
+               target_code_src = code_armv7m;
+       } else {
+               armv4_5_algo.common_magic = ARM_COMMON_MAGIC;
+               armv4_5_algo.core_mode = ARM_MODE_SVC;
+               armv4_5_algo.core_state = ARM_STATE_ARM;
+               arm_algo = &armv4_5_algo;
+               target_code_size = sizeof(code_armv4_5);
+               target_code_src = code_armv4_5;
+       }
+
        if (nand->op != ARM_NAND_WRITE || !nand->copy_area) {
-               retval = arm_code_to_working_area(target, code, sizeof(code),
+               retval = arm_code_to_working_area(target, target_code_src, target_code_size,
                                nand->chunk_size, &nand->copy_area);
                if (retval != ERROR_OK)
                        return retval;
@@ -127,20 +158,12 @@ int arm_nandwrite(struct arm_nand_data *nand, uint8_t *data, int size)
        nand->op = ARM_NAND_WRITE;
 
        /* copy data to work area */
-       target_buf = nand->copy_area->address + sizeof(code);
-       retval = target_bulk_write_memory(target, target_buf, size / 4, data);
-       if (retval == ERROR_OK && (size & 3) != 0)
-               retval = target_write_memory(target,
-                               target_buf + (size & ~3),
-                               1, size & 3, data + (size & ~3));
+       target_buf = nand->copy_area->address + target_code_size;
+       retval = target_write_buffer(target, target_buf, size, data);
        if (retval != ERROR_OK)
                return retval;
 
-       /* set up algorithm and parameters */
-       algo.common_magic = ARM_COMMON_MAGIC;
-       algo.core_mode = ARM_MODE_SVC;
-       algo.core_state = ARM_STATE_ARM;
-
+       /* set up parameters */
        init_reg_param(&reg_params[0], "r0", 32, PARAM_IN);
        init_reg_param(&reg_params[1], "r1", 32, PARAM_IN);
        init_reg_param(&reg_params[2], "r2", 32, PARAM_IN);
@@ -151,11 +174,11 @@ int arm_nandwrite(struct arm_nand_data *nand, uint8_t *data, int size)
 
        /* armv4 must exit using a hardware breakpoint */
        if (arm->is_armv4)
-               exit_var = nand->copy_area->address + sizeof(code) - 4;
+               exit_var = nand->copy_area->address + target_code_size - 4;
 
        /* use alg to write data from work area to NAND chip */
        retval = target_run_algorithm(target, 0, NULL, 3, reg_params,
-                       nand->copy_area->address, exit_var, 1000, &algo);
+                       nand->copy_area->address, exit_var, 1000, arm_algo);
        if (retval != ERROR_OK)
                LOG_ERROR("error executing hosted NAND write");
 
@@ -178,7 +201,9 @@ int arm_nandwrite(struct arm_nand_data *nand, uint8_t *data, int size)
 int arm_nandread(struct arm_nand_data *nand, uint8_t *data, uint32_t size)
 {
        struct target *target = nand->target;
-       struct arm_algorithm algo;
+       struct arm_algorithm armv4_5_algo;
+       struct armv7m_algorithm armv7m_algo;
+       void *arm_algo;
        struct arm *arm = target->arch_info;
        struct reg_param reg_params[3];
        uint32_t target_buf;
@@ -190,7 +215,7 @@ int arm_nandread(struct arm_nand_data *nand, uint8_t *data, uint32_t size)
         *  r1  NAND data address (byte wide)
         *  r2  buffer length
         */
-       static const uint32_t code[] = {
+       static const uint32_t code_armv4_5[] = {
                0xe5d13000,     /* s: ldrb  r3, [r1]     */
                0xe4c03001,     /*    strb  r3, [r0], #1 */
                0xe2522001,     /*    subs  r2, r2, #1   */
@@ -200,22 +225,51 @@ int arm_nandread(struct arm_nand_data *nand, uint8_t *data, uint32_t size)
                0xe1200070,     /* e: bkpt  #0           */
        };
 
+       /* Inputs:
+        *  r0  buffer address
+        *  r1  NAND data address (byte wide)
+        *  r2  buffer length
+        *
+        * see contrib/loaders/flash/armv7m_io.s for src
+        */
+       static const uint32_t code_armv7m[] = {
+               0xf800780b,
+               0x3a013b01,
+               0xaffaf47f,
+               0xbf00be00,
+       };
+
+       int target_code_size = 0;
+       const uint32_t *target_code_src = NULL;
+
+       /* set up algorithm */
+       if (is_armv7m(target_to_armv7m(target))) {  /* armv7m target */
+               armv7m_algo.common_magic = ARMV7M_COMMON_MAGIC;
+               armv7m_algo.core_mode = ARM_MODE_THREAD;
+               arm_algo = &armv7m_algo;
+               target_code_size = sizeof(code_armv7m);
+               target_code_src = code_armv7m;
+       } else {
+               armv4_5_algo.common_magic = ARM_COMMON_MAGIC;
+               armv4_5_algo.core_mode = ARM_MODE_SVC;
+               armv4_5_algo.core_state = ARM_STATE_ARM;
+               arm_algo = &armv4_5_algo;
+               target_code_size = sizeof(code_armv4_5);
+               target_code_src = code_armv4_5;
+       }
+
        /* create the copy area if not yet available */
        if (nand->op != ARM_NAND_READ || !nand->copy_area) {
-               retval = arm_code_to_working_area(target, code, sizeof(code),
+               retval = arm_code_to_working_area(target, target_code_src, target_code_size,
                                nand->chunk_size, &nand->copy_area);
                if (retval != ERROR_OK)
                        return retval;
        }
 
        nand->op = ARM_NAND_READ;
-       target_buf = nand->copy_area->address + sizeof(code);
-
-       /* set up algorithm and parameters */
-       algo.common_magic = ARM_COMMON_MAGIC;
-       algo.core_mode = ARM_MODE_SVC;
-       algo.core_state = ARM_STATE_ARM;
+       target_buf = nand->copy_area->address + target_code_size;
 
+       /* set up parameters */
        init_reg_param(&reg_params[0], "r0", 32, PARAM_IN);
        init_reg_param(&reg_params[1], "r1", 32, PARAM_IN);
        init_reg_param(&reg_params[2], "r2", 32, PARAM_IN);
@@ -226,11 +280,11 @@ int arm_nandread(struct arm_nand_data *nand, uint8_t *data, uint32_t size)
 
        /* armv4 must exit using a hardware breakpoint */
        if (arm->is_armv4)
-               exit_var = nand->copy_area->address + sizeof(code) - 4;
+               exit_var = nand->copy_area->address + target_code_size - 4;
 
        /* use alg to write data from NAND chip to work area */
        retval = target_run_algorithm(target, 0, NULL, 3, reg_params,
-                       nand->copy_area->address, exit_var, 1000, &algo);
+                       nand->copy_area->address, exit_var, 1000, arm_algo);
        if (retval != ERROR_OK)
                LOG_ERROR("error executing hosted NAND read");
 

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)