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");
342 uint32_t buffer_size = 2048;
349 uint32_t u32_flash_type;
350 uint32_t u32_flash_seq_address1;
351 uint32_t u32_flash_seq_address2;
357 u32_flash_type = (uint32_t) fm3_info->
flashtype;
360 u32_flash_seq_address1 = 0x00001550;
361 u32_flash_seq_address2 = 0x00000AA8;
363 u32_flash_seq_address1 = 0x00000AA8;
364 u32_flash_seq_address2 = 0x00000554;
378 static const uint8_t fm3_flash_write_code[] = {
380 0x5F, 0xF0, 0x80, 0x45,
382 0x4F, 0xF6, 0xFD, 0x76,
384 0x5F, 0xF0, 0x80, 0x46,
387 0x5F, 0xF0, 0x80, 0x45,
389 0x55, 0xF0, 0x01, 0x05,
390 0x5F, 0xF0, 0x80, 0x46,
394 0x5F, 0xF0, 0x80, 0x46,
443 0x15, 0xF0, 0x80, 0x05,
445 0x16, 0xF0, 0x80, 0x06,
471 0x5F, 0xF0, 0x80, 0x45,
473 0x4F, 0xF6, 0xFE, 0x76,
475 0x5F, 0xF0, 0x80, 0x46,
478 0x5F, 0xF0, 0x80, 0x45,
480 0x55, 0xF0, 0x02, 0x05,
481 0x5F, 0xF0, 0x80, 0x46,
485 0x5F, 0xF0, 0x80, 0x46,
490 0xDF, 0xF8, 0x08, 0x50,
499 0x00, 0x00, 0x00, 0x20,
500 0x04, 0x00, 0x00, 0x20
503 LOG_INFO(
"Fujitsu MB9[A/B]FXXX: FLASH Write ...");
529 LOG_WARNING(
"no working area available, can't do block memory writes");
534 sizeof(fm3_flash_write_code), fm3_flash_write_code);
541 +
sizeof(fm3_flash_write_code) - 8, (write_algorithm->
address));
546 +
sizeof(fm3_flash_write_code) - 4, (write_algorithm->
address) + 4);
555 if (buffer_size <= 256) {
559 LOG_WARNING(
"No large enough working area available, can't do block memory writes");
577 uint32_t thisrun_count = (
count > (buffer_size / 2)) ? (buffer_size / 2) :
count;
585 buf_set_u32(reg_params[2].value, 0, 32, thisrun_count);
586 buf_set_u32(reg_params[3].value, 0, 32, u32_flash_seq_address1);
587 buf_set_u32(reg_params[4].value, 0, 32, u32_flash_seq_address2);
590 (write_algorithm->
address + 8), 0, 1000, &armv7m_info);
592 LOG_ERROR(
"Error executing fm3 Flash programming algorithm");
598 LOG_ERROR(
"Fujitsu MB9[A/B]FXXX: Flash programming ERROR (Timeout) -> Reg R3: %" PRIx32,
604 buffer += thisrun_count * 2;
605 address += thisrun_count * 2;
606 count -= thisrun_count;
651 bank->base = 0x00000000;
652 bank->size = 32 * 1024;
654 bank->sectors[0].offset = 0;
655 bank->sectors[0].size = 16 * 1024;
656 bank->sectors[0].is_erased = -1;
657 bank->sectors[0].is_protected = -1;
659 bank->sectors[1].offset = 0x4000;
660 bank->sectors[1].size = 16 * 1024;
661 bank->sectors[1].is_erased = -1;
662 bank->sectors[1].is_protected = -1;
667 bank->size = 64 * 1024;
668 bank->num_sectors = num_pages;
670 bank->sectors[2].offset = 0x8000;
671 bank->sectors[2].size = 32 * 1024;
672 bank->sectors[2].is_erased = -1;
673 bank->sectors[2].is_protected = -1;
689 bank->size = 128 * 1024;
690 bank->num_sectors = num_pages;
692 bank->sectors[2].offset = 0x8000;
693 bank->sectors[2].size = 96 * 1024;
694 bank->sectors[2].is_erased = -1;
695 bank->sectors[2].is_protected = -1;
709 bank->size = 256 * 1024;
710 bank->num_sectors = num_pages;
712 bank->sectors[3].offset = 0x20000;
713 bank->sectors[3].size = 128 * 1024;
714 bank->sectors[3].is_erased = -1;
715 bank->sectors[3].is_protected = -1;
727 bank->size = 384 * 1024;
728 bank->num_sectors = num_pages;
730 bank->sectors[4].offset = 0x40000;
731 bank->sectors[4].size = 128 * 1024;
732 bank->sectors[4].is_erased = -1;
733 bank->sectors[4].is_protected = -1;
743 bank->size = 512 * 1024;
744 bank->num_sectors = num_pages;
746 bank->sectors[5].offset = 0x60000;
747 bank->sectors[5].size = 128 * 1024;
748 bank->sectors[5].is_erased = -1;
749 bank->sectors[5].is_protected = -1;
757 bank->size = 768 * 1024;
758 bank->num_sectors = num_pages;
760 bank->sectors[6].offset = 0x80000;
761 bank->sectors[6].size = 128 * 1024;
762 bank->sectors[6].is_erased = -1;
763 bank->sectors[6].is_protected = -1;
765 bank->sectors[7].offset = 0xa0000;
766 bank->sectors[7].size = 128 * 1024;
767 bank->sectors[7].is_erased = -1;
768 bank->sectors[7].is_protected = -1;
774 bank->size = 1024 * 1024;
775 bank->num_sectors = num_pages;
777 bank->sectors[8].offset = 0xc0000;
778 bank->sectors[8].size = 128 * 1024;
779 bank->sectors[8].is_erased = -1;
780 bank->sectors[8].is_protected = -1;
782 bank->sectors[9].offset = 0xe0000;
783 bank->sectors[9].size = 128 * 1024;
784 bank->sectors[9].is_erased = -1;
785 bank->sectors[9].is_protected = -1;
807 uint32_t u32_dummy_read;
808 uint32_t u32_flash_type;
809 uint32_t u32_flash_seq_address1;
810 uint32_t u32_flash_seq_address2;
816 u32_flash_type = (uint32_t) fm3_info2->
flashtype;
819 LOG_INFO(
"*** Erasing mb9bfxxx type");
820 u32_flash_seq_address1 = 0x00001550;
821 u32_flash_seq_address2 = 0x00000AA8;
823 LOG_INFO(
"*** Erasing mb9afxxx type");
824 u32_flash_seq_address1 = 0x00000AA8;
825 u32_flash_seq_address2 = 0x00000554;
839 static const uint8_t fm3_flash_erase_chip_code[] = {
861 LOG_INFO(
"Fujitsu MB9[A/B]xxx: Chip Erase ... (may take several seconds)");
889 LOG_WARNING(
"no working area available, can't do block memory writes");
893 sizeof(fm3_flash_erase_chip_code), fm3_flash_erase_chip_code);
903 buf_set_u32(reg_params[0].value, 0, 32, u32_flash_seq_address1);
904 buf_set_u32(reg_params[1].value, 0, 32, u32_flash_seq_address2);
907 write_algorithm->
address, 0, 100000, &armv7m_info);
909 LOG_ERROR(
"Error executing flash erase programming algorithm");
954 .
name =
"chip_erase",
956 .handler = fm3_handle_chip_erase_command,
958 .help =
"Erase entire Flash device.",
967 .help =
"fm3 Flash command group",
977 .flash_bank_command = fm3_flash_bank_command,
void init_reg_param(struct reg_param *param, 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 first, unsigned 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 first, unsigned 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.
#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_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_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, int timeout_ms, void *arch_info)
Downloads a target-specific native code algorithm to the target, and executes it.
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