From 3a96085b999220c4da0c5ef7d1f7ba26b9ddfb98 Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Sun, 31 Dec 2017 18:47:16 +0100 Subject: dec-multia: make netboot possible, add aboot bootloader --- package/aboot/src/tools/elfencap.c | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 package/aboot/src/tools/elfencap.c (limited to 'package/aboot/src/tools/elfencap.c') diff --git a/package/aboot/src/tools/elfencap.c b/package/aboot/src/tools/elfencap.c new file mode 100644 index 000000000..3e5f4b4b9 --- /dev/null +++ b/package/aboot/src/tools/elfencap.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include + +#include + +#include + + +int +main (int argc, char ** argv) +{ + int ifd; + ssize_t n; + char buf[8192]; + struct stat st; + struct { + struct elf64_hdr ehdr; + struct elf64_phdr phdr; + } h; + + ifd = open(argv[1], O_RDONLY); + if (ifd < 0) { + perror(argv[1]); + return 1; + } + + if (fstat(ifd, &st) < 0) { + perror(argv[1]); + return 1; + } + + memset(&h, 0, sizeof(h)); + + h.ehdr.e_ident[0] = 0x7f; + strcpy(h.ehdr.e_ident + 1, "ELF"); + h.ehdr.e_ident[EI_CLASS] = ELFCLASS64; + h.ehdr.e_ident[EI_DATA] = ELFDATA2LSB; + h.ehdr.e_ident[EI_VERSION] = EV_CURRENT; + h.ehdr.e_type = ET_EXEC; + h.ehdr.e_machine = EM_ALPHA; + h.ehdr.e_version = EV_CURRENT; + h.ehdr.e_entry = 0xfffffc0000310000; + h.ehdr.e_phnum = 1; + h.ehdr.e_phoff = (char *) &h.phdr - (char *) &h; + h.phdr.p_vaddr = 0xfffffc0000310000; + h.phdr.p_offset = sizeof(h); + h.phdr.p_filesz = st.st_size; + h.phdr.p_memsz = h.phdr.p_filesz; + + write(1, &h, sizeof(h)); + + while ((n = read(ifd, buf, sizeof(buf))) > 0) { + if (write(1, buf, n) != n) { + perror("short write"); + return 1; + } + } + return 0; +} -- cgit v1.2.3