OpenOCD
niietcm4.c File Reference
Include dependency graph for niietcm4.c:

Go to the source code of this file.

Data Structures

struct  niietcm4_flash_bank
 Private data for flash driver. More...
 

Macros

#define BF_LOCK_ADDR   0x40
 
#define BOOTFLASH_BASE   0xA001C000
 
#define CHIPID_ADDR   0xF0000000
 
#define FCIC   (BOOTFLASH_BASE + 0x14)
 
#define FCIC_CLR_OPCMLT   (1<<0) /* Clear completion flag in register FCIS */
 
#define FCIC_CLR_OPERROR   (1<<1) /* Clear error flag in register FCIS */
 
#define FCIM   (BOOTFLASH_BASE + 0x10)
 
#define FCIS   (BOOTFLASH_BASE + 0x0C)
 
#define FCIS_OP_CMLT   (1<<0) /* Completion flag operation */
 
#define FCIS_OP_ERROR   (1<<1) /* Flag operation error */
 
#define FLASH_DRIVER_VER   0x00010000
 
#define FMA   (BOOTFLASH_BASE + 0x00)
 
#define FMC   (BOOTFLASH_BASE + 0x08)
 
#define FMC_FULL_ERASE   (1<<2) /* Erase full flash */
 
#define FMC_MAGIC_KEY   (MAGIC_KEY<<16) /* Operation run command */
 
#define FMC_PAGE_ERASE   (1<<1) /* Page erase the main region */
 
#define FMC_PAGEERASE_IFB   (1<<5) /* Erase page of info region */
 
#define FMC_WRITE   (1<<0) /* Writing in main region */
 
#define FMC_WRITE_IFB   (1<<4) /* Writing in info region */
 
#define FMD1   (BOOTFLASH_BASE + 0x04)
 
#define FMD2   (BOOTFLASH_BASE + 0x50)
 
#define FMD3   (BOOTFLASH_BASE + 0x54)
 
#define FMD4   (BOOTFLASH_BASE + 0x58)
 
#define INFO_MEM_TYPE   1
 
#define INFOWORD0_ADDR   0x00
 
#define INFOWORD0_BOOTFROM_IFB   (1<<0) /* Boot from bootflash or bootflash_ifb */
 
#define INFOWORD0_BOOTFROM_IFB_POS   0
 
#define INFOWORD0_EN_GPIO   (1<<1) /* Remap to 0x00000000 extmem or bootflash */
 
#define INFOWORD0_EN_GPIO_POS   1
 
#define INFOWORD0_EXTMEM_SEL_POS   3 /* Choose altfunc of gpio to work with extmem */
 
#define INFOWORD1_ADDR   0x01
 
#define INFOWORD1_PINNUM_POS   0 /* Choose gpio pin number to control extmem boot */
 
#define INFOWORD1_PORTNUM_POS   4 /* Choose gpio port to control extmem boot */
 
#define INFOWORD2_ADDR   0x02
 
#define INFOWORD2_LOCK_IFB_BF   (1<<0) /* Protect info part of bootflash */
 
#define INFOWORD3_ADDR   0x03
 
#define INFOWORD3_LOCK_IFB_UF   (1<<0) /* Protect info part of userflash */
 
#define K1921VK01T_ID   0x00000000
 
#define MAGIC_KEY   0xA442
 
#define MAIN_MEM_TYPE   0
 
#define SERVICE_MODE_ERASE_ADDR   0x80030164
 
#define UF_LOCK_ADDR   0x80
 
#define UFCIC   (USERFLASH_BASE + 0x14)
 
#define UFCIC_CLR_OPCMLT   (1<<0) /* Clear completion flag in register FCIS */
 
#define UFCIC_CLR_OPERROR   (1<<1) /* Clear error flag in register FCIS */
 
#define UFCIM   (USERFLASH_BASE + 0x10)
 
#define UFCIS   (USERFLASH_BASE + 0x0C)
 
#define UFCIS_OP_CMLT   (1<<0) /* Completion flag operation */
 
#define UFCIS_OP_ERROR   (1<<1) /* Flag operation error */
 
#define UFMA   (USERFLASH_BASE + 0x00)
 
#define UFMC   (USERFLASH_BASE + 0x08)
 
#define UFMC_FULL_ERASE   (1<<2) /* Erase full flash */
 
#define UFMC_MAGIC_KEY   (MAGIC_KEY<<16) /* Operation run command */
 
#define UFMC_PAGE_ERASE   (1<<1) /* Paged erase the main region */
 
#define UFMC_PAGEERASE_IFB   (1<<5) /* Erase page of info region */
 
#define UFMC_READ   (1<<3) /* Reading from main region */
 
#define UFMC_READ_IFB   (1<<6) /* Reading from info region */
 
#define UFMC_WRITE   (1<<0) /* Writing in main region */
 
#define UFMC_WRITE_IFB   (1<<4) /* Writing in info region */
 
#define UFMD   (USERFLASH_BASE + 0x04)
 
#define USERFLASH_BASE   0xA0022000
 
#define USERFLASH_PAGE_SIZE   256
 
#define USERFLASH_PAGE_TOTALNUM   256
 

Functions

 COMMAND_HANDLER (niietcm4_handle_bflash_info_remap_command)
 
 COMMAND_HANDLER (niietcm4_handle_driver_info_command)
 
 COMMAND_HANDLER (niietcm4_handle_extmem_boot_command)
 
 COMMAND_HANDLER (niietcm4_handle_extmem_cfg_command)
 
 COMMAND_HANDLER (niietcm4_handle_service_mode_erase_command)
 
 COMMAND_HANDLER (niietcm4_handle_uflash_erase_command)
 
 COMMAND_HANDLER (niietcm4_handle_uflash_full_erase_command)
 
 COMMAND_HANDLER (niietcm4_handle_uflash_protect_check_command)
 
 COMMAND_HANDLER (niietcm4_handle_uflash_protect_command)
 
 COMMAND_HANDLER (niietcm4_handle_uflash_read_byte_command)
 
 COMMAND_HANDLER (niietcm4_handle_uflash_write_byte_command)
 
 FLASH_BANK_COMMAND_HANDLER (niietcm4_flash_bank_command)
 
static int get_niietcm4_info (struct flash_bank *bank, struct command_invocation *cmd)
 
static int niietcm4_auto_probe (struct flash_bank *bank)
 
static int niietcm4_dump_uflash_page (struct flash_bank *bank, uint32_t *dump, int page_num, int mem_type)
 Dump page of userflash region. More...
 
static int niietcm4_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int niietcm4_load_uflash_page (struct flash_bank *bank, uint32_t *dump, int page_num, int mem_type)
 Load modified page dump to userflash region page. More...
 
static int niietcm4_mass_erase (struct flash_bank *bank)
 
static int niietcm4_opstatus_check (struct flash_bank *bank)
 Wait while operation with bootflash being performed and check result status. More...
 
static int niietcm4_probe (struct flash_bank *bank)
 
static int niietcm4_probe_k1921vk01t (struct flash_bank *bank)
 
static int niietcm4_protect (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int niietcm4_protect_check (struct flash_bank *bank)
 
static int niietcm4_uflash_page_erase (struct flash_bank *bank, int page_num, int mem_type)
 Erase one page of userflash info or main region. More...
 
static int niietcm4_uflash_protect (struct flash_bank *bank, int mem_type, int set, unsigned int first, unsigned int last)
 Enable or disable protection of userflash pages. More...
 
static int niietcm4_uopstatus_check (struct flash_bank *bank)
 Wait while operation with userflash being performed and check result status. More...
 
static int niietcm4_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int niietcm4_write_block (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 

Variables

static const struct command_registration niietcm4_command_handlers []
 
static const struct command_registration niietcm4_exec_command_handlers []
 
const struct flash_driver niietcm4_flash
 

Macro Definition Documentation

◆ BF_LOCK_ADDR

#define BF_LOCK_ADDR   0x40

Definition at line 108 of file niietcm4.c.

◆ BOOTFLASH_BASE

#define BOOTFLASH_BASE   0xA001C000

Definition at line 32 of file niietcm4.c.

◆ CHIPID_ADDR

#define CHIPID_ADDR   0xF0000000

Definition at line 18 of file niietcm4.c.

◆ FCIC

#define FCIC   (BOOTFLASH_BASE + 0x14)

Definition at line 38 of file niietcm4.c.

◆ FCIC_CLR_OPCMLT

#define FCIC_CLR_OPCMLT   (1<<0) /* Clear completion flag in register FCIS */

Definition at line 57 of file niietcm4.c.

◆ FCIC_CLR_OPERROR

#define FCIC_CLR_OPERROR   (1<<1) /* Clear error flag in register FCIS */

Definition at line 58 of file niietcm4.c.

◆ FCIM

#define FCIM   (BOOTFLASH_BASE + 0x10)

Definition at line 37 of file niietcm4.c.

◆ FCIS

#define FCIS   (BOOTFLASH_BASE + 0x0C)

Definition at line 36 of file niietcm4.c.

◆ FCIS_OP_CMLT

#define FCIS_OP_CMLT   (1<<0) /* Completion flag operation */

Definition at line 53 of file niietcm4.c.

◆ FCIS_OP_ERROR

#define FCIS_OP_ERROR   (1<<1) /* Flag operation error */

Definition at line 54 of file niietcm4.c.

◆ FLASH_DRIVER_VER

#define FLASH_DRIVER_VER   0x00010000

Definition at line 17 of file niietcm4.c.

◆ FMA

#define FMA   (BOOTFLASH_BASE + 0x00)

Definition at line 33 of file niietcm4.c.

◆ FMC

#define FMC   (BOOTFLASH_BASE + 0x08)

Definition at line 35 of file niietcm4.c.

◆ FMC_FULL_ERASE

#define FMC_FULL_ERASE   (1<<2) /* Erase full flash */

Definition at line 47 of file niietcm4.c.

◆ FMC_MAGIC_KEY

#define FMC_MAGIC_KEY   (MAGIC_KEY<<16) /* Operation run command */

Definition at line 50 of file niietcm4.c.

◆ FMC_PAGE_ERASE

#define FMC_PAGE_ERASE   (1<<1) /* Page erase the main region */

Definition at line 46 of file niietcm4.c.

◆ FMC_PAGEERASE_IFB

#define FMC_PAGEERASE_IFB   (1<<5) /* Erase page of info region */

Definition at line 49 of file niietcm4.c.

◆ FMC_WRITE

#define FMC_WRITE   (1<<0) /* Writing in main region */

Definition at line 45 of file niietcm4.c.

◆ FMC_WRITE_IFB

#define FMC_WRITE_IFB   (1<<4) /* Writing in info region */

Definition at line 48 of file niietcm4.c.

◆ FMD1

#define FMD1   (BOOTFLASH_BASE + 0x04)

Definition at line 34 of file niietcm4.c.

◆ FMD2

#define FMD2   (BOOTFLASH_BASE + 0x50)

Definition at line 39 of file niietcm4.c.

◆ FMD3

#define FMD3   (BOOTFLASH_BASE + 0x54)

Definition at line 40 of file niietcm4.c.

◆ FMD4

#define FMD4   (BOOTFLASH_BASE + 0x58)

Definition at line 41 of file niietcm4.c.

◆ INFO_MEM_TYPE

#define INFO_MEM_TYPE   1

Definition at line 27 of file niietcm4.c.

◆ INFOWORD0_ADDR

#define INFOWORD0_ADDR   0x00

Definition at line 91 of file niietcm4.c.

◆ INFOWORD0_BOOTFROM_IFB

#define INFOWORD0_BOOTFROM_IFB   (1<<0) /* Boot from bootflash or bootflash_ifb */

Definition at line 92 of file niietcm4.c.

◆ INFOWORD0_BOOTFROM_IFB_POS

#define INFOWORD0_BOOTFROM_IFB_POS   0

Definition at line 94 of file niietcm4.c.

◆ INFOWORD0_EN_GPIO

#define INFOWORD0_EN_GPIO   (1<<1) /* Remap to 0x00000000 extmem or bootflash */

Definition at line 93 of file niietcm4.c.

◆ INFOWORD0_EN_GPIO_POS

#define INFOWORD0_EN_GPIO_POS   1

Definition at line 95 of file niietcm4.c.

◆ INFOWORD0_EXTMEM_SEL_POS

#define INFOWORD0_EXTMEM_SEL_POS   3 /* Choose altfunc of gpio to work with extmem */

Definition at line 96 of file niietcm4.c.

◆ INFOWORD1_ADDR

#define INFOWORD1_ADDR   0x01

Definition at line 98 of file niietcm4.c.

◆ INFOWORD1_PINNUM_POS

#define INFOWORD1_PINNUM_POS   0 /* Choose gpio pin number to control extmem boot */

Definition at line 99 of file niietcm4.c.

◆ INFOWORD1_PORTNUM_POS

#define INFOWORD1_PORTNUM_POS   4 /* Choose gpio port to control extmem boot */

Definition at line 100 of file niietcm4.c.

◆ INFOWORD2_ADDR

#define INFOWORD2_ADDR   0x02

Definition at line 102 of file niietcm4.c.

◆ INFOWORD2_LOCK_IFB_BF

#define INFOWORD2_LOCK_IFB_BF   (1<<0) /* Protect info part of bootflash */

Definition at line 103 of file niietcm4.c.

◆ INFOWORD3_ADDR

#define INFOWORD3_ADDR   0x03

Definition at line 105 of file niietcm4.c.

◆ INFOWORD3_LOCK_IFB_UF

#define INFOWORD3_LOCK_IFB_UF   (1<<0) /* Protect info part of userflash */

Definition at line 106 of file niietcm4.c.

◆ K1921VK01T_ID

#define K1921VK01T_ID   0x00000000

Definition at line 19 of file niietcm4.c.

◆ MAGIC_KEY

#define MAGIC_KEY   0xA442

Definition at line 29 of file niietcm4.c.

◆ MAIN_MEM_TYPE

#define MAIN_MEM_TYPE   0

Definition at line 26 of file niietcm4.c.

◆ SERVICE_MODE_ERASE_ADDR

#define SERVICE_MODE_ERASE_ADDR   0x80030164

Definition at line 28 of file niietcm4.c.

◆ UF_LOCK_ADDR

#define UF_LOCK_ADDR   0x80

Definition at line 109 of file niietcm4.c.

◆ UFCIC

#define UFCIC   (USERFLASH_BASE + 0x14)

Definition at line 70 of file niietcm4.c.

◆ UFCIC_CLR_OPCMLT

#define UFCIC_CLR_OPCMLT   (1<<0) /* Clear completion flag in register FCIS */

Definition at line 87 of file niietcm4.c.

◆ UFCIC_CLR_OPERROR

#define UFCIC_CLR_OPERROR   (1<<1) /* Clear error flag in register FCIS */

Definition at line 88 of file niietcm4.c.

◆ UFCIM

#define UFCIM   (USERFLASH_BASE + 0x10)

Definition at line 69 of file niietcm4.c.

◆ UFCIS

#define UFCIS   (USERFLASH_BASE + 0x0C)

Definition at line 68 of file niietcm4.c.

◆ UFCIS_OP_CMLT

#define UFCIS_OP_CMLT   (1<<0) /* Completion flag operation */

Definition at line 83 of file niietcm4.c.

◆ UFCIS_OP_ERROR

#define UFCIS_OP_ERROR   (1<<1) /* Flag operation error */

Definition at line 84 of file niietcm4.c.

◆ UFMA

#define UFMA   (USERFLASH_BASE + 0x00)

Definition at line 65 of file niietcm4.c.

◆ UFMC

#define UFMC   (USERFLASH_BASE + 0x08)

Definition at line 67 of file niietcm4.c.

◆ UFMC_FULL_ERASE

#define UFMC_FULL_ERASE   (1<<2) /* Erase full flash */

Definition at line 75 of file niietcm4.c.

◆ UFMC_MAGIC_KEY

#define UFMC_MAGIC_KEY   (MAGIC_KEY<<16) /* Operation run command */

Definition at line 80 of file niietcm4.c.

◆ UFMC_PAGE_ERASE

#define UFMC_PAGE_ERASE   (1<<1) /* Paged erase the main region */

Definition at line 74 of file niietcm4.c.

◆ UFMC_PAGEERASE_IFB

#define UFMC_PAGEERASE_IFB   (1<<5) /* Erase page of info region */

Definition at line 78 of file niietcm4.c.

◆ UFMC_READ

#define UFMC_READ   (1<<3) /* Reading from main region */

Definition at line 76 of file niietcm4.c.

◆ UFMC_READ_IFB

#define UFMC_READ_IFB   (1<<6) /* Reading from info region */

Definition at line 79 of file niietcm4.c.

◆ UFMC_WRITE

#define UFMC_WRITE   (1<<0) /* Writing in main region */

Definition at line 73 of file niietcm4.c.

◆ UFMC_WRITE_IFB

#define UFMC_WRITE_IFB   (1<<4) /* Writing in info region */

Definition at line 77 of file niietcm4.c.

◆ UFMD

#define UFMD   (USERFLASH_BASE + 0x04)

Definition at line 66 of file niietcm4.c.

◆ USERFLASH_BASE

#define USERFLASH_BASE   0xA0022000

Definition at line 64 of file niietcm4.c.

◆ USERFLASH_PAGE_SIZE

#define USERFLASH_PAGE_SIZE   256

Definition at line 61 of file niietcm4.c.

◆ USERFLASH_PAGE_TOTALNUM

#define USERFLASH_PAGE_TOTALNUM   256

Definition at line 62 of file niietcm4.c.

Function Documentation

◆ COMMAND_HANDLER() [1/11]

◆ COMMAND_HANDLER() [2/11]

COMMAND_HANDLER ( niietcm4_handle_driver_info_command  )

◆ COMMAND_HANDLER() [3/11]

◆ COMMAND_HANDLER() [4/11]

◆ COMMAND_HANDLER() [5/11]

◆ COMMAND_HANDLER() [6/11]

◆ COMMAND_HANDLER() [7/11]

◆ COMMAND_HANDLER() [8/11]

◆ COMMAND_HANDLER() [9/11]

◆ COMMAND_HANDLER() [10/11]

◆ COMMAND_HANDLER() [11/11]

◆ FLASH_BANK_COMMAND_HANDLER()

◆ get_niietcm4_info()

static int get_niietcm4_info ( struct flash_bank bank,
struct command_invocation cmd 
)
static

◆ niietcm4_auto_probe()

static int niietcm4_auto_probe ( struct flash_bank bank)
static

Definition at line 1701 of file niietcm4.c.

References bank, ERROR_OK, niietcm4_probe(), and niietcm4_flash_bank::probed.

◆ niietcm4_dump_uflash_page()

static int niietcm4_dump_uflash_page ( struct flash_bank bank,
uint32_t *  dump,
int  page_num,
int  mem_type 
)
static

Dump page of userflash region.

If we want to change some settings, we have to dump it full, because userflash is flash(not EEPROM). And correct write to flash can be performed only after erase. So without dump, changing one registers will clear others.

Definition at line 219 of file niietcm4.c.

References bank, ERROR_OK, INFO_MEM_TYPE, niietcm4_uopstatus_check(), target_read_u32(), target_write_u32(), UFMA, UFMC, UFMC_MAGIC_KEY, UFMC_READ, UFMC_READ_IFB, UFMD, and USERFLASH_PAGE_SIZE.

Referenced by COMMAND_HANDLER(), niietcm4_protect(), and niietcm4_uflash_protect().

◆ niietcm4_erase()

static int niietcm4_erase ( struct flash_bank bank,
unsigned int  first,
unsigned int  last 
)
static

◆ niietcm4_load_uflash_page()

static int niietcm4_load_uflash_page ( struct flash_bank bank,
uint32_t *  dump,
int  page_num,
int  mem_type 
)
static

Load modified page dump to userflash region page.

Definition at line 255 of file niietcm4.c.

References bank, ERROR_OK, INFO_MEM_TYPE, niietcm4_uopstatus_check(), target_write_u32(), UFMA, UFMC, UFMC_MAGIC_KEY, UFMC_WRITE, UFMC_WRITE_IFB, UFMD, and USERFLASH_PAGE_SIZE.

Referenced by COMMAND_HANDLER(), niietcm4_protect(), and niietcm4_uflash_protect().

◆ niietcm4_mass_erase()

static int niietcm4_mass_erase ( struct flash_bank bank)
static

◆ niietcm4_opstatus_check()

static int niietcm4_opstatus_check ( struct flash_bank bank)
static

Wait while operation with bootflash being performed and check result status.

Definition at line 142 of file niietcm4.c.

References bank, busy_sleep(), ERROR_FLASH_OPERATION_FAILED, ERROR_OK, FCIC, FCIC_CLR_OPCMLT, FCIC_CLR_OPERROR, FCIS, FCIS_OP_ERROR, LOG_ERROR, target_read_u32(), and target_write_u32().

Referenced by niietcm4_erase(), niietcm4_mass_erase(), and niietcm4_write().

◆ niietcm4_probe()

static int niietcm4_probe ( struct flash_bank bank)
static

◆ niietcm4_probe_k1921vk01t()

◆ niietcm4_protect()

◆ niietcm4_protect_check()

◆ niietcm4_uflash_page_erase()

static int niietcm4_uflash_page_erase ( struct flash_bank bank,
int  page_num,
int  mem_type 
)
static

◆ niietcm4_uflash_protect()

static int niietcm4_uflash_protect ( struct flash_bank bank,
int  mem_type,
int  set,
unsigned int  first,
unsigned int  last 
)
static

◆ niietcm4_uopstatus_check()

static int niietcm4_uopstatus_check ( struct flash_bank bank)
static

◆ niietcm4_write()

◆ niietcm4_write_block()

Variable Documentation

◆ niietcm4_command_handlers

const struct command_registration niietcm4_command_handlers[]
static
Initial value:
= {
{
.name = "niietcm4",
.mode = COMMAND_ANY,
.help = "niietcm4 flash command group",
.usage = "",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_ANY
Definition: command.h:42
static const struct command_registration niietcm4_exec_command_handlers[]
Definition: niietcm4.c:941

Definition at line 921 of file niietcm4.c.

◆ niietcm4_exec_command_handlers

const struct command_registration niietcm4_exec_command_handlers[]
static

Definition at line 921 of file niietcm4.c.

◆ niietcm4_flash

const struct flash_driver niietcm4_flash
Initial value:
= {
.name = "niietcm4",
.usage = "flash bank <name> niietcm4 <base> <size> 0 0 <target#>",
.flash_bank_command = niietcm4_flash_bank_command,
.erase = niietcm4_erase,
.protect = niietcm4_protect,
.write = niietcm4_write,
.probe = niietcm4_probe,
.auto_probe = niietcm4_auto_probe,
.erase_check = default_flash_blank_check,
.protect_check = niietcm4_protect_check,
.free_driver_priv = default_flash_free_driver_priv,
}
int default_flash_blank_check(struct flash_bank *bank)
Provides default erased-bank check handling.
int default_flash_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Provides default read implementation for flash memory.
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.
static const struct command_registration niietcm4_command_handlers[]
Definition: niietcm4.c:1022
static int get_niietcm4_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: niietcm4.c:1709
static int niietcm4_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: niietcm4.c:1359
static int niietcm4_probe(struct flash_bank *bank)
Definition: niietcm4.c:1664
static int niietcm4_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: niietcm4.c:1203
static int niietcm4_protect_check(struct flash_bank *bank)
Definition: niietcm4.c:1067
static int niietcm4_auto_probe(struct flash_bank *bank)
Definition: niietcm4.c:1701
static int niietcm4_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: niietcm4.c:1156

Definition at line 1709 of file niietcm4.c.