# HG changeset patch # User Michael Spacefalcon # Date 1378072551 0 # Node ID 02ece4d8c755c086200464ec61fd3b9f2227b446 # Parent b78db17bfc85ce10f5ecf0e033ce431caa1a1aa0 pirexplore: beginning of FFS support diff -r b78db17bfc85 -r 02ece4d8c755 target-utils/Makefile --- a/target-utils/Makefile Sun Sep 01 18:59:48 2013 +0000 +++ b/target-utils/Makefile Sun Sep 01 21:55:51 2013 +0000 @@ -1,5 +1,5 @@ PROGS= helloapp loadagent pirexplore -LIBS= libcommon libload libprintf +LIBS= libcommon libload libmpffs libprintf SUBDIR= ${PROGS} ${LIBS} default: loadagent @@ -7,7 +7,7 @@ helloapp: libcommon libprintf loadagent: libcommon libload libprintf -pirexplore: libcommon libprintf +pirexplore: libcommon libmpffs libprintf ${SUBDIR}: FRC cd $@; make ${MFLAGS} diff -r b78db17bfc85 -r 02ece4d8c755 target-utils/libmpffs/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/libmpffs/Makefile Sun Sep 01 21:55:51 2013 +0000 @@ -0,0 +1,16 @@ +CC= arm-elf-gcc +CFLAGS= -Os -fno-builtin +CPPFLAGS=-I../include +AR= arm-elf-ar +RANLIB= arm-elf-ranlib + +OBJS= globals.o init.o + +all: libmpffs.a + +libmpffs.a: ${OBJS} + ${AR} cru $@ ${OBJS} + ${RANLIB} $@ + +clean: + rm -f *.[oa] *errs diff -r b78db17bfc85 -r 02ece4d8c755 target-utils/libmpffs/globals.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/libmpffs/globals.c Sun Sep 01 21:55:51 2013 +0000 @@ -0,0 +1,8 @@ +/* global variables for the MPFFS reader code */ + +#include "types.h" +#include "struct.h" + +struct inode *mpffs_active_index; +int mpffs_root_ino; +int mpffs_init_done; diff -r b78db17bfc85 -r 02ece4d8c755 target-utils/libmpffs/globals.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/libmpffs/globals.h Sun Sep 01 21:55:51 2013 +0000 @@ -0,0 +1,9 @@ +/* global variables for the MPFFS reader code - extern declarations */ + +extern struct inode *mpffs_active_index; +extern int mpffs_root_ino; +extern int mpffs_init_done; + +extern const u32 mpffs_base_addr; +extern const u32 mpffs_sector_size; +extern const int mpffs_nsectors; diff -r b78db17bfc85 -r 02ece4d8c755 target-utils/libmpffs/init.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/libmpffs/init.c Sun Sep 01 21:55:51 2013 +0000 @@ -0,0 +1,74 @@ +#include "types.h" +#include "struct.h" +#include "globals.h" +#include "macros.h" + +static const u8 ffs_sector_signature[6] = {'F', 'f', 's', '#', 0x10, 0x02}; +static const u8 blank_flash_line[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF}; + +static +find_indexblk() +{ + u32 sector_addr; + u8 *sector_ptr; + int i; + + printf("Looking for MPFFS active index block\n"); + sector_addr = mpffs_base_addr; + for (i = 0; i < mpffs_nsectors; i++) { + sector_ptr = (u8 *) sector_addr; + if (!bcmp(sector_ptr, ffs_sector_signature, 6) && + sector_ptr[8] == 0xAB) { + printf("Found at %08X\n", sector_addr); + mpffs_active_index = (struct inode *) sector_ptr; + return(0); + } + sector_addr += mpffs_sector_size; + } + printf("Error: Not found in any of the %d candidate sectors\n", + mpffs_nsectors); + return(-1); +} + +static +find_rootino() +{ + int ino; + struct inode *irec; + + printf("Looking for the root inode\n"); + for (ino = 1; ; ino++) { + if (ino >= mpffs_sector_size >> 4) { + printf("Error: Hit end of sector, no root inode found\n"); + return(-1); + } + irec = mpffs_active_index + ino; + if (!bcmp((u8 *) irec, blank_flash_line, 16)) { + printf("Error: Hit blank flash, no root inode found\n"); + return(-1); + } + if (irec->type == OBJTYPE_DIR && *inode_to_dataptr(irec) == '/') + break; + } + printf("Found at inode #%x\n", ino); + mpffs_root_ino = ino; + return(0); +} + +mpffs_init() +{ + int stat; + + if (mpffs_init_done) + return(0); + stat = find_indexblk(); + if (stat < 0) + return(stat); + stat = find_rootino(); + if (stat < 0) + return(stat); + mpffs_init_done = 1; + return(0); +} diff -r b78db17bfc85 -r 02ece4d8c755 target-utils/libmpffs/macros.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/libmpffs/macros.h Sun Sep 01 21:55:51 2013 +0000 @@ -0,0 +1,1 @@ +#define inode_to_dataptr(i) ((u8 *)mpffs_base_addr + ((i)->dataptr << 4)) diff -r b78db17bfc85 -r 02ece4d8c755 target-utils/libmpffs/struct.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/libmpffs/struct.h Sun Sep 01 21:55:51 2013 +0000 @@ -0,0 +1,25 @@ +struct inode { + u16 len; + u8 reserved1; + u8 type; + u16 descend; + u16 sibling; + u32 dataptr; + u16 sequence; + u16 updates; +}; + +#define OBJTYPE_FILE 0xF1 +#define OBJTYPE_DIR 0xF2 +#define OBJTYPE_SEGMENT 0xF4 + +struct journal { + u8 status; + u8 objtype; + u16 this_ino; + u16 link_ptr; + u16 replacee; + u32 location; + u16 size; + u16 repli; /* ??? */ +}; diff -r b78db17bfc85 -r 02ece4d8c755 target-utils/pirexplore/Makefile --- a/target-utils/pirexplore/Makefile Sun Sep 01 18:59:48 2013 +0000 +++ b/target-utils/pirexplore/Makefile Sun Sep 01 21:55:51 2013 +0000 @@ -5,8 +5,8 @@ OBJCOPY=arm-elf-objcopy PROG= pirexplore -OBJS= crt0.o cmdtab.o lcd.o main.o mygetchar.o rtc.o -LIBS= ../libcommon/libcommon.a ../libprintf/libprintf.a +OBJS= crt0.o cmdtab.o ffsparam.o lcd.o main.o mygetchar.o rtc.o +LIBS= ../libcommon/libcommon.a ../libmpffs/libmpffs.a ../libprintf/libprintf.a LDS= ../env/iram.lds TC_LIBS=`${CC} -print-file-name=libc.a` \ diff -r b78db17bfc85 -r 02ece4d8c755 target-utils/pirexplore/cmdtab.c --- a/target-utils/pirexplore/cmdtab.c Sun Sep 01 18:59:48 2013 +0000 +++ b/target-utils/pirexplore/cmdtab.c Sun Sep 01 21:55:51 2013 +0000 @@ -16,9 +16,12 @@ extern void cmd_w16(); extern void cmd_w32(); +extern void mpffs_init(); + const struct cmdtab cmdtab[] = { {"baud", cmd_baud_switch}, {"dieid", cmd_dieid}, + {"ffsinit", mpffs_init}, {"jump", cmd_jump}, {"lcdfill", cmd_lcdfill}, {"lcdinit", cmd_lcdinit}, diff -r b78db17bfc85 -r 02ece4d8c755 target-utils/pirexplore/ffsparam.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/pirexplore/ffsparam.c Sun Sep 01 21:55:51 2013 +0000 @@ -0,0 +1,11 @@ +/* + * This module is linked into pirexplore for the purpose of telling the + * somewhat generic libmpffs exactly where the FFS is located on this + * device and how it is structured. + */ + +#include "types.h" + +const u32 mpffs_base_addr = 0x02000000; +const u32 mpffs_sector_size = 0x40000; +const int mpffs_nsectors = 18;