16 #define AVR_JTAG_INS_LEN 4
18 #define AVR_JTAG_INS_EXTEST 0x00
19 #define AVR_JTAG_INS_IDCODE 0x01
20 #define AVR_JTAG_INS_SAMPLE_PRELOAD 0x02
21 #define AVR_JTAG_INS_BYPASS 0x0F
23 #define AVR_JTAG_INS_AVR_RESET 0x0C
24 #define AVR_JTAG_INS_PROG_ENABLE 0x04
25 #define AVR_JTAG_INS_PROG_COMMANDS 0x05
26 #define AVR_JTAG_INS_PROG_PAGELOAD 0x06
27 #define AVR_JTAG_INS_PROG_PAGEREAD 0x07
30 #define AVR_JTAG_REG_BYPASS_LEN 1
31 #define AVR_JTAG_REG_DEVICEID_LEN 32
33 #define AVR_JTAG_REG_RESET_LEN 1
34 #define AVR_JTAG_REG_JTAGID_LEN 32
35 #define AVR_JTAG_REG_PROGRAMMING_ENABLE_LEN 16
36 #define AVR_JTAG_REG_PROGRAMMING_COMMAND_LEN 15
37 #define AVR_JTAG_REG_FLASH_DATA_BYTE_LEN 16
57 {
"atmega128", 0x9702, 256, 512, 8, 512},
58 {
"atmega128rfa1", 0xa701, 128, 512, 8, 512},
59 {
"atmega256rfr2", 0xa802, 256, 1024, 8, 1024},
60 {
"at90can128", 0x9781, 256, 512, 8, 512},
61 {
"at90usb128", 0x9782, 256, 512, 8, 512},
62 {
"atmega164p", 0x940a, 128, 128, 4, 128},
63 {
"atmega324p", 0x9508, 128, 256, 4, 256},
64 {
"atmega324pa", 0x9511, 128, 256, 4, 256},
65 {
"atmega644p", 0x960a, 256, 256, 8, 256},
66 {
"atmega1284p", 0x9705, 256, 512, 8, 512},
67 {
"atmega32u4", 0x9587, 128, 256, 4, 256},
129 LOG_DEBUG(
"poll_value = 0x%04" PRIx32
"", poll_value);
130 }
while (!(poll_value & 0x0200));
136 const bool ext_addressing,
137 const uint8_t *page_buf,
151 0x0b00 | ((
addr >> 17) & 0xFF),
157 0x0700 | ((
addr >> 9) & 0xFF),
163 0x0300 | ((
addr >> 1) & 0xFF),
168 for (uint32_t i = 0; i < page_size; i++) {
190 LOG_DEBUG(
"poll_value = 0x%04" PRIx32
"", poll_value);
191 }
while (!(poll_value & 0x0200));
240 uint32_t cur_size, cur_buffer_size, page_size;
248 page_size =
bank->sectors[0].size;
249 if ((
offset % page_size) != 0) {
250 LOG_WARNING(
"offset 0x%" PRIx32
" breaks required %" PRIu32
"-byte alignment",
262 if (
bank->size > 0x20000)
263 ext_addressing =
true;
265 ext_addressing =
false;
269 if (
count > page_size)
270 cur_buffer_size = page_size;
272 cur_buffer_size =
count;
279 count -= cur_buffer_size;
280 cur_size += cur_buffer_size;
288 #define EXTRACT_MFG(X) (((X) & 0xffe) >> 1)
289 #define EXTRACT_PART(X) (((X) & 0xffff000) >> 12)
290 #define EXTRACT_VER(X) (((X) & 0xf0000000) >> 28)
311 LOG_INFO(
"device id = 0x%08" PRIx32
"", device_id);
313 LOG_ERROR(
"0x%" PRIx32
" is invalid Manufacturer for avr, 0x%X is expected",
329 bank->base = 0x00000000;
337 bank->sectors[i].is_erased = -1;
338 bank->sectors[i].is_protected = -1;
376 LOG_INFO(
"device id = 0x%08" PRIx32
"", device_id);
378 LOG_ERROR(
"0x%" PRIx32
" is invalid Manufacturer for avr, 0x%X is expected",
442 .
name =
"mass_erase",
444 .handler = avrf_handle_mass_erase_command,
446 .help =
"erase entire device",
454 .help =
"AVR flash command group",
464 .flash_bank_command = avrf_flash_bank_command,
#define AVR_JTAG_REG_JTAGID_LEN
static int avr_jtagprg_chiperase(struct avr_common *avr)
#define AVR_JTAG_INS_AVR_RESET
static int avrf_mass_erase(struct flash_bank *bank)
static int avrf_auto_probe(struct flash_bank *bank)
#define AVR_JTAG_INS_IDCODE
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, uint32_t page_size)
static const struct avrf_type avft_chips_info[]
#define AVR_JTAG_REG_PROGRAMMING_ENABLE_LEN
FLASH_BANK_COMMAND_HANDLER(avrf_flash_bank_command)
COMMAND_HANDLER(avrf_handle_mass_erase_command)
static int avrf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
const struct flash_driver avr_flash
static int avr_jtag_reset(struct avr_common *avr, uint32_t reset)
static int avr_jtag_read_jtagid(struct avr_common *avr, uint32_t *id)
static const struct command_registration avrf_command_handlers[]
static int avrf_info(struct flash_bank *bank, struct command_invocation *cmd)
#define AVR_JTAG_INS_PROG_PAGELOAD
static int avrf_probe(struct flash_bank *bank)
#define AVR_JTAG_INS_PROG_COMMANDS
#define AVR_JTAG_REG_PROGRAMMING_COMMAND_LEN
static const struct command_registration avrf_exec_command_handlers[]
static int avr_jtagprg_enterprogmode(struct avr_common *avr)
static int avr_jtagprg_leaveprogmode(struct avr_common *avr)
#define AVR_JTAG_INS_PROG_ENABLE
static int avrf_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
#define AVR_JTAG_REG_RESET_LEN
int avr_jtag_senddat(struct jtag_tap *tap, uint32_t *dr_in, uint32_t dr_out, int len)
int avr_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
int mcu_execute_queue(void)
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
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 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_OPERATION_FAILED
#define ERROR_FLASH_DST_BREAKS_ALIGNMENT
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.
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
target_addr_t addr
Start address to search for the control block.
struct mcu_jtag jtag_info
When run_command is called, a new instance will be created on the stack, filled with the proper value...
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.
#define ERROR_TARGET_NOT_HALTED
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.