0

I tried to disas atmega328p elf files like this.

 avr-objdump -d -Maddr16,data16 target/avr-atmega328p/release/sample.elf                                                                                            (git)-[serial_echo_interrupt]

target/avr-atmega328p/release/sample.elf:     file format elf32-avr


Disassembly of section .text:

00000000 <__vectors>:
   0:   0c 94 34 00     jmp     0x68    ; 0x68 <__ctors_end>
   4:   0c 94 51 00     jmp     0xa2    ; 0xa2 <__bad_interrupt>
   8:   0c 94 51 00     jmp     0xa2    ; 0xa2 <__bad_interrupt>
   c:   0c 94 51 00     jmp     0xa2    ; 0xa2 <__bad_interrupt>
  10:   0c 94 51 00     jmp     0xa2    ; 0xa2 <__bad_interrupt>

but the program address is mismatch because the flash width is 16 bit.

Do you know how to set 16-bit flash width?

Kyuvie
  • 23
  • 5

2 Answers2

0

This command works for disassembling an ELF or HEX file compiled for the ATmega328P:

avr-objdump -D -m avr5 FILENAME

The trickiest part of this command is the avr5 argument, which specifies the architecture of the chip. If you are using a chip other than the ATmega328P, you can get a hint about what architecture to specify by looking at this file in the GCC source code and finding the line that defines your chip:

https://github.com/gcc-mirror/gcc/blob/releases%2Fgcc-10.2.0/gcc/config/avr/avr-mcus.def

David Grayson
  • 84,103
  • 24
  • 152
  • 189
0

the program address is mismatch because the flash width is 16 bit.

Do you know how to set 16-bit flash width?

GNU tools are using byte addresses, and there is no way to change that. This applies to:

  • Addresses displayed with tools like objdump, readelf, nm, etc.

  • Addresses used in the linker description file.

  • Addresses displayed in the map file as of avr-gcc -Wl,-Map,source.map source.c ...

  • Addresses used by the compiler, e.g when you take the address of an object in SRAM (in .data, .bss) or in flash (.progmem).

  • Addresses in options like -Ttext=0x1234 to specify the start of the text section.

The only exception is when you are taking the address of a function in C/C++ which will be a word-address suitable for an indirect call via icall.

As an aside, specifying an emulation like with objdump -m avr5 as proposed in the other answer won't change this in any way. You are disassembling an ELF file which knows the emulation anyways (as opposed to Intel HEX format which is agnostic).

emacs drives me nuts
  • 2,785
  • 13
  • 23