From a708b6d25ec72c6de57ff42bdc6c0b4d52a69388 Mon Sep 17 00:00:00 2001 From: Lars Poeschel Date: Tue, 5 Nov 2019 16:37:43 +0100 Subject: [PATCH] avrf.c: Use extended addressing for flash > 0x20000 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The current method used for flash addressing uses 16 bit. Every access to flash is 16 bit wide. With 16 address bits one can address 0x10000 unique locations á 16 bits thats 0x20000 bytes. For flashes bigger than that avrs have an extended addressing with more than 16 address bits. This is now implemented and used for flashs larger than 0x20000 bytes. Change-Id: Id8b6337dde3830fb3c56b9042872e040bb67c12d Signed-off-by: Lars Pöschel Reviewed-on: http://openocd.zylin.com/5502 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/flash/nor/avrf.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/flash/nor/avrf.c b/src/flash/nor/avrf.c index 178567e6b4..aa86459090 100644 --- a/src/flash/nor/avrf.c +++ b/src/flash/nor/avrf.c @@ -142,6 +142,7 @@ static int avr_jtagprg_chiperase(struct avr_common *avr) } static int avr_jtagprg_writeflashpage(struct avr_common *avr, + const bool ext_addressing, const uint8_t *page_buf, uint32_t buf_size, uint32_t addr, @@ -152,6 +153,13 @@ static int avr_jtagprg_writeflashpage(struct avr_common *avr, avr_jtag_sendinstr(avr->jtag_info.tap, NULL, AVR_JTAG_INS_PROG_COMMANDS); avr_jtag_senddat(avr->jtag_info.tap, NULL, 0x2310, AVR_JTAG_REG_ProgrammingCommand_Len); + /* load extended high byte */ + if (ext_addressing) + avr_jtag_senddat(avr->jtag_info.tap, + NULL, + 0x0b00 | ((addr >> 17) & 0xFF), + AVR_JTAG_REG_ProgrammingCommand_Len); + /* load addr high byte */ avr_jtag_senddat(avr->jtag_info.tap, NULL, @@ -238,6 +246,7 @@ static int avrf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t o struct target *target = bank->target; struct avr_common *avr = target->arch_info; uint32_t cur_size, cur_buffer_size, page_size; + bool ext_addressing; if (bank->target->state != TARGET_HALTED) { LOG_ERROR("Target not halted"); @@ -258,6 +267,11 @@ static int avrf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t o if (ERROR_OK != avr_jtagprg_enterprogmode(avr)) return ERROR_FAIL; + if (bank->size > 0x20000) + ext_addressing = true; + else + ext_addressing = false; + cur_size = 0; while (count > 0) { if (count > page_size) @@ -265,6 +279,7 @@ static int avrf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t o else cur_buffer_size = count; avr_jtagprg_writeflashpage(avr, + ext_addressing, buffer + cur_size, cur_buffer_size, offset + cur_size, -- 2.30.2