21 #define FLASH_DQ6 0x40
22 #define FLASH_DQ5 0x20
64 bank->driver_priv = fm3_info;
67 if (strcmp(
CMD_ARGV[5],
"mb9bfxx1.cpu") == 0) {
70 }
else if (strcmp(
CMD_ARGV[5],
"mb9bfxx2.cpu") == 0) {
73 }
else if (strcmp(
CMD_ARGV[5],
"mb9bfxx3.cpu") == 0) {
76 }
else if (strcmp(
CMD_ARGV[5],
"mb9bfxx4.cpu") == 0) {
79 }
else if (strcmp(
CMD_ARGV[5],
"mb9bfxx5.cpu") == 0) {
82 }
else if (strcmp(
CMD_ARGV[5],
"mb9bfxx6.cpu") == 0) {
85 }
else if (strcmp(
CMD_ARGV[5],
"mb9bfxx7.cpu") == 0) {
88 }
else if (strcmp(
CMD_ARGV[5],
"mb9bfxx8.cpu") == 0) {
91 }
else if (strcmp(
CMD_ARGV[5],
"mb9afxx1.cpu") == 0) {
94 }
else if (strcmp(
CMD_ARGV[5],
"mb9afxx2.cpu") == 0) {
97 }
else if (strcmp(
CMD_ARGV[5],
"mb9afxx3.cpu") == 0) {
100 }
else if (strcmp(
CMD_ARGV[5],
"mb9afxx4.cpu") == 0) {
103 }
else if (strcmp(
CMD_ARGV[5],
"mb9afxx5.cpu") == 0) {
106 }
else if (strcmp(
CMD_ARGV[5],
"mb9afxx6.cpu") == 0) {
109 }
else if (strcmp(
CMD_ARGV[5],
"mb9afxx7.cpu") == 0) {
112 }
else if (strcmp(
CMD_ARGV[5],
"mb9afxx8.cpu") == 0) {
133 uint8_t state1, state2;
181 if (ms > timeout_ms) {
182 LOG_ERROR(
"Polling data reading timed out!");
199 uint32_t u32_dummy_read;
201 uint32_t u32_flash_type;
202 uint32_t u32_flash_seq_address1;
203 uint32_t u32_flash_seq_address2;
209 u32_flash_type = (uint32_t) fm3_info->
flashtype;
212 u32_flash_seq_address1 = 0x00001550;
213 u32_flash_seq_address2 = 0x00000AA8;
215 u32_flash_seq_address1 = 0x00000AA8;
216 u32_flash_seq_address2 = 0x00000554;
231 static const uint8_t fm3_flash_erase_sector_code[] = {
253 LOG_INFO(
"Fujitsu MB9[A/B]FXXX: Sector Erase ... (%u to %u)", first, last);
281 LOG_WARNING(
"no working area available, can't do block memory writes");
285 sizeof(fm3_flash_erase_sector_code), fm3_flash_erase_sector_code);
297 for (
unsigned int sector = first ; sector <= last ; sector++) {
298 uint32_t
offset =
bank->sectors[sector].offset;
300 for (odd = 0; odd < 2 ; odd++) {
304 buf_set_u32(reg_params[0].value, 0, 32, u32_flash_seq_address1);
305 buf_set_u32(reg_params[1].value, 0, 32, u32_flash_seq_address2);
309 write_algorithm->
address, 0, 100000, &armv7m_info);
311 LOG_ERROR(
"Error executing flash erase programming algorithm");
347 uint32_t u32_flash_type;
348 uint32_t u32_flash_seq_address1;
349 uint32_t u32_flash_seq_address2;
355 u32_flash_type = (uint32_t) fm3_info->
flashtype;
358 u32_flash_seq_address1 = 0x00001550;
359 u32_flash_seq_address2 = 0x00000AA8;
361 u32_flash_seq_address1 = 0x00000AA8;
362 u32_flash_seq_address2 = 0x00000554;
376 static const uint8_t fm3_flash_write_code[] = {
378 0x5F, 0xF0, 0x80, 0x45,
380 0x4F, 0xF6, 0xFD, 0x76,
382 0x5F, 0xF0, 0x80, 0x46,
385 0x5F, 0xF0, 0x80, 0x45,
387 0x55, 0xF0, 0x01, 0x05,
388 0x5F, 0xF0, 0x80, 0x46,
392 0x5F, 0xF0, 0x80, 0x46,
441 0x15, 0xF0, 0x80, 0x05,
443 0x16, 0xF0, 0x80, 0x06,
469 0x5F, 0xF0, 0x80, 0x45,
471 0x4F, 0xF6, 0xFE, 0x76,
473 0x5F, 0xF0, 0x80, 0x46,
476 0x5F, 0xF0, 0x80, 0x45,
478 0x55, 0xF0, 0x02, 0x05,
479 0x5F, 0xF0, 0x80, 0x46,
483 0x5F, 0xF0, 0x80, 0x46,
488 0xDF, 0xF8, 0x08, 0x50,
497 0x00, 0x00, 0x00, 0x20,
498 0x04, 0x00, 0x00, 0x20
501 LOG_INFO(
"Fujitsu MB9[A/B]FXXX: FLASH Write ...");
527 LOG_WARNING(
"no working area available, can't do block memory writes");
532 sizeof(fm3_flash_write_code), fm3_flash_write_code);
539 +
sizeof(fm3_flash_write_code) - 8, (write_algorithm->
address));
544 +
sizeof(fm3_flash_write_code) - 4, (write_algorithm->
address) + 4);
557 LOG_WARNING(
"No large enough working area available, can't do block memory writes");
583 buf_set_u32(reg_params[2].value, 0, 32, thisrun_count);
584 buf_set_u32(reg_params[3].value, 0, 32, u32_flash_seq_address1);
585 buf_set_u32(reg_params[4].value, 0, 32, u32_flash_seq_address2);
588 (write_algorithm->
address + 8), 0, 1000, &armv7m_info);
590 LOG_ERROR(
"Error executing fm3 Flash programming algorithm");
596 LOG_ERROR(
"Fujitsu MB9[A/B]FXXX: Flash programming ERROR (Timeout) -> Reg R3: %" PRIx32,
602 buffer += thisrun_count * 2;
604 count -= thisrun_count;
649 bank->base = 0x00000000;
650 bank->size = 32 * 1024;
652 bank->sectors[0].offset = 0;
653 bank->sectors[0].size = 16 * 1024;
654 bank->sectors[0].is_erased = -1;
655 bank->sectors[0].is_protected = -1;
657 bank->sectors[1].offset = 0x4000;
658 bank->sectors[1].size = 16 * 1024;
659 bank->sectors[1].is_erased = -1;
660 bank->sectors[1].is_protected = -1;
665 bank->size = 64 * 1024;
666 bank->num_sectors = num_pages;
668 bank->sectors[2].offset = 0x8000;
669 bank->sectors[2].size = 32 * 1024;
670 bank->sectors[2].is_erased = -1;
671 bank->sectors[2].is_protected = -1;
687 bank->size = 128 * 1024;
688 bank->num_sectors = num_pages;
690 bank->sectors[2].offset = 0x8000;
691 bank->sectors[2].size = 96 * 1024;
692 bank->sectors[2].is_erased = -1;
693 bank->sectors[2].is_protected = -1;
707 bank->size = 256 * 1024;
708 bank->num_sectors = num_pages;
710 bank->sectors[3].offset = 0x20000;
711 bank->sectors[3].size = 128 * 1024;
712 bank->sectors[3].is_erased = -1;
713 bank->sectors[3].is_protected = -1;
725 bank->size = 384 * 1024;
726 bank->num_sectors = num_pages;
728 bank->sectors[4].offset = 0x40000;
729 bank->sectors[4].size = 128 * 1024;
730 bank->sectors[4].is_erased = -1;
731 bank->sectors[4].is_protected = -1;
741 bank->size = 512 * 1024;
742 bank->num_sectors = num_pages;
744 bank->sectors[5].offset = 0x60000;
745 bank->sectors[5].size = 128 * 1024;
746 bank->sectors[5].is_erased = -1;
747 bank->sectors[5].is_protected = -1;
755 bank->size = 768 * 1024;
756 bank->num_sectors = num_pages;
758 bank->sectors[6].offset = 0x80000;
759 bank->sectors[6].size = 128 * 1024;
760 bank->sectors[6].is_erased = -1;
761 bank->sectors[6].is_protected = -1;
763 bank->sectors[7].offset = 0xa0000;
764 bank->sectors[7].size = 128 * 1024;
765 bank->sectors[7].is_erased = -1;
766 bank->sectors[7].is_protected = -1;
772 bank->size = 1024 * 1024;
773 bank->num_sectors = num_pages;
775 bank->sectors[8].offset = 0xc0000;
776 bank->sectors[8].size = 128 * 1024;
777 bank->sectors[8].is_erased = -1;
778 bank->sectors[8].is_protected = -1;
780 bank->sectors[9].offset = 0xe0000;
781 bank->sectors[9].size = 128 * 1024;
782 bank->sectors[9].is_erased = -1;
783 bank->sectors[9].is_protected = -1;
805 uint32_t u32_dummy_read;
806 uint32_t u32_flash_type;
807 uint32_t u32_flash_seq_address1;
808 uint32_t u32_flash_seq_address2;
814 u32_flash_type = (uint32_t) fm3_info2->
flashtype;
817 LOG_INFO(
"*** Erasing mb9bfxxx type");
818 u32_flash_seq_address1 = 0x00001550;
819 u32_flash_seq_address2 = 0x00000AA8;
821 LOG_INFO(
"*** Erasing mb9afxxx type");
822 u32_flash_seq_address1 = 0x00000AA8;
823 u32_flash_seq_address2 = 0x00000554;
837 static const uint8_t fm3_flash_erase_chip_code[] = {
859 LOG_INFO(
"Fujitsu MB9[A/B]xxx: Chip Erase ... (may take several seconds)");
887 LOG_WARNING(
"no working area available, can't do block memory writes");
891 sizeof(fm3_flash_erase_chip_code), fm3_flash_erase_chip_code);
901 buf_set_u32(reg_params[0].value, 0, 32, u32_flash_seq_address1);
902 buf_set_u32(reg_params[1].value, 0, 32, u32_flash_seq_address2);
905 write_algorithm->
address, 0, 100000, &armv7m_info);
907 LOG_ERROR(
"Error executing flash erase programming algorithm");
950 .
name =
"chip_erase",
952 .handler = fm3_handle_chip_erase_command,
954 .help =
"Erase entire Flash device.",
963 .help =
"fm3 Flash command group",
973 .flash_bank_command = fm3_flash_bank_command,
void init_reg_param(struct reg_param *param, const char *reg_name, uint32_t size, enum param_direction direction)
void destroy_reg_param(struct reg_param *param)
#define ARMV7M_COMMON_MAGIC
Support functions to access arbitrary bits in a byte array.
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
uint64_t buffer
Pointer to data buffer to send over SPI.
uint32_t buffer_size
Size of dw_spi_program::buffer.
uint32_t address
Starting address. Sector aligned.
#define ERROR_FLASH_BANK_INVALID
#define ERROR_FLASH_OPERATION_FAILED
#define ERROR_FLASH_DST_BREAKS_ALIGNMENT
int default_flash_blank_check(struct flash_bank *bank)
Provides default erased-bank check handling.
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.
static const struct command_registration fm3_exec_command_handlers[]
static int fm3_probe(struct flash_bank *bank)
FLASH_BANK_COMMAND_HANDLER(fm3_flash_bank_command)
static int fm3_busy_wait(struct target *target, uint32_t offset, int timeout_ms)
static int fm3_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
const struct flash_driver fm3_flash
static int fm3_chip_erase(struct flash_bank *bank)
static const struct command_registration fm3_command_handlers[]
static int fm3_auto_probe(struct flash_bank *bank)
COMMAND_HANDLER(fm3_handle_chip_erase_command)
static int fm3_write_block(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
unsigned int common_magic
Provides details of a flash bank, available either on-chip or through a major interface.
Provides the implementation-independent structure that defines all of the callbacks required by OpenO...
const char * name
Gives a human-readable name of this flash driver, This field is used to select and initialize the dri...
Describes the geometry and status of a single flash sector within a flash bank.
enum fm3_flash_type flashtype
uint32_t working_area_size
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
int target_read_u8(struct target *target, target_addr_t address, uint8_t *value)
int target_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Downloads a target-specific native code algorithm to the target, and executes it.
int target_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
int target_free_working_area(struct target *target, struct working_area *area)
Free a working area.
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
#define ERROR_TARGET_NOT_HALTED
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE