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},
128 LOG_DEBUG(
"poll_value = 0x%04" PRIx32
"", poll_value);
129 }
while (!(poll_value & 0x0200));
135 const bool ext_addressing,
136 const uint8_t *page_buf,
150 0x0b00 | ((
addr >> 17) & 0xFF),
156 0x0700 | ((
addr >> 9) & 0xFF),
162 0x0300 | ((
addr >> 1) & 0xFF),
167 for (uint32_t i = 0; i < page_size; i++) {
189 LOG_DEBUG(
"poll_value = 0x%04" PRIx32
"", poll_value);
190 }
while (!(poll_value & 0x0200));
239 uint32_t cur_size, cur_buffer_size, page_size;
247 page_size =
bank->sectors[0].size;
248 if ((
offset % page_size) != 0) {
249 LOG_WARNING(
"offset 0x%" PRIx32
" breaks required %" PRIu32
"-byte alignment",
261 if (
bank->size > 0x20000)
262 ext_addressing =
true;
264 ext_addressing =
false;
268 if (
count > page_size)
269 cur_buffer_size = page_size;
271 cur_buffer_size =
count;
278 count -= cur_buffer_size;
279 cur_size += cur_buffer_size;
287 #define EXTRACT_MFG(X) (((X) & 0xffe) >> 1)
288 #define EXTRACT_PART(X) (((X) & 0xffff000) >> 12)
289 #define EXTRACT_VER(X) (((X) & 0xf0000000) >> 28)
310 LOG_INFO(
"device id = 0x%08" PRIx32
"", device_id);
312 LOG_ERROR(
"0x%" PRIx32
" is invalid Manufacturer for avr, 0x%X is expected",
328 bank->base = 0x00000000;
336 bank->sectors[i].is_erased = -1;
337 bank->sectors[i].is_protected = -1;
375 LOG_INFO(
"device id = 0x%08" PRIx32
"", device_id);
377 LOG_ERROR(
"0x%" PRIx32
" is invalid Manufacturer for avr, 0x%X is expected",
441 .
name =
"mass_erase",
443 .handler = avrf_handle_mass_erase_command,
445 .help =
"erase entire device",
453 .help =
"AVR flash command group",
463 .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 ...)
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.