-#define AO_USB_DESC_STRING 3
-
-struct sym {
- unsigned addr;
- char *name;
- int required;
-} ao_symbols[] = {
-
- { 0, "ao_romconfig_version", 1 },
-#define AO_ROMCONFIG_VERSION (ao_symbols[0].addr)
-
- { 0, "ao_romconfig_check", 1 },
-#define AO_ROMCONFIG_CHECK (ao_symbols[1].addr)
-
- { 0, "ao_serial_number", 1 },
-#define AO_SERIAL_NUMBER (ao_symbols[2].addr)
-
- { 0, "ao_usb_descriptors", 0 },
-#define AO_USB_DESCRIPTORS (ao_symbols[3].addr)
-
- { 0, "ao_radio_cal", 0 },
-#define AO_RADIO_CAL (ao_symbols[4].addr)
-};
-
-#define NUM_SYMBOLS 5
-#define NUM_REQUIRED_SYMBOLS 3
-
-/*
- * Look through the Elf file for the AltOS symbols
- * that can be adjusted before the image is written
- * to the device
- */
-static int
-find_symbols (Elf *e)
-{
- Elf_Scn *scn;
- Elf_Data *symbol_data = NULL;
- GElf_Shdr shdr;
- GElf_Sym sym;
- int i, symbol_count, s;
- int required = 0;
- char *symbol_name;
-
- /*
- * Find the symbols
- */
-
- scn = NULL;
- while ((scn = elf_nextscn(e, scn)) != NULL) {
- if (gelf_getshdr(scn, &shdr) != &shdr)
- return 0;
-
- if (shdr.sh_type == SHT_SYMTAB) {
- symbol_data = elf_getdata(scn, NULL);
- symbol_count = shdr.sh_size / shdr.sh_entsize;
- break;
- }
- }
-
- if (!symbol_data)
- return 0;
-
- for (i = 0; i < symbol_count; i++) {
- gelf_getsym(symbol_data, i, &sym);
-
- symbol_name = elf_strptr(e, shdr.sh_link, sym.st_name);
-
- for (s = 0; s < NUM_SYMBOLS; s++)
- if (!strcmp (ao_symbols[s].name, symbol_name)) {
- int t;
- ao_symbols[s].addr = sym.st_value;
- if (ao_symbols[s].required)
- ++required;
- }
- }
-
- return required >= NUM_REQUIRED_SYMBOLS;
-}
-
-struct load {
- uint32_t addr;
- uint32_t len;
- uint8_t buf[0];
-};
-
-uint32_t round4(uint32_t a) {
- return (a + 3) & ~3;
-}
-
-struct load *
-new_load (uint32_t addr, uint32_t len)
-{
- struct load *new;
-
- len = round4(len);
- new = calloc (1, sizeof (struct load) + len);
- if (!new)
- abort();
-
- new->addr = addr;
- new->len = len;
- return new;
-}
-
-void
-load_paste(struct load *into, struct load *from)
-{
- if (from->addr < into->addr || into->addr + into->len < from->addr + from->len)
- abort();
-
- memcpy(into->buf + from->addr - into->addr, from->buf, from->len);
-}