- * 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;
- char *section_name;
- size_t shstrndx;
-
- if (elf_getshdrstrndx(e, &shstrndx) < 0)
- return 0;
-
- /*
- * Find the symbols
- */
-
- scn = NULL;
- while ((scn = elf_nextscn(e, scn)) != NULL) {
-
- if (gelf_getshdr(scn, &shdr) != &shdr)
- return 0;
-
-#if 0
- section_name = elf_strptr(e, shstrndx, shdr.sh_name);
-
- printf ("name %s\n", section_name);
-
- if (shdr.sh_type == SHT_PROGBITS)
- {
- printf ("\ttype %lx\n", shdr.sh_type);
- printf ("\tflags %lx\n", shdr.sh_flags);
- printf ("\taddr %lx\n", shdr.sh_addr);
- printf ("\toffset %lx\n", shdr.sh_offset);
- printf ("\tsize %lx\n", shdr.sh_size);
- printf ("\tlink %lx\n", shdr.sh_link);
- printf ("\tinfo %lx\n", shdr.sh_info);
- printf ("\taddralign %lx\n", shdr.sh_addralign);
- printf ("\tentsize %lx\n", shdr.sh_entsize);
- }
-#endif
-
- 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);
-}
-
-/*
- * Make a new load structure large enough to hold the old one and
- * the new data