Author: mcayland Date: Fri Mar 26 21:25:04 2010 New Revision: 707 URL: http://tracker.coreboot.org/trac/openbios/changeset/707
Log: 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 mark.cave-ayland@siriusit.co.uk
Deleted: trunk/openbios-devel/arch/amd64/loadfs.c trunk/openbios-devel/arch/amd64/loadfs.h trunk/openbios-devel/arch/sparc32/loadfs.c trunk/openbios-devel/arch/sparc32/loadfs.h trunk/openbios-devel/arch/sparc64/loadfs.c trunk/openbios-devel/arch/sparc64/loadfs.h trunk/openbios-devel/arch/x86/loadfs.c trunk/openbios-devel/arch/x86/loadfs.h Modified: trunk/openbios-devel/arch/sparc32/aoutload.c trunk/openbios-devel/arch/sparc32/build.xml trunk/openbios-devel/arch/sparc32/elfload.c trunk/openbios-devel/arch/sparc32/forthload.c trunk/openbios-devel/arch/sparc32/linux_load.c trunk/openbios-devel/arch/sparc64/aoutload.c trunk/openbios-devel/arch/sparc64/build.xml trunk/openbios-devel/arch/sparc64/elfload.c trunk/openbios-devel/arch/sparc64/fcodeload.c trunk/openbios-devel/arch/sparc64/forthload.c trunk/openbios-devel/arch/sparc64/linux_load.c trunk/openbios-devel/arch/x86/build.xml trunk/openbios-devel/arch/x86/elfload.c trunk/openbios-devel/arch/x86/forthload.c trunk/openbios-devel/arch/x86/linux_load.c
Modified: trunk/openbios-devel/arch/sparc32/aoutload.c ============================================================================== --- trunk/openbios-devel/arch/sparc32/aoutload.c Thu Mar 25 22:14:00 2010 (r706) +++ trunk/openbios-devel/arch/sparc32/aoutload.c Fri Mar 26 21:25:04 2010 (r707) @@ -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 @@
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 @@
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 @@ retval = 0;
out: - file_close(); + close_io(fd); return retval; }
Modified: trunk/openbios-devel/arch/sparc32/build.xml ============================================================================== --- trunk/openbios-devel/arch/sparc32/build.xml Thu Mar 25 22:14:00 2010 (r706) +++ trunk/openbios-devel/arch/sparc32/build.xml Fri Mar 26 21:25:04 2010 (r707) @@ -18,7 +18,6 @@ <object source="elfload.c"/> <object source="aoutload.c"/> <object source="forthload.c"/> - <object source="loadfs.c"/> <object source="romvec.c"/> <object source="entry.S"/> <object source="vectors.S"/>
Modified: trunk/openbios-devel/arch/sparc32/elfload.c ============================================================================== --- trunk/openbios-devel/arch/sparc32/elfload.c Thu Mar 25 22:14:00 2010 (r706) +++ trunk/openbios-devel/arch/sparc32/elfload.c Fri Mar 26 21:25:04 2010 (r707) @@ -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 @@ 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 @@ } } out: - file_close(); + close_io(fd); if (buf) free(buf); return retval; @@ -147,9 +148,9 @@ 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 @@
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 @@ 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 @@
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 @@ retval = 0;
out: - file_close(); + close_io(fd); if (phdr) free(phdr); if (boot_notes)
Modified: trunk/openbios-devel/arch/sparc32/forthload.c ============================================================================== --- trunk/openbios-devel/arch/sparc32/forthload.c Thu Mar 25 22:14:00 2010 (r706) +++ trunk/openbios-devel/arch/sparc32/forthload.c Fri Mar 26 21:25:04 2010 (r707) @@ -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 @@ 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 @@ 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; }
Modified: trunk/openbios-devel/arch/sparc32/linux_load.c ============================================================================== --- trunk/openbios-devel/arch/sparc32/linux_load.c Thu Mar 25 22:14:00 2010 (r706) +++ trunk/openbios-devel/arch/sparc32/linux_load.c Fri Mar 26 21:25:04 2010 (r707) @@ -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 @@ };
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 @@ 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 @@ 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 @@ 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 @@ #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 @@ 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 @@ }
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 @@ params->initrd_start = start; params->initrd_size = size;
+ close_io(fd); + return 0; }
@@ -586,12 +608,13 @@ 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; }
Modified: trunk/openbios-devel/arch/sparc64/aoutload.c ============================================================================== --- trunk/openbios-devel/arch/sparc64/aoutload.c Thu Mar 25 22:14:00 2010 (r706) +++ trunk/openbios-devel/arch/sparc64/aoutload.c Fri Mar 26 21:25:04 2010 (r707) @@ -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 @@
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 @@
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 @@ retval = 0;
out: - file_close(); + close_io(fd); return retval; }
Modified: trunk/openbios-devel/arch/sparc64/build.xml ============================================================================== --- trunk/openbios-devel/arch/sparc64/build.xml Thu Mar 25 22:14:00 2010 (r706) +++ trunk/openbios-devel/arch/sparc64/build.xml Fri Mar 26 21:25:04 2010 (r707) @@ -18,7 +18,6 @@ <object source="aoutload.c"/> <object source="forthload.c"/> <object source="fcodeload.c"/> - <object source="loadfs.c"/> <object source="ofmem_sparc64.c"/> <object source="entry.S"/> <object source="vectors.S"/>
Modified: trunk/openbios-devel/arch/sparc64/elfload.c ============================================================================== --- trunk/openbios-devel/arch/sparc64/elfload.c Thu Mar 25 22:14:00 2010 (r706) +++ trunk/openbios-devel/arch/sparc64/elfload.c Fri Mar 26 21:25:04 2010 (r707) @@ -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 @@ 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 @@ } } out: - file_close(); + close_io(fd); if (buf) free(buf); return retval; @@ -147,9 +148,9 @@ 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 @@
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 @@ 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 @@
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 @@ retval = 0;
out: - file_close(); + close_io(fd); if (phdr) free(phdr); if (boot_notes)
Modified: trunk/openbios-devel/arch/sparc64/fcodeload.c ============================================================================== --- trunk/openbios-devel/arch/sparc64/fcodeload.c Thu Mar 25 22:14:00 2010 (r706) +++ trunk/openbios-devel/arch/sparc64/fcodeload.c Fri Mar 26 21:25:04 2010 (r707) @@ -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 @@ 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 @@
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 @@ retval = 0;
out: - file_close(); + close_io(fd); return retval; }
Modified: trunk/openbios-devel/arch/sparc64/forthload.c ============================================================================== --- trunk/openbios-devel/arch/sparc64/forthload.c Thu Mar 25 22:14:00 2010 (r706) +++ trunk/openbios-devel/arch/sparc64/forthload.c Fri Mar 26 21:25:04 2010 (r707) @@ -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 @@ 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");
Modified: trunk/openbios-devel/arch/sparc64/linux_load.c ============================================================================== --- trunk/openbios-devel/arch/sparc64/linux_load.c Thu Mar 25 22:14:00 2010 (r706) +++ trunk/openbios-devel/arch/sparc64/linux_load.c Fri Mar 26 21:25:04 2010 (r707) @@ -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 @@ };
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 @@ 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 @@ 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 @@ 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 @@ #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 @@ 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 @@ }
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 @@ params->initrd_start = start; params->initrd_size = size;
+ close_io(fd); + return 0; }
@@ -586,12 +608,13 @@ 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; }
Modified: trunk/openbios-devel/arch/x86/build.xml ============================================================================== --- trunk/openbios-devel/arch/x86/build.xml Thu Mar 25 22:14:00 2010 (r706) +++ trunk/openbios-devel/arch/x86/build.xml Fri Mar 26 21:25:04 2010 (r707) @@ -16,7 +16,6 @@ <object source="sys_info.c"/> <object source="elfload.c"/> <object source="forthload.c"/> - <object source="loadfs.c"/> <object source="entry.S"/> <object source="xbox/console.c" condition="XBOX"/> <object source="xbox/methods.c" condition="XBOX"/>
Modified: trunk/openbios-devel/arch/x86/elfload.c ============================================================================== --- trunk/openbios-devel/arch/x86/elfload.c Thu Mar 25 22:14:00 2010 (r706) +++ trunk/openbios-devel/arch/x86/elfload.c Fri Mar 26 21:25:04 2010 (r707) @@ -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 @@ 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 @@ 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 @@
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 @@
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; }
Modified: trunk/openbios-devel/arch/x86/forthload.c ============================================================================== --- trunk/openbios-devel/arch/x86/forthload.c Thu Mar 25 22:14:00 2010 (r706) +++ trunk/openbios-devel/arch/x86/forthload.c Fri Mar 26 21:25:04 2010 (r707) @@ -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 @@ 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; }
Modified: trunk/openbios-devel/arch/x86/linux_load.c ============================================================================== --- trunk/openbios-devel/arch/x86/linux_load.c Thu Mar 25 22:14:00 2010 (r706) +++ trunk/openbios-devel/arch/x86/linux_load.c Fri Mar 26 21:25:04 2010 (r707) @@ -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 @@ };
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 @@ 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 @@ 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 @@ 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 @@ #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 @@ 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 @@ }
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 @@ params->initrd_start = start; params->initrd_size = size;
+ close_io(fd); + return 0; }
@@ -612,7 +634,8 @@ 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);