avr_eeprom_desc_t d = { .ee = firmware->eeprom, .offset = 0, .size = firmware->eesize };
avr_ioctl(avr, AVR_IOCTL_EEPROM_SET, &d);
}
+ if (firmware->fuse)
+ memcpy(avr->fuse, firmware->fuse, firmware->fusesize);
+ if (firmware->lockbits)
+ avr->lockbits = firmware->lockbits[0];
// load the default pull up/down values for ports
for (int i = 0; i < 8; i++)
if (firmware->external_state[i].port == 0)
}
}
+static int
+elf_copy_section(
+ const char *name,
+ Elf_Data *data,
+ uint8_t **dest)
+{
+ *dest = malloc(data->d_size);
+ if (!*dest)
+ return -1;
+
+ memcpy(*dest, data->d_buf, data->d_size);
+ AVR_LOG(NULL, LOG_TRACE, "Loaded %zu .%s\n", name, data->d_size);
+
+ return 0;
+}
+
+
int elf_read_firmware(const char * file, elf_firmware_t * firmware)
{
Elf32_Ehdr elf_header; /* ELF header */
Elf_Data *data_data = NULL,
*data_text = NULL,
*data_ee = NULL; /* Data Descriptor */
+ Elf_Data *data_fuse = NULL;
+ Elf_Data *data_lockbits = NULL;
memset(firmware, 0, sizeof(*firmware));
#if ELF_SYMBOLS
data_data = elf_getdata(scn, NULL);
else if (!strcmp(name, ".eeprom"))
data_ee = elf_getdata(scn, NULL);
+ else if (!strcmp(name, ".fuse"))
+ data_fuse = elf_getdata(scn, NULL);
+ else if (!strcmp(name, ".lock"))
+ data_lockbits = elf_getdata(scn, NULL);
else if (!strcmp(name, ".bss")) {
Elf_Data *s = elf_getdata(scn, NULL);
firmware->bsssize = s->d_size;
AVR_LOG(NULL, LOG_TRACE, "Loaded %u .eeprom\n", (unsigned int)data_ee->d_size);
firmware->eesize = data_ee->d_size;
}
+ if (data_fuse) {
+ elf_copy_section(".fuse", data_fuse, &firmware->fuse);
+ firmware->fusesize = data_fuse->d_size;
+ }
+ if (data_lockbits)
+ elf_copy_section(".lock", data_fuse, &firmware->lockbits);
+
// hdump("flash", avr->flash, offset);
elf_end(elf);
close(fd);