From d66540542d67dc98175b1ac5d9dd29e04471c1e0 Mon Sep 17 00:00:00 2001 From: Mark Cave-Ayland Date: Fri, 26 Mar 2010 20:25:04 +0000 Subject: [PATCH] Remove loadfs.c and loadfs.h from all of the various architectures. They appear to be almost non-existent wrappers which add an extra layer of indirection without much benefit. Signed-off-by: Mark Cave-Ayland git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@707 f158a5a8-5612-0410-a976-696ce0be7e32 --- arch/amd64/loadfs.c | 43 --------------------------- arch/amd64/loadfs.h | 4 --- arch/sparc32/aoutload.c | 20 +++++++------ arch/sparc32/build.xml | 1 - arch/sparc32/elfload.c | 26 +++++++++-------- arch/sparc32/forthload.c | 17 ++++++----- arch/sparc32/linux_load.c | 43 ++++++++++++++++++++------- arch/sparc32/loadfs.c | 61 --------------------------------------- arch/sparc32/loadfs.h | 5 ---- arch/sparc64/aoutload.c | 20 +++++++------ arch/sparc64/build.xml | 1 - arch/sparc64/elfload.c | 26 +++++++++-------- arch/sparc64/fcodeload.c | 17 ++++++----- arch/sparc64/forthload.c | 20 ++++++++----- arch/sparc64/linux_load.c | 43 ++++++++++++++++++++------- arch/sparc64/loadfs.c | 61 --------------------------------------- arch/sparc64/loadfs.h | 5 ---- arch/x86/build.xml | 1 - arch/x86/elfload.c | 20 +++++++------ arch/x86/forthload.c | 18 +++++++----- arch/x86/linux_load.c | 41 ++++++++++++++++++++------ arch/x86/loadfs.c | 43 --------------------------- arch/x86/loadfs.h | 4 --- 23 files changed, 203 insertions(+), 337 deletions(-) delete mode 100644 arch/amd64/loadfs.c delete mode 100644 arch/amd64/loadfs.h delete mode 100644 arch/sparc32/loadfs.c delete mode 100644 arch/sparc32/loadfs.h delete mode 100644 arch/sparc64/loadfs.c delete mode 100644 arch/sparc64/loadfs.h delete mode 100644 arch/x86/loadfs.c delete mode 100644 arch/x86/loadfs.h diff --git a/arch/amd64/loadfs.c b/arch/amd64/loadfs.c deleted file mode 100644 index 6226fa9..0000000 --- a/arch/amd64/loadfs.c +++ /dev/null @@ -1,43 +0,0 @@ -#include "config.h" -#include "kernel/kernel.h" -#include "libc/diskio.h" -#include "loadfs.h" - -static int load_fd=-1; - -int file_open(const char *filename) -{ - load_fd=open_io(filename); - /* if(load_fd!=-1) */ seek_io(load_fd, 0); - return load_fd>-1; -} - -int lfile_read(void *buf, unsigned long len) -{ - int ret; - ret=read_io(load_fd, buf, len); - return ret; -} - -int file_seek(unsigned long offset) -{ - return seek_io(load_fd, offset); -} - -unsigned long file_size(void) -{ - llong fpos, fsize; - - /* save current position */ - fpos=tell(load_fd); - - /* go to end of file and get position */ - seek_io(load_fd, -1); - fsize=tell(load_fd); - - /* go back to old position */ - seek_io(load_fd, 0); - seek_io(load_fd, fpos); - - return fsize; -} diff --git a/arch/amd64/loadfs.h b/arch/amd64/loadfs.h deleted file mode 100644 index 50b5e23..0000000 --- a/arch/amd64/loadfs.h +++ /dev/null @@ -1,4 +0,0 @@ -int file_open(const char *filename); -int lfile_read(void *buf, unsigned long len); -int file_seek(unsigned long offset); -unsigned long file_size(void); diff --git a/arch/sparc32/aoutload.c b/arch/sparc32/aoutload.c index 082c9f4..b9633ee 100644 --- a/arch/sparc32/aoutload.c +++ b/arch/sparc32/aoutload.c @@ -7,7 +7,7 @@ #include "kernel/kernel.h" #include "arch/common/a.out.h" #include "libopenbios/sys_info.h" -#include "loadfs.h" +#include "libc/diskio.h" #include "boot.h" #define printf printk #define debug printk @@ -15,6 +15,7 @@ #define addr_fixup(addr) ((addr) & 0x00ffffff) static char *image_name, *image_version; +static int fd; static int check_mem_ranges(struct sys_info *info, unsigned long start, @@ -61,12 +62,13 @@ int aout_load(struct sys_info *info, const char *filename, const void *romvec) image_name = image_version = NULL; - if (!file_open(filename)) + fd = open_io(filename); + if (!fd) goto out; - file_seek(offset); + seek_io(fd, offset); - if (lfile_read(&ehdr, sizeof ehdr) != sizeof ehdr) { + if (read_io(fd, &ehdr, sizeof ehdr) != sizeof ehdr) { debug("Can't read a.out header\n"); retval = LOADER_NOT_SUPPORT; goto out; @@ -98,19 +100,19 @@ int aout_load(struct sys_info *info, const char *filename, const void *romvec) printf("Loading a.out %s...\n", image_name ? image_name : "image"); - file_seek(offset + N_TXTOFF(ehdr)); + seek_io(fd, offset + N_TXTOFF(ehdr)); if (N_MAGIC(ehdr) == NMAGIC) { - if ((unsigned long)lfile_read((void *)start, ehdr.a_text) != ehdr.a_text) { + if ((unsigned long)read_io(fd, (void *)start, ehdr.a_text) != ehdr.a_text) { printf("Can't read program text segment (size 0x%lx)\n", ehdr.a_text); goto out; } - if ((unsigned long)lfile_read((void *)(start + N_DATADDR(ehdr)), ehdr.a_data) != ehdr.a_data) { + if ((unsigned long)read_io(fd, (void *)(start + N_DATADDR(ehdr)), ehdr.a_data) != ehdr.a_data) { printf("Can't read program data segment (size 0x%lx)\n", ehdr.a_data); goto out; } } else { - if ((unsigned long)lfile_read((void *)start, size) != size) { + if ((unsigned long)read_io(fd, (void *)start, size) != size) { printf("Can't read program (size 0x%lx)\n", size); goto out; } @@ -134,6 +136,6 @@ int aout_load(struct sys_info *info, const char *filename, const void *romvec) retval = 0; out: - file_close(); + close_io(fd); return retval; } diff --git a/arch/sparc32/build.xml b/arch/sparc32/build.xml index a7d1522..c297938 100644 --- a/arch/sparc32/build.xml +++ b/arch/sparc32/build.xml @@ -18,7 +18,6 @@ - diff --git a/arch/sparc32/elfload.c b/arch/sparc32/elfload.c index a4e86b8..5164245 100644 --- a/arch/sparc32/elfload.c +++ b/arch/sparc32/elfload.c @@ -10,7 +10,7 @@ #include "arch/common/elf_boot.h" #include "libopenbios/sys_info.h" #include "libopenbios/ipchecksum.h" -#include "loadfs.h" +#include "libc/diskio.h" #include "boot.h" #define printf printk #define debug printk @@ -18,6 +18,7 @@ #define addr_fixup(addr) ((addr) & 0x00ffffff) static char *image_name, *image_version; +static int fd; static void *calloc(size_t nmemb, size_t size) { @@ -90,8 +91,8 @@ static unsigned long process_image_notes(Elf_phdr *phdr, int phnum, if (phdr[i].p_type != PT_NOTE) continue; buf = malloc(phdr[i].p_filesz); - file_seek(offset + phdr[i].p_offset); - if ((uint32_t)lfile_read(buf, phdr[i].p_filesz) != phdr[i].p_filesz) { + seek_io(fd, offset + phdr[i].p_offset); + if ((uint32_t)read_io(fd, buf, phdr[i].p_filesz) != phdr[i].p_filesz) { printf("Can't read note segment\n"); goto out; } @@ -126,7 +127,7 @@ static unsigned long process_image_notes(Elf_phdr *phdr, int phnum, } } out: - file_close(); + close_io(fd); if (buf) free(buf); return retval; @@ -147,9 +148,9 @@ static int load_segments(Elf_phdr *phdr, int phnum, continue; debug("segment %d addr:%#x file:%#x mem:%#x ", i, addr_fixup(phdr[i].p_paddr), phdr[i].p_filesz, phdr[i].p_memsz); - file_seek(offset + phdr[i].p_offset); + seek_io(fd, offset + phdr[i].p_offset); debug("loading... "); - if ((uint32_t)lfile_read(phys_to_virt(addr_fixup(phdr[i].p_paddr)), phdr[i].p_filesz) + if ((uint32_t)read_io(fd, phys_to_virt(addr_fixup(phdr[i].p_paddr)), phdr[i].p_filesz) != phdr[i].p_filesz) { printf("Can't read program segment %d\n", i); return 0; @@ -316,11 +317,12 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline, image_name = image_version = NULL; - if (!file_open(filename)) + fd = open_io(filename); + if (!fd) goto out; for (offset = 0; offset < 16 * 512; offset += 512) { - if (lfile_read(&ehdr, sizeof ehdr) != sizeof ehdr) { + if (read_io(fd, &ehdr, sizeof ehdr) != sizeof ehdr) { debug("Can't read ELF header\n"); retval = LOADER_NOT_SUPPORT; goto out; @@ -329,7 +331,7 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline, if (ehdr.e_ident[EI_MAG0] == ELFMAG0) break; - file_seek(offset); + seek_io(fd, offset); } if (ehdr.e_ident[EI_MAG0] != ELFMAG0 @@ -350,8 +352,8 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline, phdr_size = ehdr.e_phnum * sizeof *phdr; phdr = malloc(phdr_size); - file_seek(offset + ehdr.e_phoff); - if ((uint32_t)lfile_read(phdr, phdr_size) != phdr_size) { + seek_io(fd, offset + ehdr.e_phoff); + if ((uint32_t)read_io(fd, phdr, phdr_size) != phdr_size) { printf("Can't read program header\n"); goto out; } @@ -397,7 +399,7 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline, retval = 0; out: - file_close(); + close_io(fd); if (phdr) free(phdr); if (boot_notes) diff --git a/arch/sparc32/forthload.c b/arch/sparc32/forthload.c index 1c0f5d3..da60849 100644 --- a/arch/sparc32/forthload.c +++ b/arch/sparc32/forthload.c @@ -10,12 +10,13 @@ #include "kernel/kernel.h" #include "libopenbios/bindings.h" #include "libopenbios/sys_info.h" -#include "loadfs.h" +#include "libc/diskio.h" #include "boot.h" #define printk printk #define debug printk static char *forthtext=NULL; +static int fd; int forth_load(const char *filename) { @@ -23,10 +24,11 @@ int forth_load(const char *filename) unsigned long forthsize; int retval = -1; - if (!file_open(filename)) + fd = open_io(filename); + if (!fd) goto out; - if (lfile_read(magic, 2) != 2) { + if (read_io(fd, magic, 2) != 2) { debug("Can't read magic header\n"); retval = LOADER_NOT_SUPPORT; goto out; @@ -38,13 +40,14 @@ int forth_load(const char *filename) goto out; } - forthsize = file_size(); - + /* Calculate the file size by seeking to the end of the file */ + seek_io(fd, -1); + forthsize = tell(fd); forthtext = malloc(forthsize+1); - file_seek(0); + seek_io(fd, 0); printk("Loading forth source ..."); - if ((unsigned long)lfile_read(forthtext, forthsize) != forthsize) { + if ((unsigned long)read_io(fd, forthtext, forthsize) != forthsize) { printk("Can't read forth text\n"); goto out; } diff --git a/arch/sparc32/linux_load.c b/arch/sparc32/linux_load.c index d378e70..69edadc 100644 --- a/arch/sparc32/linux_load.c +++ b/arch/sparc32/linux_load.c @@ -13,7 +13,7 @@ #include "libopenbios/bindings.h" #include "libopenbios/sys_info.h" #include "context.h" -#include "loadfs.h" +#include "libc/diskio.h" #include "boot.h" #define printf printk @@ -157,6 +157,25 @@ struct linux_params { }; static uint64_t forced_memsize; +static int fd; + +static unsigned long file_size(void) +{ + llong fpos, fsize; + + /* Save current position */ + fpos = tell(fd); + + /* Go to end of file and get position */ + seek_io(fd, -1); + fsize = tell(fd); + + /* Go back to old position */ + seek_io(fd, 0); + seek_io(fd, fpos); + + return fsize; +} /* Load the first part the file and check if it's Linux */ static uint32_t load_linux_header(struct linux_header *hdr) @@ -164,7 +183,7 @@ static uint32_t load_linux_header(struct linux_header *hdr) int load_high; uint32_t kern_addr; - if (lfile_read(hdr, sizeof *hdr) != sizeof *hdr) { + if (read_io(fd, hdr, sizeof *hdr) != sizeof *hdr) { debug("Can't read Linux header\n"); return 0; } @@ -191,8 +210,8 @@ static uint32_t load_linux_header(struct linux_header *hdr) printf("Found Linux"); if (hdr->protocol_version >= 0x200 && hdr->kver_addr) { char kver[256]; - file_seek(hdr->kver_addr + 0x200); - if (lfile_read(kver, sizeof kver) != 0) { + seek_io(fd, hdr->kver_addr + 0x200); + if (read_io(fd, kver, sizeof kver) != 0) { kver[255] = 0; printf(" version %s", kver); } @@ -412,7 +431,7 @@ static int load_linux_kernel(struct linux_header *hdr, uint32_t kern_addr) if (hdr->setup_sects == 0) hdr->setup_sects = 4; kern_offset = (hdr->setup_sects + 1) * 512; - file_seek(kern_offset); + seek_io(fd, kern_offset); kern_size = file_size() - kern_offset; debug("offset=%#x addr=%#x size=%#x\n", kern_offset, kern_addr, kern_size); @@ -425,7 +444,7 @@ static int load_linux_kernel(struct linux_header *hdr, uint32_t kern_addr) #endif printf("Loading kernel... "); - if ((uint32_t)lfile_read(phys_to_virt(kern_addr), kern_size) != kern_size) { + if ((uint32_t)read_io(fd, phys_to_virt(kern_addr), kern_size) != kern_size) { printf("Can't read kernel\n"); return 0; } @@ -441,7 +460,8 @@ static int load_initrd(struct linux_header *hdr, uint32_t kern_end, uint32_t start, end, size; uint64_t forced; - if (!file_open(initrd_file)) { + fd = open_io(initrd_file); + if (!fd) { printf("Can't open initrd: %s\n", initrd_file); return -1; } @@ -498,7 +518,7 @@ static int load_initrd(struct linux_header *hdr, uint32_t kern_end, } printf("Loading initrd... "); - if ((uint32_t)lfile_read(phys_to_virt(start), size) != size) { + if ((uint32_t)read_io(fd, phys_to_virt(start), size) != size) { printf("Can't read initrd\n"); return -1; } @@ -507,6 +527,8 @@ static int load_initrd(struct linux_header *hdr, uint32_t kern_end, params->initrd_start = start; params->initrd_size = size; + close_io(fd); + return 0; } @@ -586,12 +608,13 @@ int linux_load(struct sys_info *info, const char *file, const char *cmdline) uint32_t kern_addr, kern_size; char *initrd_file = NULL; - if (!file_open(file)) + fd = open_io(file); + if (!fd) return -1; kern_addr = load_linux_header(&hdr); if (kern_addr == 0) { - file_close(); + close_io(fd); return LOADER_NOT_SUPPORT; } diff --git a/arch/sparc32/loadfs.c b/arch/sparc32/loadfs.c deleted file mode 100644 index 28406ab..0000000 --- a/arch/sparc32/loadfs.c +++ /dev/null @@ -1,61 +0,0 @@ -#include "config.h" -#include "kernel/kernel.h" -#include "libc/diskio.h" -#include "loadfs.h" - -static int load_fd=-1; - -int file_open(const char *filename) -{ - load_fd=open_io(filename); - if(load_fd >= 0) - seek_io(load_fd, 0); - return load_fd>-1; -} - -void file_close(void) -{ - if(load_fd==-1) - return; - - close_io(load_fd); - load_fd=-1; -} - -int lfile_read(void *buf, unsigned long len) -{ - int ret = 0; - - if (load_fd >= 0) - ret=read_io(load_fd, buf, len); - return ret; -} - -int file_seek(unsigned long offset) -{ - if (load_fd >= 0) - return seek_io(load_fd, offset); - else - return -1; -} - -unsigned long file_size(void) -{ - llong fpos, fsize; - - if (load_fd < 0) - return 0; - - /* save current position */ - fpos=tell(load_fd); - - /* go to end of file and get position */ - seek_io(load_fd, -1); - fsize=tell(load_fd); - - /* go back to old position */ - seek_io(load_fd, 0); - seek_io(load_fd, fpos); - - return fsize; -} diff --git a/arch/sparc32/loadfs.h b/arch/sparc32/loadfs.h deleted file mode 100644 index 58fa722..0000000 --- a/arch/sparc32/loadfs.h +++ /dev/null @@ -1,5 +0,0 @@ -int file_open(const char *filename); -int lfile_read(void *buf, unsigned long len); -int file_seek(unsigned long offset); -unsigned long file_size(void); -void file_close(void); diff --git a/arch/sparc64/aoutload.c b/arch/sparc64/aoutload.c index 1162ecb..f239e33 100644 --- a/arch/sparc64/aoutload.c +++ b/arch/sparc64/aoutload.c @@ -8,7 +8,7 @@ #define CONFIG_SPARC64_PAGE_SIZE_8KB #include "arch/common/a.out.h" #include "libopenbios/sys_info.h" -#include "loadfs.h" +#include "libc/diskio.h" #include "boot.h" #define printf printk #define debug printk @@ -16,6 +16,7 @@ #define addr_fixup(addr) ((addr) & 0x00ffffff) static char *image_name, *image_version; +static int fd; static int check_mem_ranges(struct sys_info *info, unsigned long start, @@ -62,12 +63,13 @@ int aout_load(struct sys_info *info, const char *filename) image_name = image_version = NULL; - if (!file_open(filename)) + fd = open_io(filename); + if (!fd) goto out; for (offset = 0; offset < 16 * 512; offset += 512) { - file_seek(offset); - if (lfile_read(&ehdr, sizeof ehdr) != sizeof ehdr) { + seek_io(fd, offset); + if (read_io(fd, &ehdr, sizeof ehdr) != sizeof ehdr) { debug("Can't read a.out header\n"); retval = LOADER_NOT_SUPPORT; goto out; @@ -102,19 +104,19 @@ int aout_load(struct sys_info *info, const char *filename) printf("Loading a.out %s...\n", image_name ? image_name : "image"); - file_seek(offset + N_TXTOFF(ehdr)); + seek_io(fd, offset + N_TXTOFF(ehdr)); if (N_MAGIC(ehdr) == NMAGIC) { - if ((unsigned long)lfile_read((void *)start, ehdr.a_text) != ehdr.a_text) { + if ((unsigned long)read_io(fd, (void *)start, ehdr.a_text) != ehdr.a_text) { printf("Can't read program text segment (size 0x%x)\n", ehdr.a_text); goto out; } - if ((unsigned long)lfile_read((void *)(start + N_DATADDR(ehdr)), ehdr.a_data) != ehdr.a_data) { + if ((unsigned long)read_io(fd, (void *)(start + N_DATADDR(ehdr)), ehdr.a_data) != ehdr.a_data) { printf("Can't read program data segment (size 0x%x)\n", ehdr.a_data); goto out; } } else { - if ((unsigned long)lfile_read((void *)start, size) != size) { + if ((unsigned long)read_io(fd, (void *)start, size) != size) { printf("Can't read program (size 0x%lx)\n", size); goto out; } @@ -134,6 +136,6 @@ int aout_load(struct sys_info *info, const char *filename) retval = 0; out: - file_close(); + close_io(fd); return retval; } diff --git a/arch/sparc64/build.xml b/arch/sparc64/build.xml index 47a2df4..3c45e13 100644 --- a/arch/sparc64/build.xml +++ b/arch/sparc64/build.xml @@ -18,7 +18,6 @@ - diff --git a/arch/sparc64/elfload.c b/arch/sparc64/elfload.c index 8b40472..d6f0f8c 100644 --- a/arch/sparc64/elfload.c +++ b/arch/sparc64/elfload.c @@ -10,7 +10,7 @@ #include "arch/common/elf_boot.h" #include "libopenbios/sys_info.h" #include "libopenbios/ipchecksum.h" -#include "loadfs.h" +#include "libc/diskio.h" #include "boot.h" #define printf printk #define debug printk @@ -18,6 +18,7 @@ #define addr_fixup(addr) ((addr) & 0x00ffffff) static char *image_name, *image_version; +static int fd; static void *calloc(size_t nmemb, size_t size) { @@ -90,8 +91,8 @@ static unsigned long process_image_notes(Elf_phdr *phdr, int phnum, if (phdr[i].p_type != PT_NOTE) continue; buf = malloc(phdr[i].p_filesz); - file_seek(offset + phdr[i].p_offset); - if ((uint64_t)lfile_read(buf, phdr[i].p_filesz) != phdr[i].p_filesz) { + seek_io(fd, offset + phdr[i].p_offset); + if ((uint64_t)read_io(fd, buf, phdr[i].p_filesz) != phdr[i].p_filesz) { printf("Can't read note segment\n"); goto out; } @@ -126,7 +127,7 @@ static unsigned long process_image_notes(Elf_phdr *phdr, int phnum, } } out: - file_close(); + close_io(fd); if (buf) free(buf); return retval; @@ -147,9 +148,9 @@ static int load_segments(Elf_phdr *phdr, int phnum, continue; debug("segment %d addr:%#llx file:%#llx mem:%#llx ", i, addr_fixup(phdr[i].p_paddr), phdr[i].p_filesz, phdr[i].p_memsz); - file_seek(offset + phdr[i].p_offset); + seek_io(fd, offset + phdr[i].p_offset); debug("loading... "); - if ((uint64_t)lfile_read(phys_to_virt(addr_fixup(phdr[i].p_paddr)), phdr[i].p_filesz) + if ((uint64_t)read_io(fd, phys_to_virt(addr_fixup(phdr[i].p_paddr)), phdr[i].p_filesz) != phdr[i].p_filesz) { printf("Can't read program segment %d\n", i); return 0; @@ -315,11 +316,12 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) image_name = image_version = NULL; - if (!file_open(filename)) + fd = open_io(filename); + if (!fd) goto out; for (offset = 0; offset < 16 * 512; offset += 512) { - if ((size_t)lfile_read(&ehdr, sizeof ehdr) != sizeof ehdr) { + if ((size_t)read_io(fd, &ehdr, sizeof ehdr) != sizeof ehdr) { debug("Can't read ELF header\n"); retval = LOADER_NOT_SUPPORT; goto out; @@ -328,7 +330,7 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) if (ehdr.e_ident[EI_MAG0] == ELFMAG0) break; - file_seek(offset); + seek_io(fd, offset); } if (ehdr.e_ident[EI_MAG0] != ELFMAG0 @@ -349,8 +351,8 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) phdr_size = ehdr.e_phnum * sizeof *phdr; phdr = malloc(phdr_size); - file_seek(offset + ehdr.e_phoff); - if ((unsigned long)lfile_read(phdr, phdr_size) != phdr_size) { + seek_io(fd, offset + ehdr.e_phoff); + if ((unsigned long)read_io(fd, phdr, phdr_size) != phdr_size) { printf("Can't read program header\n"); goto out; } @@ -402,7 +404,7 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) retval = 0; out: - file_close(); + close_io(fd); if (phdr) free(phdr); if (boot_notes) diff --git a/arch/sparc64/fcodeload.c b/arch/sparc64/fcodeload.c index a414b7f..af589af 100644 --- a/arch/sparc64/fcodeload.c +++ b/arch/sparc64/fcodeload.c @@ -6,11 +6,13 @@ #include "kernel/kernel.h" #include "libopenbios/bindings.h" #include "libopenbios/sys_info.h" -#include "loadfs.h" +#include "libc/diskio.h" #include "boot.h" #define printf printk #define debug printk +static int fd; + int fcode_load(const char *filename) { int retval = -1; @@ -18,12 +20,13 @@ int fcode_load(const char *filename) unsigned long start, size; unsigned int offset; - if (!file_open(filename)) + fd = open_io(filename); + if (!fd) goto out; for (offset = 0; offset < 16 * 512; offset += 512) { - file_seek(offset); - if (lfile_read(&fcode_header, sizeof(fcode_header)) + seek_io(fd, offset); + if (read_io(fd, &fcode_header, sizeof(fcode_header)) != sizeof(fcode_header)) { debug("Can't read FCode header from file %s\n", filename); retval = LOADER_NOT_SUPPORT; @@ -51,9 +54,9 @@ int fcode_load(const char *filename) printf("Loading FCode image...\n"); - file_seek(offset + sizeof(fcode_header)); + seek_io(fd, offset + sizeof(fcode_header)); - if ((unsigned long)lfile_read((void *)start, size) != size) { + if ((unsigned long)read_io(fd, (void *)start, size) != size) { printf("Can't read file (size 0x%lx)\n", size); goto out; } @@ -70,6 +73,6 @@ int fcode_load(const char *filename) retval = 0; out: - file_close(); + close_io(fd); return retval; } diff --git a/arch/sparc64/forthload.c b/arch/sparc64/forthload.c index d6d2715..9b43d82 100644 --- a/arch/sparc64/forthload.c +++ b/arch/sparc64/forthload.c @@ -10,22 +10,25 @@ #include "kernel/kernel.h" #include "libopenbios/bindings.h" #include "libopenbios/sys_info.h" -#include "loadfs.h" +#include "libc/diskio.h" #include "boot.h" #define printk printk #define debug printk static char *forthtext=NULL; +static int fd; + int forth_load(const char *filename) { char magic[2]; unsigned long forthsize; int retval = -1; - if (!file_open(filename)) + fd = open_io(filename); + if (!fd) goto out; - if (lfile_read(magic, 2) != 2) { + if (read_io(fd, magic, 2) != 2) { debug("Can't read magic header\n"); retval = LOADER_NOT_SUPPORT; goto out; @@ -37,19 +40,22 @@ int forth_load(const char *filename) goto out; } - forthsize = file_size(); - + /* Calculate the file size by seeking to the end of the file */ + seek_io(fd, -1); + forthsize = tell(fd); forthtext = malloc(forthsize+1); - file_seek(0); + seek_io(fd, 0); printk("Loading forth source ..."); - if ((unsigned long)lfile_read(forthtext, forthsize) != forthsize) { + if ((unsigned long)read_io(fd, forthtext, forthsize) != forthsize) { printk("Can't read forth text\n"); goto out; } forthtext[forthsize]=0; printk("ok\n"); + close_io(fd); + PUSH ( (ucell)forthtext ); PUSH ( (ucell)forthsize ); fword("eval2"); diff --git a/arch/sparc64/linux_load.c b/arch/sparc64/linux_load.c index 247281a..07b2b42 100644 --- a/arch/sparc64/linux_load.c +++ b/arch/sparc64/linux_load.c @@ -13,7 +13,7 @@ #include "libopenbios/bindings.h" #include "libopenbios/sys_info.h" #include "context.h" -#include "loadfs.h" +#include "libc/diskio.h" #include "boot.h" #define printf printk @@ -157,6 +157,25 @@ struct linux_params { }; static uint64_t forced_memsize; +static int fd; + +static unsigned long file_size(void) +{ + llong fpos, fsize; + + /* Save current position */ + fpos = tell(fd); + + /* Go to end of file and get position */ + seek_io(fd, -1); + fsize = tell(fd); + + /* Go back to old position */ + seek_io(fd, 0); + seek_io(fd, fpos); + + return fsize; +} /* Load the first part the file and check if it's Linux */ static uint32_t load_linux_header(struct linux_header *hdr) @@ -164,7 +183,7 @@ static uint32_t load_linux_header(struct linux_header *hdr) int load_high; uint32_t kern_addr; - if (lfile_read(hdr, sizeof *hdr) != sizeof *hdr) { + if (read_io(fd, hdr, sizeof *hdr) != sizeof *hdr) { debug("Can't read Linux header\n"); return 0; } @@ -191,8 +210,8 @@ static uint32_t load_linux_header(struct linux_header *hdr) printf("Found Linux"); if (hdr->protocol_version >= 0x200 && hdr->kver_addr) { char kver[256]; - file_seek(hdr->kver_addr + 0x200); - if (lfile_read(kver, sizeof kver) != 0) { + seek_io(fd, hdr->kver_addr + 0x200); + if (read_io(fd, kver, sizeof kver) != 0) { kver[255] = 0; printf(" version %s", kver); } @@ -412,7 +431,7 @@ static int load_linux_kernel(struct linux_header *hdr, uint32_t kern_addr) if (hdr->setup_sects == 0) hdr->setup_sects = 4; kern_offset = (hdr->setup_sects + 1) * 512; - file_seek(kern_offset); + seek_io(fd, kern_offset); kern_size = file_size() - kern_offset; debug("offset=%#x addr=%#x size=%#x\n", kern_offset, kern_addr, kern_size); @@ -425,7 +444,7 @@ static int load_linux_kernel(struct linux_header *hdr, uint32_t kern_addr) #endif printf("Loading kernel... "); - if ((uint32_t)lfile_read(phys_to_virt(kern_addr), kern_size) != kern_size) { + if ((uint32_t)read_io(fd, phys_to_virt(kern_addr), kern_size) != kern_size) { printf("Can't read kernel\n"); return 0; } @@ -441,7 +460,8 @@ static int load_initrd(struct linux_header *hdr, uint32_t kern_end, uint32_t start, end, size; uint64_t forced; - if (!file_open(initrd_file)) { + fd = open_io(initrd_file); + if (!fd) { printf("Can't open initrd: %s\n", initrd_file); return -1; } @@ -498,7 +518,7 @@ static int load_initrd(struct linux_header *hdr, uint32_t kern_end, } printf("Loading initrd... "); - if ((uint32_t)lfile_read(phys_to_virt(start), size) != size) { + if ((uint32_t)read_io(fd, phys_to_virt(start), size) != size) { printf("Can't read initrd\n"); return -1; } @@ -507,6 +527,8 @@ static int load_initrd(struct linux_header *hdr, uint32_t kern_end, params->initrd_start = start; params->initrd_size = size; + close_io(fd); + return 0; } @@ -586,12 +608,13 @@ int linux_load(struct sys_info *info, const char *file, const char *cmdline) uint32_t kern_addr, kern_size; char *initrd_file = NULL; - if (!file_open(file)) + fd = open_io(file); + if (!fd) return -1; kern_addr = load_linux_header(&hdr); if (kern_addr == 0) { - file_close(); + close_io(fd); return LOADER_NOT_SUPPORT; } diff --git a/arch/sparc64/loadfs.c b/arch/sparc64/loadfs.c deleted file mode 100644 index 28406ab..0000000 --- a/arch/sparc64/loadfs.c +++ /dev/null @@ -1,61 +0,0 @@ -#include "config.h" -#include "kernel/kernel.h" -#include "libc/diskio.h" -#include "loadfs.h" - -static int load_fd=-1; - -int file_open(const char *filename) -{ - load_fd=open_io(filename); - if(load_fd >= 0) - seek_io(load_fd, 0); - return load_fd>-1; -} - -void file_close(void) -{ - if(load_fd==-1) - return; - - close_io(load_fd); - load_fd=-1; -} - -int lfile_read(void *buf, unsigned long len) -{ - int ret = 0; - - if (load_fd >= 0) - ret=read_io(load_fd, buf, len); - return ret; -} - -int file_seek(unsigned long offset) -{ - if (load_fd >= 0) - return seek_io(load_fd, offset); - else - return -1; -} - -unsigned long file_size(void) -{ - llong fpos, fsize; - - if (load_fd < 0) - return 0; - - /* save current position */ - fpos=tell(load_fd); - - /* go to end of file and get position */ - seek_io(load_fd, -1); - fsize=tell(load_fd); - - /* go back to old position */ - seek_io(load_fd, 0); - seek_io(load_fd, fpos); - - return fsize; -} diff --git a/arch/sparc64/loadfs.h b/arch/sparc64/loadfs.h deleted file mode 100644 index 58fa722..0000000 --- a/arch/sparc64/loadfs.h +++ /dev/null @@ -1,5 +0,0 @@ -int file_open(const char *filename); -int lfile_read(void *buf, unsigned long len); -int file_seek(unsigned long offset); -unsigned long file_size(void); -void file_close(void); diff --git a/arch/x86/build.xml b/arch/x86/build.xml index fb42456..476d361 100644 --- a/arch/x86/build.xml +++ b/arch/x86/build.xml @@ -16,7 +16,6 @@ - diff --git a/arch/x86/elfload.c b/arch/x86/elfload.c index 09ab2aa..9dcd29b 100644 --- a/arch/x86/elfload.c +++ b/arch/x86/elfload.c @@ -10,7 +10,7 @@ #include "arch/common/elf_boot.h" #include "libopenbios/sys_info.h" #include "libopenbios/ipchecksum.h" -#include "loadfs.h" +#include "libc/diskio.h" #include "boot.h" #define debug printk @@ -22,6 +22,7 @@ extern char _start, _end; static char *image_name, *image_version; +static int fd; static void *calloc(size_t nmemb, size_t size) { @@ -94,8 +95,8 @@ static unsigned long process_image_notes(Elf_phdr *phdr, int phnum, if (phdr[i].p_type != PT_NOTE) continue; buf = malloc(phdr[i].p_filesz); - file_seek(phdr[i].p_offset); - if (lfile_read(buf, phdr[i].p_filesz) != phdr[i].p_filesz) { + seek_io(fd, phdr[i].p_offset); + if (read_io(fd, buf, phdr[i].p_filesz) != phdr[i].p_filesz) { printk("Can't read note segment\n"); goto out; } @@ -149,9 +150,9 @@ static int load_segments(Elf_phdr *phdr, int phnum, continue; debug("segment %d addr:%#x file:%#x mem:%#x ", i, phdr[i].p_paddr, phdr[i].p_filesz, phdr[i].p_memsz); - file_seek(phdr[i].p_offset); + seek_io(fd, phdr[i].p_offset); debug("loading... "); - if (lfile_read(phys_to_virt(phdr[i].p_paddr & ADDRMASK), phdr[i].p_filesz) + if (read_io(fd, phys_to_virt(phdr[i].p_paddr & ADDRMASK), phdr[i].p_filesz) != phdr[i].p_filesz) { printk("Can't read program segment %d\n", i); return 0; @@ -316,10 +317,11 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) image_name = image_version = NULL; - if (!file_open(filename)) + fd = open_io(filename); + if (!fd) goto out; - if (lfile_read(&ehdr, sizeof ehdr) != sizeof ehdr) { + if (read_io(fd, &ehdr, sizeof ehdr) != sizeof ehdr) { debug("Can't read ELF header\n"); retval = LOADER_NOT_SUPPORT; goto out; @@ -343,8 +345,8 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) phdr_size = ehdr.e_phnum * sizeof *phdr; phdr = malloc(phdr_size); - file_seek(ehdr.e_phoff); - if (lfile_read(phdr, phdr_size) != phdr_size) { + seek_io(fd, ehdr.e_phoff); + if (read_io(fd, phdr, phdr_size) != phdr_size) { printk("Can't read program header\n"); goto out; } diff --git a/arch/x86/forthload.c b/arch/x86/forthload.c index 2591a09..a50b8d2 100644 --- a/arch/x86/forthload.c +++ b/arch/x86/forthload.c @@ -10,22 +10,25 @@ #include "kernel/kernel.h" #include "libopenbios/bindings.h" #include "libopenbios/sys_info.h" -#include "loadfs.h" +#include "libc/diskio.h" #include "boot.h" #define printk printk #define debug printk static char *forthtext=NULL; +static int fd; + int forth_load(struct sys_info *info, const char *filename, const char *cmdline) { char magic[2]; unsigned long forthsize; int retval = -1; - if (!file_open(filename)) + fd = open_io(filename); + if (!fd) goto out; - if (lfile_read(magic, 2) != 2) { + if (read_io(fd, magic, 2) != 2) { debug("Can't read magic header\n"); retval = LOADER_NOT_SUPPORT; goto out; @@ -37,13 +40,14 @@ int forth_load(struct sys_info *info, const char *filename, const char *cmdline) goto out; } - forthsize = file_size(); - + /* Calculate the file size by seeking to the end of the file */ + seek_io(fd, -1); + forthsize = tell(fd); forthtext = malloc(forthsize+1); - file_seek(0); + seek_io(fd, 0); printk("Loading forth source ..."); - if (lfile_read(forthtext, forthsize) != forthsize) { + if (read_io(fd, forthtext, forthsize) != forthsize) { printk("Can't read forth text\n"); goto out; } diff --git a/arch/x86/linux_load.c b/arch/x86/linux_load.c index 8871f6f..3abe443 100644 --- a/arch/x86/linux_load.c +++ b/arch/x86/linux_load.c @@ -14,7 +14,7 @@ #include "libopenbios/sys_info.h" #include "context.h" #include "segment.h" -#include "loadfs.h" +#include "libc/diskio.h" #include "boot.h" #define printf printk @@ -158,6 +158,25 @@ struct linux_params { }; static uint64_t forced_memsize; +static int fd; + +static unsigned long file_size(void) +{ + llong fpos, fsize; + + /* Save current position */ + fpos = tell(fd); + + /* Go to end of file and get position */ + seek_io(fd, -1); + fsize = tell(fd); + + /* Go back to old position */ + seek_io(fd, 0); + seek_io(fd, fpos); + + return fsize; +} /* Load the first part the file and check if it's Linux */ static uint32_t load_linux_header(struct linux_header *hdr) @@ -165,7 +184,7 @@ static uint32_t load_linux_header(struct linux_header *hdr) int load_high; uint32_t kern_addr; - if (lfile_read(hdr, sizeof *hdr) != sizeof *hdr) { + if (read_io(fd, hdr, sizeof *hdr) != sizeof *hdr) { debug("Can't read Linux header\n"); return 0; } @@ -192,8 +211,8 @@ static uint32_t load_linux_header(struct linux_header *hdr) printf("Found Linux"); if (hdr->protocol_version >= 0x200 && hdr->kver_addr) { char kver[256]; - file_seek(hdr->kver_addr + 0x200); - if (lfile_read(kver, sizeof kver) != 0) { + seek_io(fd, hdr->kver_addr + 0x200); + if (read_io(fd, kver, sizeof kver) != 0) { kver[255] = 0; printf(" version %s", kver); } @@ -413,7 +432,7 @@ static int load_linux_kernel(struct linux_header *hdr, uint32_t kern_addr) if (hdr->setup_sects == 0) hdr->setup_sects = 4; kern_offset = (hdr->setup_sects + 1) * 512; - file_seek(kern_offset); + seek_io(fd, kern_offset); kern_size = file_size() - kern_offset; debug("offset=%#x addr=%#x size=%#x\n", kern_offset, kern_addr, kern_size); @@ -426,7 +445,7 @@ static int load_linux_kernel(struct linux_header *hdr, uint32_t kern_addr) #endif printf("Loading kernel... "); - if (lfile_read(phys_to_virt(kern_addr), kern_size) != kern_size) { + if (read_io(fd, phys_to_virt(kern_addr), kern_size) != kern_size) { printf("Can't read kernel\n"); return 0; } @@ -443,7 +462,8 @@ static int load_initrd(struct linux_header *hdr, struct sys_info *info, uint64_t forced; extern char _start[], _end[]; - if (!file_open(initrd_file)) { + fd = open_io(initrd_file); + if (!fd) { printf("Can't open initrd: %s\n", initrd_file); return -1; } @@ -500,7 +520,7 @@ static int load_initrd(struct linux_header *hdr, struct sys_info *info, } printf("Loading initrd... "); - if (lfile_read(phys_to_virt(start), size) != size) { + if (read_io(fd, phys_to_virt(start), size) != size) { printf("Can't read initrd\n"); return -1; } @@ -509,6 +529,8 @@ static int load_initrd(struct linux_header *hdr, struct sys_info *info, params->initrd_start = start; params->initrd_size = size; + close_io(fd); + return 0; } @@ -612,7 +634,8 @@ int linux_load(struct sys_info *info, const char *file, const char *cmdline) uint32_t kern_addr, kern_size; char *initrd_file = NULL; - if (!file_open(file)) + fd = open_io(file); + if (!fd) return -1; kern_addr = load_linux_header(&hdr); diff --git a/arch/x86/loadfs.c b/arch/x86/loadfs.c deleted file mode 100644 index 6226fa9..0000000 --- a/arch/x86/loadfs.c +++ /dev/null @@ -1,43 +0,0 @@ -#include "config.h" -#include "kernel/kernel.h" -#include "libc/diskio.h" -#include "loadfs.h" - -static int load_fd=-1; - -int file_open(const char *filename) -{ - load_fd=open_io(filename); - /* if(load_fd!=-1) */ seek_io(load_fd, 0); - return load_fd>-1; -} - -int lfile_read(void *buf, unsigned long len) -{ - int ret; - ret=read_io(load_fd, buf, len); - return ret; -} - -int file_seek(unsigned long offset) -{ - return seek_io(load_fd, offset); -} - -unsigned long file_size(void) -{ - llong fpos, fsize; - - /* save current position */ - fpos=tell(load_fd); - - /* go to end of file and get position */ - seek_io(load_fd, -1); - fsize=tell(load_fd); - - /* go back to old position */ - seek_io(load_fd, 0); - seek_io(load_fd, fpos); - - return fsize; -} diff --git a/arch/x86/loadfs.h b/arch/x86/loadfs.h deleted file mode 100644 index 50b5e23..0000000 --- a/arch/x86/loadfs.h +++ /dev/null @@ -1,4 +0,0 @@ -int file_open(const char *filename); -int lfile_read(void *buf, unsigned long len); -int file_seek(unsigned long offset); -unsigned long file_size(void);