This is an automated email from Gerrit.

"Carlos Sanchez <carlossanc...@geotab.com>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8011

-- gerrit

commit 2adb6b6c5630ea3fdd52be72c6c6601d55ced9de
Author: Sven van Ashbrook <svenvanasbro...@geotab.com>
Date:   Fri Apr 29 16:35:22 2022 -0400

    flash/nor/kinetis: create separate nvm_partition cmd for S32K
    
    S32K FlexNVM partitioning is different from Kinetis,
    so a separate nvm_partition command is required.
    
    Change-Id: Iadb634e2d0619c2c5f0f1926d26bc6629cda0e61
    Signed-off-by: Sven van Ashbrook <svenvanasbro...@geotab.com>

diff --git a/src/flash/nor/kinetis.c b/src/flash/nor/kinetis.c
index 6ac0b31438..e33570b69f 100644
--- a/src/flash/nor/kinetis.c
+++ b/src/flash/nor/kinetis.c
@@ -327,6 +327,7 @@ struct kinetis_chip {
 
        int (*probe_chip)(struct kinetis_chip *k_chip);
        int (*bank_verify_maxaddr)(struct flash_bank *bank);
+       __COMMAND_HANDLER((*nvm_partition_handler));
 };
 
 struct kinetis_type {
@@ -412,6 +413,8 @@ static int kinetis_probe_chip(struct kinetis_chip *k_chip);
 static int s32k_probe_chip(struct kinetis_chip *k_chip);
 static int kinetis_bank_verify_maxaddr(struct flash_bank *bank);
 static int kinetis_auto_probe(struct flash_bank *bank);
+COMMAND_HANDLER(kinetis_nvm_partition);
+COMMAND_HANDLER(s32k_nvm_partition);
 
 
 static int kinetis_mdm_write_register(struct adiv5_dap *dap, unsigned reg, 
uint32_t value)
@@ -900,6 +903,7 @@ static int kinetis_chip_options(struct kinetis_chip 
*k_chip, int argc, const cha
                        if (i + 1 < argc && strcmp(argv[++i], "s32k") == 0) {
                                k_chip->probe_chip = s32k_probe_chip;
                                k_chip->bank_verify_maxaddr = NULL;
+                               k_chip->nvm_partition_handler = 
s32k_nvm_partition;
                        }
                } else
                        LOG_ERROR("Unsupported flash bank option %s", argv[i]);
@@ -931,6 +935,7 @@ FLASH_BANK_COMMAND_HANDLER(kinetis_flash_bank_command)
                k_chip->target = target;
                k_chip->probe_chip = kinetis_probe_chip;
                k_chip->bank_verify_maxaddr = kinetis_bank_verify_maxaddr;
+               k_chip->nvm_partition_handler = kinetis_nvm_partition;
 
                /* only the first defined bank can define chip options */
                retval = kinetis_chip_options(k_chip, CMD_ARGC - 6, CMD_ARGV + 
6);
@@ -3042,6 +3047,100 @@ static int kinetis_blank_check(struct flash_bank *bank)
        return ERROR_OK;
 }
 
+COMMAND_HANDLER(s32k_nvm_partition)
+{
+       enum { SHOW_INFO, DF_SIZE, EEBKP_SIZE } sz_type = SHOW_INFO;
+       struct target *target = get_current_target(CMD_CTX);
+       struct kinetis_chip *k_chip = kinetis_get_chip(target);
+       unsigned int num_blocks, first_nvm_bank;
+       uint8_t flex_nvm_partition_code;
+       uint8_t ee_size_code;
+       bool load_flex_ram = false;
+       int result, ee1, ee2;
+       unsigned int bank_idx;
+       unsigned long par;
+
+       if (CMD_ARGC >= 2) {
+               if (strcmp(CMD_ARGV[0], "dataflash") == 0)
+                       sz_type = DF_SIZE;
+               else if (strcmp(CMD_ARGV[0], "eebkp") == 0)
+                       sz_type = EEBKP_SIZE;
+
+               COMMAND_PARSE_NUMBER(ulong, CMD_ARGV[1], par);
+       }
+
+       switch (sz_type) {
+       case SHOW_INFO:
+               if (!k_chip) {
+                       LOG_ERROR("Chip not probed.");
+                       return ERROR_FAIL;
+               }
+               if (k_chip->ee_size) {
+                       command_print(CMD, "FlexNVM: %dk total, data flash %dk, 
eeram %dk",
+                               k_chip->nvm_size >> 10, k_chip->dflash_size >> 
10, k_chip->ee_size >> 10);
+               } else {
+                       command_print(CMD, "No EEPROM backup, data flash only");
+               }
+               return ERROR_OK;
+
+       default:
+               break;
+       }
+
+       if (k_chip->pflash_size != 3 * (512 << 10) || k_chip->nvm_size != (512 
<< 10)) {
+               LOG_ERROR("Unsupported Flash Layout");
+               return ERROR_FAIL;
+       }
+
+       if ((sz_type == DF_SIZE && par == 448) || (sz_type == EEBKP_SIZE && par 
== 4)) {
+               flex_nvm_partition_code = 4;
+               ee_size_code = 0x2;
+       } else if ((sz_type == DF_SIZE && par == 512) || (sz_type == EEBKP_SIZE 
&& par == 0)) {
+               flex_nvm_partition_code = 0;
+               ee_size_code = 0xF;
+       } else {
+               command_print(CMD, "Unsupported EEPROM backup size");
+               return ERROR_FAIL;
+       }
+
+       if (CMD_ARGC >= 4) {
+               if (sscanf(CMD_ARGV[2], "%i", &ee1) != 1 || sscanf(CMD_ARGV[3], 
"%i", &ee2) != 1 || ee1 != 0 || ee2 != 0) {
+                       command_print(CMD, "ERROR: eesize1 and eesize2 must be 
zero on S32K");
+                       return ERROR_FAIL;
+               }
+       }
+
+       if (CMD_ARGC >= 5)
+               COMMAND_PARSE_ON_OFF(CMD_ARGV[4], load_flex_ram);
+
+       result = kinetis_check_run_mode(k_chip);
+       if (result != ERROR_OK)
+               return result;
+
+       /* reset error flags */
+       result = kinetis_ftfx_prepare(target);
+       if (result != ERROR_OK)
+               return result;
+
+       result = kinetis_ftfx_command(target, FTFX_CMD_PGMPART, load_flex_ram ? 
0 : 1,
+                                     ee_size_code, flex_nvm_partition_code, 0, 
0,
+                                     0, 0, 0, 0,  NULL);
+       if (result != ERROR_OK)
+               return result;
+
+       command_print(CMD, "FlexNVM partition set. Please reset MCU.");
+
+       if (k_chip) {
+               first_nvm_bank = k_chip->num_pflash_blocks;
+               num_blocks = k_chip->num_pflash_blocks + k_chip->num_nvm_blocks;
+               for (bank_idx = first_nvm_bank; bank_idx < num_blocks; 
bank_idx++)
+                       k_chip->banks[bank_idx].probed = false; /* re-probe 
before next use */
+               k_chip->probed = false;
+       }
+
+       command_print(CMD, "FlexNVM banks will be re-probed to set new data 
flash size.");
+       return ERROR_OK;
+}
 
 COMMAND_HANDLER(kinetis_nvm_partition)
 {
@@ -3191,6 +3290,14 @@ COMMAND_HANDLER(kinetis_nvm_partition)
        return ERROR_OK;
 }
 
+COMMAND_HANDLER(nvm_partition)
+{
+       struct target *target = get_current_target(CMD_CTX);
+       struct kinetis_chip *k_chip = kinetis_get_chip(target);
+
+       return CALL_COMMAND_HANDLER(k_chip->nvm_partition_handler);
+}
+
 COMMAND_HANDLER(kinetis_fcf_source_handler)
 {
        if (CMD_ARGC > 1)
@@ -3293,9 +3400,10 @@ static const struct command_registration 
kinetis_exec_command_handlers[] = {
                .name = "nvm_partition",
                .mode = COMMAND_EXEC,
                .help = "Show/set data flash or EEPROM backup size in 
kilobytes,"
-                       " set two EEPROM sizes in bytes and FlexRAM loading 
during reset",
+                       " set two EEPROM sizes in bytes and FlexRAM loading 
during reset."
+                       " Note that on S32K, eesize1 and eesize2 are reserved 
and must be set to zero.",
                .usage = "('info'|'dataflash' size|'eebkp' size) [eesize1 
eesize2] ['on'|'off']",
-               .handler = kinetis_nvm_partition,
+               .handler = nvm_partition,
        },
        {
                .name = "fcf_source",

-- 

Reply via email to