ghidra
ghidra copied to clipboard
Need to set language for specific AVR8 chips to get proper interrupt vector tables and peripheral sets
I am fairly new to Ghidra so apologies if I am missing something obvious.
Describe the bug I have a "FLASH.BIN" file for an Atmel ATmega128 that I have imported into a new project but I am unable to analyze the file for this specific processor. Ghidra supports only a few generic AVR types that are unsuitable for my purpose (different vector tables, presumably different peripherals).
To Reproduce Steps to reproduce the behavior:
- Create a new project
- Select "Import File..." to import a 128K image file (or pretty much anything at this point. It won't matter to illustrate the problem)
- Ghidra will show the "Raw Binary" format. Fine. Click the three dots button to the right of the Language field.
- Only a few generic AVR8 options are provided. Neither the "AVR8 atmega256" not the "AVR8 default" options for the gcc compiler will have the appropriate interrupt vector table for the ATmega128. Presumably there are various peripheral fetaures that are different as well from those available but I haven't gotten that far yet.
Expected behavior I should be able to pick a variant specific to the ATmega128 to get the appropriate interrupt vector table and peripheral set for my target processor, an Atmega 128L
Attachments Processor Datasheet: http://ww1.microchip.com/downloads/en/devicedoc/doc2467.pdf
Table 23 shows the interrupt vector table.
Environment (please complete the following information):
- OS: Arch Linux
- Java Version: 20.0.1
- Ghidra Version: 10.2.3
- Ghidra Origin: packages.archlinux.org
Additional context I was able to edit the /opt/ghidra/Ghidra/Processors/Atmel/ghidra_scripts/CreateAVR8GDTArchiveScript.java mentioned in https://github.com/NationalSecurityAgency/ghidra/issues/2689 to successfully create a new avr8.gdt file that I was able to successfully import into the project, but that doesn't get me the pspec files that I presume Ghidra needs to do what I'm after
Would I need to write my own pspec file if I want specific support for this processor, and would that be accepted in a pull request if I did? It seems that support for other Atmega processors like the 1284p (pull request in https://github.com/NationalSecurityAgency/ghidra/pull/3324) is blocked and doesn't appear in 10.2.3 that I can find.
I am quite new to Ghidra so apologies if I am missing something obvious.
For this type of microcontroller with basically an unbound number of variants, I think there may be some resistance to adding all possible types and permutations. Note @emteere's comment in #3324 :
we're considering adding the variants into a data type archive for the processor. This would possibly include bit-field definitions for the registers.
Until there is progress on that, I think your immediate solutions are either:
- maintain local patches and pspec files for your devices;
- make some scripts that are manually run to define vectors etc. This may not work for bit-mapped SFRs however (since those need lower-level support, i.e. pspec), but is satisfactory for vectors and memory maps. I have used this method, for some SH70xx mcus that luckily have simple memory-mapped IO : https://github.com/fenugrec/nissutils/blob/master/ghidra_helpers/nissan_load.py
Thanks for the feedback. Unfortunately it looks like emteere's comment was back in August 2021. I don't suppose there is any update on these considerations?
Appreciate the pointer to the python script. I'll check it out.
Hello, I have the similar issue with atmega168pa. atmega256 seems to be close enough for what I am doing right now, but hopefully something more precise can be added. I would be willing to work on it