Disassemble XMEGA HEX into NOT DISASSEMBLY but ASSEMBLY

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a bootloader built in my XMEGA and I have no source for it. There's a source I found already, but it's not the exact one which communicates with the PC side bootloader.

I need to disassemble a HEX file into XMEGA ASM, not listing. Does that option exist?

I need it to debug and trace what the HEX file is doing so that I can make my own PC bootloader because the one I already have is so horribly programmed that every single time a byte is sent, the whole GUI gets refreshed, causing the upload to be ultra slow. It's so frustrating!

I did avr-objdump.exe, but that didn't turn into assembly, but just listing.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can probably find a disassembler that produces "assembler ready" code rather than a listing, but IMO it's easier to use avr-objdump and manually edit the "listing."

 

If you're trying to analyze the PC-side bootloader behavior, I'd think you would be better off with a listing-style disassembly, anyway?

 

You should be able to use a debugger on the bootloader without having source code.  Though IIRC it can be a bit of a pain in the neck.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I believe objdump has options to change the format of disasm listing anyway.

 

In the past I have used "disavr" and that does produce code that can be fed straight to a disassembler but I think (well like objdump too) it has no way to identify data/code regions (well not form hex anyway) so data may be shown as illegal opcodes.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried removing the invalid syntaxes, but when I have something like

rjmp .-55 ; 0x2004D

then I did this

rjmp 0x004D

and it told me it's out of range.

I also tried messing with .org's because there were warnings that they were outside of the code segment blah blah...

I think that when I used disavr, I got weird code. It wasn't at 0x20000. Probably because disavr was made for ATMEGAs and not ATXMEGAs.
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

then I did this

Which suggests you don't know what RJMP is or how it works. It can only be used for jumps with a +/- range of 2K words (4K bytes) in either direction. If the target is beyond that you will get "out of range". Clearly if some code is located at 0x200xx and you try to jump to 0x004D that is (possibly) a huge distance away. The only way it might be in range is if the 0x200xx address is very near the end of the flash. In this case the address on that micro may wrap so a small jump forward "off the end of flash" may wrap back round to near 0x0000.

 

BTW what is preventing you getting access to the source of this bootloader? It would be infinitely easier to work with the source. Is this one of those "the dog ate my homework" things?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think I read a post somewhere by OP that it's a bootloader from Microelectronica. There's only a .hex file for the bootloader in their download .zip.

So it seems they want to keep the source for themselves. But maybe they're interested in bug reports or enhancement requests.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I found the source, but I didn't believe it was right because the PC-side bootloader says "Uploading" and then stops the terminal activity and says "Finishing". I believed that the "Finishing" part is something like CRC or checking bytes, idk. Some feedback.

 

In the end, I realized that the bootloader says "Uploading" while there's something to load from the HEX file and when it's finished, it says "Finishing", finishing off the rest of the flash memory with zeros (or F's, idk). MCU is just asking for more and more bytes.

 

First, MCU says "gggggg"... until PC says "r". Then MCU and PC set their counters(let's call it 'i') on 0. After that, MCU says "y", PC says the low byte of the i-th word of the flash binary, then MCU says "x", PC says the high byte of the i-th word of the flash binary and so on until the end of Application Section is reached.