Repository navigation
sim: boot section and reset vector from the fuses and IVSEL - #604
Conversation
|
I see nothing that sets avr->reset_pcm so it would seem to do nothing. Setting it should depend on the fuses, at least for Mega328 and 32U4. It looks possible to set the fuses in the firmware, but I never saw it used. |
19405fd to
c16b237
Compare
3022be5 to
be16f5c
Compare
be16f5c to
3d167d2
Compare
|
@gatk555 Sorry, I forgot to pull the relevant changes in from my usbip branch, I've now folded in those changes. This PR has now grown somewhat into sourcing the default boot address of the AVR from the fuse bits rather than relying on the machine implementation to define the boot address directly. IVSEL then allows deriving the interrupt vector table from the boot sector or the start of flash. |
c2b6446 to
0678c6c
Compare
|
Looks good, but two quibbles: sim_avr.c: sim_elf.c: Thanks, G. |
7ad8eb8 to
da0ddfb
Compare
Bootloaders that use interrupts set IVSEL to move the vectors to the boot section. simavr always used the vectors at 0. - Each mega core gives its smallest boot section (BOOTSZ = 11) and the fuse byte that holds BOOTRST and BOOTSZ. The values come from the datasheets. - avr_update_reset_vector() computes boot_start from BOOTSZ. When BOOTRST is programmed it also sets reset_pc and the PC to boot_start. Otherwise reset_pc is left as the caller set it. - avr_reset() calls it and so does avr_load_firmware() when the firmware carries fuses. - Interrupts vector to boot_start while IVSEL is set. - _BV is now the real macro. The identity _BV made every default fuse value wrong. - The watchdog no longer hooks the missing vector of the ATmega8/16/32. A second reset crashed these parts. - board_simduino sets the board BOOTRST and BOOTSZ bits instead of the PC. Its ATmega2560 detection now triggers. test_boot_section checks 26 parts against the datasheet tables and that a reset keeps reset_pc when BOOTRST is unprogrammed. test_atmega328p_ivsel runs a bootloader and an application that each take an interrupt through their own vectors. AVR_LDFLAGS gives per-firmware link flags.
da0ddfb to
4db7c91
Compare
|
@gatk555 Thanks for taking another look! I've addressed both. The fuse bits are now plain bit numbers as avr-libc has them with a mask for BOOTSZ next to them. The boot section size is now a couple of named steps that read the BOOTSZ field with the shift you suggested. I realized a second full reset was heavier than it needed to be. I replaced it with a small helper utility |
Bootloaders that use interrupts (Caterina, LUFA CDC/DFU, ...) set MCUCR.IVSEL (GICR.IVSEL on the older megas) to move the vector table to the start of the boot section, and clear it before starting the application. simavr always used the vectors at 0, so such a bootloader ended up in the application's handlers.
The bit is declared by DEFAULT_CORE for every core whose avr-libc header defines IVSEL. While it is set, vectors are taken relative to reset_pc, which is where a bootloader is started from (BOOTRST). The IVCE timed sequence is not modeled.