30 #include "elfio/elfio.hpp" 42 avr_error(
"File '%s' not found or isn't a elf object",
45 if(reader.get_machine() != EM_AVR)
46 avr_error(
"ELF file '%s' is not for Atmel AVR architecture (%d)",
48 reader.get_machine());
51 ELFIO::Elf_Half sec_num = reader.sections.size();
53 for(ELFIO::Elf_Half i = 0; i < sec_num; i++) {
54 ELFIO::section* psec = reader.sections[i];
56 if(psec->get_type() == SHT_SYMTAB) {
57 const ELFIO::symbol_section_accessor symbols(reader, psec);
59 for(ELFIO::Elf_Xword j = 0; j < symbols.get_symbols_num(); j++) {
61 ELFIO::Elf64_Addr value = 0;
62 ELFIO::Elf_Xword size = 0;
63 unsigned char bind = 0;
64 unsigned char type = 0;
65 ELFIO::Elf_Half section_index = 0;
66 unsigned char other = 0;
69 symbols.get_symbol(j, name, value, size, bind,
70 type, section_index, other);
73 if(name.length() == 0)
77 if(section_index == SHN_ABS)
81 if((bind == STB_LOCAL) && (type != STT_NOTYPE))
84 if(value < 0x800000) {
86 std::pair<unsigned int, std::string> p(value >> 1, name);
89 }
else if(value < 0x810000) {
91 ELFIO::Elf64_Addr offset = value - 0x800000;
92 std::pair<unsigned int, std::string> p(offset, name);
95 }
else if(value < 0x820000) {
97 ELFIO::Elf64_Addr offset = value - 0x810000;
98 std::pair<unsigned int, std::string> p(offset, name);
101 }
else if(value < 0x820400) {
103 }
else if(value >= 0x830000 && value < 0x830400) {
105 }
else if(value >= 0x840000 && value < 0x840400) {
108 avr_warning(
"Unknown symbol address range found! (symbol='%s', address=0x%lx)",
117 ELFIO::Elf_Half seg_num = reader.segments.size();
119 for(ELFIO::Elf_Half i = 0; i < seg_num; i++) {
120 ELFIO::segment* pseg = reader.segments[i];
122 if(pseg->get_type() == PT_LOAD) {
123 ELFIO::Elf_Xword filesize = pseg->get_file_size();
124 ELFIO::Elf64_Addr vma = pseg->get_virtual_address();
125 ELFIO::Elf64_Addr pma = pseg->get_physical_address();
130 const unsigned char* data = (
const unsigned char*)pseg->get_data();
135 }
else if(vma >= 0x810000 && vma < 0x820000) {
137 unsigned int offset = vma - 0x810000;
140 }
else if(vma >= 0x820000 && vma < 0x820400) {
144 }
else if(vma >= 0x830000 && vma < 0x830400) {
147 avr_error(
"wrong byte size of lock bits");
148 }
else if(vma >= 0x840000 && vma < 0x840400) {
151 avr_error(
"wrong device signature size in elf file, expected=3, given=%lu",
154 unsigned int sig = (((data[2] << 8) + data[1]) << 8) + data[0];
157 avr_error(
"wrong device signature, expected=0x%x, given=0x%x",
167 unsigned int signature = std::numeric_limits<unsigned int>::max();
170 if(!reader.load(filename))
171 avr_error(
"File '%s' not found or isn't a elf object", filename);
173 if(reader.get_machine() != EM_AVR)
174 avr_error(
"ELF file '%s' is not for Atmel AVR architecture (%d)",
176 reader.get_machine());
178 ELFIO::Elf_Half seg_num = reader.segments.size();
180 for(ELFIO::Elf_Half i = 0; i < seg_num; i++) {
181 ELFIO::segment* pseg = reader.segments[i];
183 if(pseg->get_type() == PT_LOAD) {
184 ELFIO::Elf_Xword filesize = pseg->get_file_size();
185 ELFIO::Elf64_Addr vma = pseg->get_virtual_address();
190 if(vma >= 0x840000 && vma < 0x840400) {
193 avr_error(
"wrong device signature size in elf file, expected=3, given=%lu",
196 const unsigned char* data = (
const unsigned char*)pseg->get_data();
198 signature = (((data[2] << 8) + data[1]) << 8) + data[0];
Basic AVR device, contains the core functionality.
void ELFLoad(const AvrDevice *core)
void WriteMem(const unsigned char *src, unsigned int addr, unsigned int secSize)
std::string actualFilename
void AddSymbol(std::pair< unsigned int, std::string > p)
bool LoadLockBits(const unsigned char *buffer, int size)
Initialize lock bits from elf, checks proper size.
void WriteMem(const unsigned char *, unsigned int offset, unsigned int size)
Data * data
a hack for symbol look-up
unsigned int ELFGetSignature(const char *filename)
unsigned int devSignature
hold the device signature for this core
bool LoadFuses(const unsigned char *buffer, int size)
Initialize fuses from elf, checks proper size.