From 0365bbb5c58912fd24b3d33b90477d3de5d46d96 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Fri, 15 May 2015 02:06:48 +0200 Subject: fixes and imporvements --- fs/elf.c | 7 ++++--- fs/ext2.c | 9 +++++++-- fs/fs.c | 19 +++++++++++++++---- fs/fs.h | 6 +++--- 4 files changed, 29 insertions(+), 12 deletions(-) (limited to 'fs') diff --git a/fs/elf.c b/fs/elf.c index 241b3ae..f9f479c 100644 --- a/fs/elf.c +++ b/fs/elf.c @@ -69,8 +69,9 @@ Elf32_Phdr; // returns elf entry point uint32_t load_elf(char *name, uint32_t *alloc) { + uint32_t ext2_ramimage= fs_get_root_ext2_ramimage(); - int inode_nr=ext2_filename_to_inode(EXT2_RAM_ADDRESS,name); + int inode_nr=ext2_filename_to_inode(ext2_ramimage,name); if(inode_nr<1)return 0; //TODO: load ELF binary and move this to own compilation unit @@ -80,8 +81,8 @@ uint32_t load_elf(char *name, uint32_t *alloc) uint32_t vaddr=0x08000000; log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"loading %s",name); - ext2_check(EXT2_RAM_ADDRESS); - ext2_inode_content(EXT2_RAM_ADDRESS,inode_nr,vaddr,0x100000); // load 1mb; + ext2_check(ext2_ramimage); + ext2_inode_content(ext2_ramimage,inode_nr,vaddr,0x100000); // load 1mb; log(FOOLOS_MODULE_NAME,FOOLOS_LOG_DEBUG,"ELF File loaded to final destination."); Elf32_Ehdr *elf; diff --git a/fs/ext2.c b/fs/ext2.c index 4a41a24..858b7d6 100644 --- a/fs/ext2.c +++ b/fs/ext2.c @@ -120,7 +120,8 @@ int ext2_check(uint8_t *ram) ram_read(ptr,&super,sizeof(super),1); if(super.ext2_sig!=0xef53){ - panic(FOOLOS_MODULE_NAME,"no ext2 signature found, where ram-image expected!"); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"addr: 0x%08X",ram); + panic(FOOLOS_MODULE_NAME,"no ext2 signature found, where ram-image expected"); } } @@ -134,7 +135,11 @@ ext2_inode ext2_get_inode(uint8_t *ram,int inode_num) uint8_t *ptr=ram+1024; ram_read(ptr,&super,sizeof(super),1); - if(super.ext2_sig!=0xef53)panic(FOOLOS_MODULE_NAME,"no ext2 signature found, where ram-image expected!"); + if(super.ext2_sig!=0xef53) + { + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"addr: 0x%08X",ram); + panic(FOOLOS_MODULE_NAME,"no ext2 signature found, where ram-image expected!"); + } int block_group=(inode_num-1)/super.inodes_per_group; diff --git a/fs/fs.c b/fs/fs.c index 1373afb..fd43c52 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -2,17 +2,28 @@ #include "fs.h" #include "ext2.h" + + +static uint32_t root_ext2_ramimage=0; + // // returns number of entries in the directory specified by name. // fills 0-max into *dirs int fs_readdir(const char *name,fs_dirent *dirs,int max) { - int inode_nr=ext2_filename_to_inode(EXT2_RAM_ADDRESS,name); + + int inode_nr=ext2_filename_to_inode(root_ext2_ramimage,name); if(inode_nr<1)return -1; - return ext2_read_dir(EXT2_RAM_ADDRESS, inode_nr,dirs,max); // TODO: hardcoded, fix this + return ext2_read_dir(root_ext2_ramimage, inode_nr,dirs,max); // TODO: hardcoded, fix this } +void fs_mount(uint32_t ext2_ramimage) +{ + root_ext2_ramimage=ext2_ramimage; +} - - +uint32_t fs_get_root_ext2_ramimage() +{ + return root_ext2_ramimage; +} diff --git a/fs/fs.h b/fs/fs.h index fe35f3f..db6e608 100644 --- a/fs/fs.h +++ b/fs/fs.h @@ -3,9 +3,6 @@ #include - -#define EXT2_RAM_ADDRESS 0x124000 // here the bootloader puts our image - enum FS_FILE_TYPE{ FS_FILE_TYPE_DIR = 1, @@ -20,6 +17,9 @@ typedef struct fs_dirent_struct uint8_t type; char name[256]; }fs_dirent; + int fs_readdir(const char *name,fs_dirent *dirs,int max); +void fs_mount(uint32_t ext2_ramimage); // all you can mount so far is just one single + // ext2 ramimage as root #endif -- cgit v1.2.3