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>


git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@707 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
Mark Cave-Ayland
2010-03-26 20:25:04 +00:00
committed by Mark Cave-Ayland
parent 34d5a76f7e
commit d66540542d
23 changed files with 203 additions and 337 deletions

View File

@@ -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"/>

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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);