mirror of
https://gitlab.com/qemu-project/openbios.git
synced 2024-02-13 08:34:06 +08:00
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:
committed by
Mark Cave-Ayland
parent
34d5a76f7e
commit
d66540542d
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -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);
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
#include "kernel/kernel.h"
|
#include "kernel/kernel.h"
|
||||||
#include "arch/common/a.out.h"
|
#include "arch/common/a.out.h"
|
||||||
#include "libopenbios/sys_info.h"
|
#include "libopenbios/sys_info.h"
|
||||||
#include "loadfs.h"
|
#include "libc/diskio.h"
|
||||||
#include "boot.h"
|
#include "boot.h"
|
||||||
#define printf printk
|
#define printf printk
|
||||||
#define debug printk
|
#define debug printk
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
#define addr_fixup(addr) ((addr) & 0x00ffffff)
|
#define addr_fixup(addr) ((addr) & 0x00ffffff)
|
||||||
|
|
||||||
static char *image_name, *image_version;
|
static char *image_name, *image_version;
|
||||||
|
static int fd;
|
||||||
|
|
||||||
static int check_mem_ranges(struct sys_info *info,
|
static int check_mem_ranges(struct sys_info *info,
|
||||||
unsigned long start,
|
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;
|
image_name = image_version = NULL;
|
||||||
|
|
||||||
if (!file_open(filename))
|
fd = open_io(filename);
|
||||||
|
if (!fd)
|
||||||
goto out;
|
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");
|
debug("Can't read a.out header\n");
|
||||||
retval = LOADER_NOT_SUPPORT;
|
retval = LOADER_NOT_SUPPORT;
|
||||||
goto out;
|
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");
|
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 (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);
|
printf("Can't read program text segment (size 0x%lx)\n", ehdr.a_text);
|
||||||
goto out;
|
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);
|
printf("Can't read program data segment (size 0x%lx)\n", ehdr.a_data);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
printf("Can't read program (size 0x%lx)\n", size);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -134,6 +136,6 @@ int aout_load(struct sys_info *info, const char *filename, const void *romvec)
|
|||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
file_close();
|
close_io(fd);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
<object source="elfload.c"/>
|
<object source="elfload.c"/>
|
||||||
<object source="aoutload.c"/>
|
<object source="aoutload.c"/>
|
||||||
<object source="forthload.c"/>
|
<object source="forthload.c"/>
|
||||||
<object source="loadfs.c"/>
|
|
||||||
<object source="romvec.c"/>
|
<object source="romvec.c"/>
|
||||||
<object source="entry.S"/>
|
<object source="entry.S"/>
|
||||||
<object source="vectors.S"/>
|
<object source="vectors.S"/>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include "arch/common/elf_boot.h"
|
#include "arch/common/elf_boot.h"
|
||||||
#include "libopenbios/sys_info.h"
|
#include "libopenbios/sys_info.h"
|
||||||
#include "libopenbios/ipchecksum.h"
|
#include "libopenbios/ipchecksum.h"
|
||||||
#include "loadfs.h"
|
#include "libc/diskio.h"
|
||||||
#include "boot.h"
|
#include "boot.h"
|
||||||
#define printf printk
|
#define printf printk
|
||||||
#define debug printk
|
#define debug printk
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
#define addr_fixup(addr) ((addr) & 0x00ffffff)
|
#define addr_fixup(addr) ((addr) & 0x00ffffff)
|
||||||
|
|
||||||
static char *image_name, *image_version;
|
static char *image_name, *image_version;
|
||||||
|
static int fd;
|
||||||
|
|
||||||
static void *calloc(size_t nmemb, size_t size)
|
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)
|
if (phdr[i].p_type != PT_NOTE)
|
||||||
continue;
|
continue;
|
||||||
buf = malloc(phdr[i].p_filesz);
|
buf = malloc(phdr[i].p_filesz);
|
||||||
file_seek(offset + phdr[i].p_offset);
|
seek_io(fd, offset + phdr[i].p_offset);
|
||||||
if ((uint32_t)lfile_read(buf, phdr[i].p_filesz) != phdr[i].p_filesz) {
|
if ((uint32_t)read_io(fd, buf, phdr[i].p_filesz) != phdr[i].p_filesz) {
|
||||||
printf("Can't read note segment\n");
|
printf("Can't read note segment\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -126,7 +127,7 @@ static unsigned long process_image_notes(Elf_phdr *phdr, int phnum,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
file_close();
|
close_io(fd);
|
||||||
if (buf)
|
if (buf)
|
||||||
free(buf);
|
free(buf);
|
||||||
return retval;
|
return retval;
|
||||||
@@ -147,9 +148,9 @@ static int load_segments(Elf_phdr *phdr, int phnum,
|
|||||||
continue;
|
continue;
|
||||||
debug("segment %d addr:%#x file:%#x mem:%#x ",
|
debug("segment %d addr:%#x file:%#x mem:%#x ",
|
||||||
i, addr_fixup(phdr[i].p_paddr), phdr[i].p_filesz, phdr[i].p_memsz);
|
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... ");
|
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) {
|
!= phdr[i].p_filesz) {
|
||||||
printf("Can't read program segment %d\n", i);
|
printf("Can't read program segment %d\n", i);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -316,11 +317,12 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline,
|
|||||||
|
|
||||||
image_name = image_version = NULL;
|
image_name = image_version = NULL;
|
||||||
|
|
||||||
if (!file_open(filename))
|
fd = open_io(filename);
|
||||||
|
if (!fd)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
for (offset = 0; offset < 16 * 512; offset += 512) {
|
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");
|
debug("Can't read ELF header\n");
|
||||||
retval = LOADER_NOT_SUPPORT;
|
retval = LOADER_NOT_SUPPORT;
|
||||||
goto out;
|
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)
|
if (ehdr.e_ident[EI_MAG0] == ELFMAG0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
file_seek(offset);
|
seek_io(fd, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ehdr.e_ident[EI_MAG0] != ELFMAG0
|
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_size = ehdr.e_phnum * sizeof *phdr;
|
||||||
phdr = malloc(phdr_size);
|
phdr = malloc(phdr_size);
|
||||||
file_seek(offset + ehdr.e_phoff);
|
seek_io(fd, offset + ehdr.e_phoff);
|
||||||
if ((uint32_t)lfile_read(phdr, phdr_size) != phdr_size) {
|
if ((uint32_t)read_io(fd, phdr, phdr_size) != phdr_size) {
|
||||||
printf("Can't read program header\n");
|
printf("Can't read program header\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -397,7 +399,7 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline,
|
|||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
file_close();
|
close_io(fd);
|
||||||
if (phdr)
|
if (phdr)
|
||||||
free(phdr);
|
free(phdr);
|
||||||
if (boot_notes)
|
if (boot_notes)
|
||||||
|
|||||||
@@ -10,12 +10,13 @@
|
|||||||
#include "kernel/kernel.h"
|
#include "kernel/kernel.h"
|
||||||
#include "libopenbios/bindings.h"
|
#include "libopenbios/bindings.h"
|
||||||
#include "libopenbios/sys_info.h"
|
#include "libopenbios/sys_info.h"
|
||||||
#include "loadfs.h"
|
#include "libc/diskio.h"
|
||||||
#include "boot.h"
|
#include "boot.h"
|
||||||
#define printk printk
|
#define printk printk
|
||||||
#define debug printk
|
#define debug printk
|
||||||
|
|
||||||
static char *forthtext=NULL;
|
static char *forthtext=NULL;
|
||||||
|
static int fd;
|
||||||
|
|
||||||
int forth_load(const char *filename)
|
int forth_load(const char *filename)
|
||||||
{
|
{
|
||||||
@@ -23,10 +24,11 @@ int forth_load(const char *filename)
|
|||||||
unsigned long forthsize;
|
unsigned long forthsize;
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
||||||
if (!file_open(filename))
|
fd = open_io(filename);
|
||||||
|
if (!fd)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (lfile_read(magic, 2) != 2) {
|
if (read_io(fd, magic, 2) != 2) {
|
||||||
debug("Can't read magic header\n");
|
debug("Can't read magic header\n");
|
||||||
retval = LOADER_NOT_SUPPORT;
|
retval = LOADER_NOT_SUPPORT;
|
||||||
goto out;
|
goto out;
|
||||||
@@ -38,13 +40,14 @@ int forth_load(const char *filename)
|
|||||||
goto out;
|
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);
|
forthtext = malloc(forthsize+1);
|
||||||
file_seek(0);
|
seek_io(fd, 0);
|
||||||
|
|
||||||
printk("Loading forth source ...");
|
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");
|
printk("Can't read forth text\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#include "libopenbios/bindings.h"
|
#include "libopenbios/bindings.h"
|
||||||
#include "libopenbios/sys_info.h"
|
#include "libopenbios/sys_info.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "loadfs.h"
|
#include "libc/diskio.h"
|
||||||
#include "boot.h"
|
#include "boot.h"
|
||||||
|
|
||||||
#define printf printk
|
#define printf printk
|
||||||
@@ -157,6 +157,25 @@ struct linux_params {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static uint64_t forced_memsize;
|
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 */
|
/* Load the first part the file and check if it's Linux */
|
||||||
static uint32_t load_linux_header(struct linux_header *hdr)
|
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;
|
int load_high;
|
||||||
uint32_t kern_addr;
|
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");
|
debug("Can't read Linux header\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -191,8 +210,8 @@ static uint32_t load_linux_header(struct linux_header *hdr)
|
|||||||
printf("Found Linux");
|
printf("Found Linux");
|
||||||
if (hdr->protocol_version >= 0x200 && hdr->kver_addr) {
|
if (hdr->protocol_version >= 0x200 && hdr->kver_addr) {
|
||||||
char kver[256];
|
char kver[256];
|
||||||
file_seek(hdr->kver_addr + 0x200);
|
seek_io(fd, hdr->kver_addr + 0x200);
|
||||||
if (lfile_read(kver, sizeof kver) != 0) {
|
if (read_io(fd, kver, sizeof kver) != 0) {
|
||||||
kver[255] = 0;
|
kver[255] = 0;
|
||||||
printf(" version %s", kver);
|
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)
|
if (hdr->setup_sects == 0)
|
||||||
hdr->setup_sects = 4;
|
hdr->setup_sects = 4;
|
||||||
kern_offset = (hdr->setup_sects + 1) * 512;
|
kern_offset = (hdr->setup_sects + 1) * 512;
|
||||||
file_seek(kern_offset);
|
seek_io(fd, kern_offset);
|
||||||
kern_size = file_size() - kern_offset;
|
kern_size = file_size() - kern_offset;
|
||||||
debug("offset=%#x addr=%#x size=%#x\n", kern_offset, kern_addr, kern_size);
|
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
|
#endif
|
||||||
|
|
||||||
printf("Loading kernel... ");
|
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");
|
printf("Can't read kernel\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -441,7 +460,8 @@ static int load_initrd(struct linux_header *hdr, uint32_t kern_end,
|
|||||||
uint32_t start, end, size;
|
uint32_t start, end, size;
|
||||||
uint64_t forced;
|
uint64_t forced;
|
||||||
|
|
||||||
if (!file_open(initrd_file)) {
|
fd = open_io(initrd_file);
|
||||||
|
if (!fd) {
|
||||||
printf("Can't open initrd: %s\n", initrd_file);
|
printf("Can't open initrd: %s\n", initrd_file);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -498,7 +518,7 @@ static int load_initrd(struct linux_header *hdr, uint32_t kern_end,
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("Loading initrd... ");
|
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");
|
printf("Can't read initrd\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -507,6 +527,8 @@ static int load_initrd(struct linux_header *hdr, uint32_t kern_end,
|
|||||||
params->initrd_start = start;
|
params->initrd_start = start;
|
||||||
params->initrd_size = size;
|
params->initrd_size = size;
|
||||||
|
|
||||||
|
close_io(fd);
|
||||||
|
|
||||||
return 0;
|
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;
|
uint32_t kern_addr, kern_size;
|
||||||
char *initrd_file = NULL;
|
char *initrd_file = NULL;
|
||||||
|
|
||||||
if (!file_open(file))
|
fd = open_io(file);
|
||||||
|
if (!fd)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
kern_addr = load_linux_header(&hdr);
|
kern_addr = load_linux_header(&hdr);
|
||||||
if (kern_addr == 0) {
|
if (kern_addr == 0) {
|
||||||
file_close();
|
close_io(fd);
|
||||||
return LOADER_NOT_SUPPORT;
|
return LOADER_NOT_SUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -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);
|
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
#define CONFIG_SPARC64_PAGE_SIZE_8KB
|
#define CONFIG_SPARC64_PAGE_SIZE_8KB
|
||||||
#include "arch/common/a.out.h"
|
#include "arch/common/a.out.h"
|
||||||
#include "libopenbios/sys_info.h"
|
#include "libopenbios/sys_info.h"
|
||||||
#include "loadfs.h"
|
#include "libc/diskio.h"
|
||||||
#include "boot.h"
|
#include "boot.h"
|
||||||
#define printf printk
|
#define printf printk
|
||||||
#define debug printk
|
#define debug printk
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
#define addr_fixup(addr) ((addr) & 0x00ffffff)
|
#define addr_fixup(addr) ((addr) & 0x00ffffff)
|
||||||
|
|
||||||
static char *image_name, *image_version;
|
static char *image_name, *image_version;
|
||||||
|
static int fd;
|
||||||
|
|
||||||
static int check_mem_ranges(struct sys_info *info,
|
static int check_mem_ranges(struct sys_info *info,
|
||||||
unsigned long start,
|
unsigned long start,
|
||||||
@@ -62,12 +63,13 @@ int aout_load(struct sys_info *info, const char *filename)
|
|||||||
|
|
||||||
image_name = image_version = NULL;
|
image_name = image_version = NULL;
|
||||||
|
|
||||||
if (!file_open(filename))
|
fd = open_io(filename);
|
||||||
|
if (!fd)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
for (offset = 0; offset < 16 * 512; offset += 512) {
|
for (offset = 0; offset < 16 * 512; offset += 512) {
|
||||||
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");
|
debug("Can't read a.out header\n");
|
||||||
retval = LOADER_NOT_SUPPORT;
|
retval = LOADER_NOT_SUPPORT;
|
||||||
goto out;
|
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");
|
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 (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);
|
printf("Can't read program text segment (size 0x%x)\n", ehdr.a_text);
|
||||||
goto out;
|
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);
|
printf("Can't read program data segment (size 0x%x)\n", ehdr.a_data);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
printf("Can't read program (size 0x%lx)\n", size);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -134,6 +136,6 @@ int aout_load(struct sys_info *info, const char *filename)
|
|||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
file_close();
|
close_io(fd);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
<object source="aoutload.c"/>
|
<object source="aoutload.c"/>
|
||||||
<object source="forthload.c"/>
|
<object source="forthload.c"/>
|
||||||
<object source="fcodeload.c"/>
|
<object source="fcodeload.c"/>
|
||||||
<object source="loadfs.c"/>
|
|
||||||
<object source="ofmem_sparc64.c"/>
|
<object source="ofmem_sparc64.c"/>
|
||||||
<object source="entry.S"/>
|
<object source="entry.S"/>
|
||||||
<object source="vectors.S"/>
|
<object source="vectors.S"/>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include "arch/common/elf_boot.h"
|
#include "arch/common/elf_boot.h"
|
||||||
#include "libopenbios/sys_info.h"
|
#include "libopenbios/sys_info.h"
|
||||||
#include "libopenbios/ipchecksum.h"
|
#include "libopenbios/ipchecksum.h"
|
||||||
#include "loadfs.h"
|
#include "libc/diskio.h"
|
||||||
#include "boot.h"
|
#include "boot.h"
|
||||||
#define printf printk
|
#define printf printk
|
||||||
#define debug printk
|
#define debug printk
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
#define addr_fixup(addr) ((addr) & 0x00ffffff)
|
#define addr_fixup(addr) ((addr) & 0x00ffffff)
|
||||||
|
|
||||||
static char *image_name, *image_version;
|
static char *image_name, *image_version;
|
||||||
|
static int fd;
|
||||||
|
|
||||||
static void *calloc(size_t nmemb, size_t size)
|
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)
|
if (phdr[i].p_type != PT_NOTE)
|
||||||
continue;
|
continue;
|
||||||
buf = malloc(phdr[i].p_filesz);
|
buf = malloc(phdr[i].p_filesz);
|
||||||
file_seek(offset + phdr[i].p_offset);
|
seek_io(fd, offset + phdr[i].p_offset);
|
||||||
if ((uint64_t)lfile_read(buf, phdr[i].p_filesz) != phdr[i].p_filesz) {
|
if ((uint64_t)read_io(fd, buf, phdr[i].p_filesz) != phdr[i].p_filesz) {
|
||||||
printf("Can't read note segment\n");
|
printf("Can't read note segment\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -126,7 +127,7 @@ static unsigned long process_image_notes(Elf_phdr *phdr, int phnum,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
file_close();
|
close_io(fd);
|
||||||
if (buf)
|
if (buf)
|
||||||
free(buf);
|
free(buf);
|
||||||
return retval;
|
return retval;
|
||||||
@@ -147,9 +148,9 @@ static int load_segments(Elf_phdr *phdr, int phnum,
|
|||||||
continue;
|
continue;
|
||||||
debug("segment %d addr:%#llx file:%#llx mem:%#llx ",
|
debug("segment %d addr:%#llx file:%#llx mem:%#llx ",
|
||||||
i, addr_fixup(phdr[i].p_paddr), phdr[i].p_filesz, phdr[i].p_memsz);
|
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... ");
|
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) {
|
!= phdr[i].p_filesz) {
|
||||||
printf("Can't read program segment %d\n", i);
|
printf("Can't read program segment %d\n", i);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -315,11 +316,12 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline)
|
|||||||
|
|
||||||
image_name = image_version = NULL;
|
image_name = image_version = NULL;
|
||||||
|
|
||||||
if (!file_open(filename))
|
fd = open_io(filename);
|
||||||
|
if (!fd)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
for (offset = 0; offset < 16 * 512; offset += 512) {
|
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");
|
debug("Can't read ELF header\n");
|
||||||
retval = LOADER_NOT_SUPPORT;
|
retval = LOADER_NOT_SUPPORT;
|
||||||
goto out;
|
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)
|
if (ehdr.e_ident[EI_MAG0] == ELFMAG0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
file_seek(offset);
|
seek_io(fd, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ehdr.e_ident[EI_MAG0] != ELFMAG0
|
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_size = ehdr.e_phnum * sizeof *phdr;
|
||||||
phdr = malloc(phdr_size);
|
phdr = malloc(phdr_size);
|
||||||
file_seek(offset + ehdr.e_phoff);
|
seek_io(fd, offset + ehdr.e_phoff);
|
||||||
if ((unsigned long)lfile_read(phdr, phdr_size) != phdr_size) {
|
if ((unsigned long)read_io(fd, phdr, phdr_size) != phdr_size) {
|
||||||
printf("Can't read program header\n");
|
printf("Can't read program header\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -402,7 +404,7 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline)
|
|||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
file_close();
|
close_io(fd);
|
||||||
if (phdr)
|
if (phdr)
|
||||||
free(phdr);
|
free(phdr);
|
||||||
if (boot_notes)
|
if (boot_notes)
|
||||||
|
|||||||
@@ -6,11 +6,13 @@
|
|||||||
#include "kernel/kernel.h"
|
#include "kernel/kernel.h"
|
||||||
#include "libopenbios/bindings.h"
|
#include "libopenbios/bindings.h"
|
||||||
#include "libopenbios/sys_info.h"
|
#include "libopenbios/sys_info.h"
|
||||||
#include "loadfs.h"
|
#include "libc/diskio.h"
|
||||||
#include "boot.h"
|
#include "boot.h"
|
||||||
#define printf printk
|
#define printf printk
|
||||||
#define debug printk
|
#define debug printk
|
||||||
|
|
||||||
|
static int fd;
|
||||||
|
|
||||||
int fcode_load(const char *filename)
|
int fcode_load(const char *filename)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
@@ -18,12 +20,13 @@ int fcode_load(const char *filename)
|
|||||||
unsigned long start, size;
|
unsigned long start, size;
|
||||||
unsigned int offset;
|
unsigned int offset;
|
||||||
|
|
||||||
if (!file_open(filename))
|
fd = open_io(filename);
|
||||||
|
if (!fd)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
for (offset = 0; offset < 16 * 512; offset += 512) {
|
for (offset = 0; offset < 16 * 512; offset += 512) {
|
||||||
file_seek(offset);
|
seek_io(fd, offset);
|
||||||
if (lfile_read(&fcode_header, sizeof(fcode_header))
|
if (read_io(fd, &fcode_header, sizeof(fcode_header))
|
||||||
!= sizeof(fcode_header)) {
|
!= sizeof(fcode_header)) {
|
||||||
debug("Can't read FCode header from file %s\n", filename);
|
debug("Can't read FCode header from file %s\n", filename);
|
||||||
retval = LOADER_NOT_SUPPORT;
|
retval = LOADER_NOT_SUPPORT;
|
||||||
@@ -51,9 +54,9 @@ int fcode_load(const char *filename)
|
|||||||
|
|
||||||
printf("Loading FCode image...\n");
|
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);
|
printf("Can't read file (size 0x%lx)\n", size);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -70,6 +73,6 @@ int fcode_load(const char *filename)
|
|||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
file_close();
|
close_io(fd);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,22 +10,25 @@
|
|||||||
#include "kernel/kernel.h"
|
#include "kernel/kernel.h"
|
||||||
#include "libopenbios/bindings.h"
|
#include "libopenbios/bindings.h"
|
||||||
#include "libopenbios/sys_info.h"
|
#include "libopenbios/sys_info.h"
|
||||||
#include "loadfs.h"
|
#include "libc/diskio.h"
|
||||||
#include "boot.h"
|
#include "boot.h"
|
||||||
#define printk printk
|
#define printk printk
|
||||||
#define debug printk
|
#define debug printk
|
||||||
|
|
||||||
static char *forthtext=NULL;
|
static char *forthtext=NULL;
|
||||||
|
static int fd;
|
||||||
|
|
||||||
int forth_load(const char *filename)
|
int forth_load(const char *filename)
|
||||||
{
|
{
|
||||||
char magic[2];
|
char magic[2];
|
||||||
unsigned long forthsize;
|
unsigned long forthsize;
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
||||||
if (!file_open(filename))
|
fd = open_io(filename);
|
||||||
|
if (!fd)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (lfile_read(magic, 2) != 2) {
|
if (read_io(fd, magic, 2) != 2) {
|
||||||
debug("Can't read magic header\n");
|
debug("Can't read magic header\n");
|
||||||
retval = LOADER_NOT_SUPPORT;
|
retval = LOADER_NOT_SUPPORT;
|
||||||
goto out;
|
goto out;
|
||||||
@@ -37,19 +40,22 @@ int forth_load(const char *filename)
|
|||||||
goto out;
|
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);
|
forthtext = malloc(forthsize+1);
|
||||||
file_seek(0);
|
seek_io(fd, 0);
|
||||||
|
|
||||||
printk("Loading forth source ...");
|
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");
|
printk("Can't read forth text\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
forthtext[forthsize]=0;
|
forthtext[forthsize]=0;
|
||||||
printk("ok\n");
|
printk("ok\n");
|
||||||
|
|
||||||
|
close_io(fd);
|
||||||
|
|
||||||
PUSH ( (ucell)forthtext );
|
PUSH ( (ucell)forthtext );
|
||||||
PUSH ( (ucell)forthsize );
|
PUSH ( (ucell)forthsize );
|
||||||
fword("eval2");
|
fword("eval2");
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#include "libopenbios/bindings.h"
|
#include "libopenbios/bindings.h"
|
||||||
#include "libopenbios/sys_info.h"
|
#include "libopenbios/sys_info.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "loadfs.h"
|
#include "libc/diskio.h"
|
||||||
#include "boot.h"
|
#include "boot.h"
|
||||||
|
|
||||||
#define printf printk
|
#define printf printk
|
||||||
@@ -157,6 +157,25 @@ struct linux_params {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static uint64_t forced_memsize;
|
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 */
|
/* Load the first part the file and check if it's Linux */
|
||||||
static uint32_t load_linux_header(struct linux_header *hdr)
|
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;
|
int load_high;
|
||||||
uint32_t kern_addr;
|
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");
|
debug("Can't read Linux header\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -191,8 +210,8 @@ static uint32_t load_linux_header(struct linux_header *hdr)
|
|||||||
printf("Found Linux");
|
printf("Found Linux");
|
||||||
if (hdr->protocol_version >= 0x200 && hdr->kver_addr) {
|
if (hdr->protocol_version >= 0x200 && hdr->kver_addr) {
|
||||||
char kver[256];
|
char kver[256];
|
||||||
file_seek(hdr->kver_addr + 0x200);
|
seek_io(fd, hdr->kver_addr + 0x200);
|
||||||
if (lfile_read(kver, sizeof kver) != 0) {
|
if (read_io(fd, kver, sizeof kver) != 0) {
|
||||||
kver[255] = 0;
|
kver[255] = 0;
|
||||||
printf(" version %s", kver);
|
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)
|
if (hdr->setup_sects == 0)
|
||||||
hdr->setup_sects = 4;
|
hdr->setup_sects = 4;
|
||||||
kern_offset = (hdr->setup_sects + 1) * 512;
|
kern_offset = (hdr->setup_sects + 1) * 512;
|
||||||
file_seek(kern_offset);
|
seek_io(fd, kern_offset);
|
||||||
kern_size = file_size() - kern_offset;
|
kern_size = file_size() - kern_offset;
|
||||||
debug("offset=%#x addr=%#x size=%#x\n", kern_offset, kern_addr, kern_size);
|
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
|
#endif
|
||||||
|
|
||||||
printf("Loading kernel... ");
|
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");
|
printf("Can't read kernel\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -441,7 +460,8 @@ static int load_initrd(struct linux_header *hdr, uint32_t kern_end,
|
|||||||
uint32_t start, end, size;
|
uint32_t start, end, size;
|
||||||
uint64_t forced;
|
uint64_t forced;
|
||||||
|
|
||||||
if (!file_open(initrd_file)) {
|
fd = open_io(initrd_file);
|
||||||
|
if (!fd) {
|
||||||
printf("Can't open initrd: %s\n", initrd_file);
|
printf("Can't open initrd: %s\n", initrd_file);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -498,7 +518,7 @@ static int load_initrd(struct linux_header *hdr, uint32_t kern_end,
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("Loading initrd... ");
|
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");
|
printf("Can't read initrd\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -507,6 +527,8 @@ static int load_initrd(struct linux_header *hdr, uint32_t kern_end,
|
|||||||
params->initrd_start = start;
|
params->initrd_start = start;
|
||||||
params->initrd_size = size;
|
params->initrd_size = size;
|
||||||
|
|
||||||
|
close_io(fd);
|
||||||
|
|
||||||
return 0;
|
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;
|
uint32_t kern_addr, kern_size;
|
||||||
char *initrd_file = NULL;
|
char *initrd_file = NULL;
|
||||||
|
|
||||||
if (!file_open(file))
|
fd = open_io(file);
|
||||||
|
if (!fd)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
kern_addr = load_linux_header(&hdr);
|
kern_addr = load_linux_header(&hdr);
|
||||||
if (kern_addr == 0) {
|
if (kern_addr == 0) {
|
||||||
file_close();
|
close_io(fd);
|
||||||
return LOADER_NOT_SUPPORT;
|
return LOADER_NOT_SUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -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);
|
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
<object source="sys_info.c"/>
|
<object source="sys_info.c"/>
|
||||||
<object source="elfload.c"/>
|
<object source="elfload.c"/>
|
||||||
<object source="forthload.c"/>
|
<object source="forthload.c"/>
|
||||||
<object source="loadfs.c"/>
|
|
||||||
<object source="entry.S"/>
|
<object source="entry.S"/>
|
||||||
<object source="xbox/console.c" condition="XBOX"/>
|
<object source="xbox/console.c" condition="XBOX"/>
|
||||||
<object source="xbox/methods.c" condition="XBOX"/>
|
<object source="xbox/methods.c" condition="XBOX"/>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include "arch/common/elf_boot.h"
|
#include "arch/common/elf_boot.h"
|
||||||
#include "libopenbios/sys_info.h"
|
#include "libopenbios/sys_info.h"
|
||||||
#include "libopenbios/ipchecksum.h"
|
#include "libopenbios/ipchecksum.h"
|
||||||
#include "loadfs.h"
|
#include "libc/diskio.h"
|
||||||
#include "boot.h"
|
#include "boot.h"
|
||||||
|
|
||||||
#define debug printk
|
#define debug printk
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
extern char _start, _end;
|
extern char _start, _end;
|
||||||
|
|
||||||
static char *image_name, *image_version;
|
static char *image_name, *image_version;
|
||||||
|
static int fd;
|
||||||
|
|
||||||
static void *calloc(size_t nmemb, size_t size)
|
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)
|
if (phdr[i].p_type != PT_NOTE)
|
||||||
continue;
|
continue;
|
||||||
buf = malloc(phdr[i].p_filesz);
|
buf = malloc(phdr[i].p_filesz);
|
||||||
file_seek(phdr[i].p_offset);
|
seek_io(fd, phdr[i].p_offset);
|
||||||
if (lfile_read(buf, phdr[i].p_filesz) != phdr[i].p_filesz) {
|
if (read_io(fd, buf, phdr[i].p_filesz) != phdr[i].p_filesz) {
|
||||||
printk("Can't read note segment\n");
|
printk("Can't read note segment\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -149,9 +150,9 @@ static int load_segments(Elf_phdr *phdr, int phnum,
|
|||||||
continue;
|
continue;
|
||||||
debug("segment %d addr:%#x file:%#x mem:%#x ",
|
debug("segment %d addr:%#x file:%#x mem:%#x ",
|
||||||
i, phdr[i].p_paddr, phdr[i].p_filesz, phdr[i].p_memsz);
|
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... ");
|
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) {
|
!= phdr[i].p_filesz) {
|
||||||
printk("Can't read program segment %d\n", i);
|
printk("Can't read program segment %d\n", i);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -316,10 +317,11 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline)
|
|||||||
|
|
||||||
image_name = image_version = NULL;
|
image_name = image_version = NULL;
|
||||||
|
|
||||||
if (!file_open(filename))
|
fd = open_io(filename);
|
||||||
|
if (!fd)
|
||||||
goto out;
|
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");
|
debug("Can't read ELF header\n");
|
||||||
retval = LOADER_NOT_SUPPORT;
|
retval = LOADER_NOT_SUPPORT;
|
||||||
goto out;
|
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_size = ehdr.e_phnum * sizeof *phdr;
|
||||||
phdr = malloc(phdr_size);
|
phdr = malloc(phdr_size);
|
||||||
file_seek(ehdr.e_phoff);
|
seek_io(fd, ehdr.e_phoff);
|
||||||
if (lfile_read(phdr, phdr_size) != phdr_size) {
|
if (read_io(fd, phdr, phdr_size) != phdr_size) {
|
||||||
printk("Can't read program header\n");
|
printk("Can't read program header\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,22 +10,25 @@
|
|||||||
#include "kernel/kernel.h"
|
#include "kernel/kernel.h"
|
||||||
#include "libopenbios/bindings.h"
|
#include "libopenbios/bindings.h"
|
||||||
#include "libopenbios/sys_info.h"
|
#include "libopenbios/sys_info.h"
|
||||||
#include "loadfs.h"
|
#include "libc/diskio.h"
|
||||||
#include "boot.h"
|
#include "boot.h"
|
||||||
#define printk printk
|
#define printk printk
|
||||||
#define debug printk
|
#define debug printk
|
||||||
|
|
||||||
static char *forthtext=NULL;
|
static char *forthtext=NULL;
|
||||||
|
static int fd;
|
||||||
|
|
||||||
int forth_load(struct sys_info *info, const char *filename, const char *cmdline)
|
int forth_load(struct sys_info *info, const char *filename, const char *cmdline)
|
||||||
{
|
{
|
||||||
char magic[2];
|
char magic[2];
|
||||||
unsigned long forthsize;
|
unsigned long forthsize;
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
||||||
if (!file_open(filename))
|
fd = open_io(filename);
|
||||||
|
if (!fd)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (lfile_read(magic, 2) != 2) {
|
if (read_io(fd, magic, 2) != 2) {
|
||||||
debug("Can't read magic header\n");
|
debug("Can't read magic header\n");
|
||||||
retval = LOADER_NOT_SUPPORT;
|
retval = LOADER_NOT_SUPPORT;
|
||||||
goto out;
|
goto out;
|
||||||
@@ -37,13 +40,14 @@ int forth_load(struct sys_info *info, const char *filename, const char *cmdline)
|
|||||||
goto out;
|
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);
|
forthtext = malloc(forthsize+1);
|
||||||
file_seek(0);
|
seek_io(fd, 0);
|
||||||
|
|
||||||
printk("Loading forth source ...");
|
printk("Loading forth source ...");
|
||||||
if (lfile_read(forthtext, forthsize) != forthsize) {
|
if (read_io(fd, forthtext, forthsize) != forthsize) {
|
||||||
printk("Can't read forth text\n");
|
printk("Can't read forth text\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
#include "libopenbios/sys_info.h"
|
#include "libopenbios/sys_info.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "segment.h"
|
#include "segment.h"
|
||||||
#include "loadfs.h"
|
#include "libc/diskio.h"
|
||||||
#include "boot.h"
|
#include "boot.h"
|
||||||
|
|
||||||
#define printf printk
|
#define printf printk
|
||||||
@@ -158,6 +158,25 @@ struct linux_params {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static uint64_t forced_memsize;
|
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 */
|
/* Load the first part the file and check if it's Linux */
|
||||||
static uint32_t load_linux_header(struct linux_header *hdr)
|
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;
|
int load_high;
|
||||||
uint32_t kern_addr;
|
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");
|
debug("Can't read Linux header\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -192,8 +211,8 @@ static uint32_t load_linux_header(struct linux_header *hdr)
|
|||||||
printf("Found Linux");
|
printf("Found Linux");
|
||||||
if (hdr->protocol_version >= 0x200 && hdr->kver_addr) {
|
if (hdr->protocol_version >= 0x200 && hdr->kver_addr) {
|
||||||
char kver[256];
|
char kver[256];
|
||||||
file_seek(hdr->kver_addr + 0x200);
|
seek_io(fd, hdr->kver_addr + 0x200);
|
||||||
if (lfile_read(kver, sizeof kver) != 0) {
|
if (read_io(fd, kver, sizeof kver) != 0) {
|
||||||
kver[255] = 0;
|
kver[255] = 0;
|
||||||
printf(" version %s", kver);
|
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)
|
if (hdr->setup_sects == 0)
|
||||||
hdr->setup_sects = 4;
|
hdr->setup_sects = 4;
|
||||||
kern_offset = (hdr->setup_sects + 1) * 512;
|
kern_offset = (hdr->setup_sects + 1) * 512;
|
||||||
file_seek(kern_offset);
|
seek_io(fd, kern_offset);
|
||||||
kern_size = file_size() - kern_offset;
|
kern_size = file_size() - kern_offset;
|
||||||
debug("offset=%#x addr=%#x size=%#x\n", kern_offset, kern_addr, kern_size);
|
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
|
#endif
|
||||||
|
|
||||||
printf("Loading kernel... ");
|
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");
|
printf("Can't read kernel\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -443,7 +462,8 @@ static int load_initrd(struct linux_header *hdr, struct sys_info *info,
|
|||||||
uint64_t forced;
|
uint64_t forced;
|
||||||
extern char _start[], _end[];
|
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);
|
printf("Can't open initrd: %s\n", initrd_file);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -500,7 +520,7 @@ static int load_initrd(struct linux_header *hdr, struct sys_info *info,
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("Loading initrd... ");
|
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");
|
printf("Can't read initrd\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -509,6 +529,8 @@ static int load_initrd(struct linux_header *hdr, struct sys_info *info,
|
|||||||
params->initrd_start = start;
|
params->initrd_start = start;
|
||||||
params->initrd_size = size;
|
params->initrd_size = size;
|
||||||
|
|
||||||
|
close_io(fd);
|
||||||
|
|
||||||
return 0;
|
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;
|
uint32_t kern_addr, kern_size;
|
||||||
char *initrd_file = NULL;
|
char *initrd_file = NULL;
|
||||||
|
|
||||||
if (!file_open(file))
|
fd = open_io(file);
|
||||||
|
if (!fd)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
kern_addr = load_linux_header(&hdr);
|
kern_addr = load_linux_header(&hdr);
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -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);
|
|
||||||
Reference in New Issue
Block a user