changeset 217:30a173257f4a

gsm-fw/services/ffs: ffs_target.c generation and compilation
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 06 Jan 2014 08:07:36 +0000
parents 0eb85790c0ed
children fee45482aa2a
files .hgignore gsm-fw/services/ffs/Makefile gsm-fw/services/ffs/ffs.c gsm-fw/services/ffs/mktarget.pl
diffstat 4 files changed, 215 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Mon Jan 06 07:23:36 2014 +0000
+++ b/.hgignore	Mon Jan 06 08:07:36 2014 +0000
@@ -10,6 +10,7 @@
 ^gsm-fw/finlink/.*\.ld$
 ^gsm-fw/finlink/.*\.map$
 ^gsm-fw/include/config\.
+^gsm-fw/services/ffs/ffs_target
 
 ^loadtools/fc-iram$
 ^loadtools/fc-loadtool$
--- a/gsm-fw/services/ffs/Makefile	Mon Jan 06 07:23:36 2014 +0000
+++ b/gsm-fw/services/ffs/Makefile	Mon Jan 06 08:07:36 2014 +0000
@@ -2,7 +2,8 @@
 CFLAGS=	-O2 -fno-builtin -mthumb-interwork -mthumb
 LD=	arm-elf-ld
 
-OBJS=	cfgffs.o core.o drv.o ffs_env.o ffstrace.o fsck.o reclaim.o task.o
+OBJS=	cfgffs.o core.o drv.o ffs_env.o ffs_target.o ffstrace.o fsck.o \
+	reclaim.o task.o
 
 HDRS=	core.h drv.h ffs.h ffs_api.h ffs_env.h ffs_pool_size.h ffstrace.h \
 	intctl.h ramffs.h task.h tmffs.h
@@ -11,8 +12,11 @@
 
 ${OBJS}:	${HDRS}
 
+ffs_target.c:	ffs.c mktarget.pl
+	./mktarget.pl
+
 xipcode.o:	${OBJS}
 	${LD} -r -o $@ ${OBJS}
 
 clean:
-	rm -f *.[oa] *errs
+	rm -f *.[oa] *errs ffs_target.c
--- a/gsm-fw/services/ffs/ffs.c	Mon Jan 06 07:23:36 2014 +0000
+++ b/gsm-fw/services/ffs/ffs.c	Mon Jan 06 08:07:36 2014 +0000
@@ -8,12 +8,10 @@
  *
 f ******************************************************************************/
 
-#ifndef TARGET
-#include "ffs.cfg"
-#endif
+#include "ffs.h"
 
 #if ((TARGET == 1) || (RIV_ENV== 1))
-#include "ffs/board/task.h"
+#include "task.h"
 #endif
 
 #if (TARGET == 0) 
@@ -23,9 +21,8 @@
 #include <string.h>
 #include <limits.h>
 
-#include "ffs/ffs.h"
-#include "ffs/board/core.h"
-#include "ffs/board/ffstrace.h"
+#include "core.h"
+#include "ffstrace.h"
 
 /******************************************************************************
  *
@@ -95,7 +92,7 @@
     else {
         // Object found, continue like fupdate()
         if (is_open_option(option, (FFS_O_CREATE)) 
-			&& is_open_option(option, (FFS_O_EXCL)))
+	    && is_open_option(option, (FFS_O_EXCL)))
             return EFFS_EXISTS;
 
         if (get_fdi(i) >= 0) 
@@ -143,7 +140,7 @@
 
         chunk_size = (size_remaining > fs.chunk_size_max ? 
                       fs.chunk_size_max : size_remaining);
-        
+
         journal_begin(0);
         
         if ((i = segment_create((char*) src + size - size_remaining,
@@ -279,7 +276,7 @@
     iref_t i;
  
     tw(tr(TR_FUNC, TrApi, "ffs_stat('%s', ?) ?\n", name));
-	ttw(ttr(TTrApi, "ffs_stat('%s', ?) ?" NL, name)); 
+    ttw(ttr(TTrApi, "ffs_stat('%s', ?) ?" NL, name)); 
 
     if (name == NULL)
         return EFFS_BADNAME;
@@ -298,7 +295,7 @@
     iref_t i;
  
     tw(tr(TR_FUNC, TrApi, "ffs_lstat('%s', ?) ?\n", name));
-	ttw(ttr(TTrApi, "ffs_lstat('%s', ?) ?" NL, name)); 
+    ttw(ttr(TTrApi, "ffs_lstat('%s', ?) ?" NL, name)); 
 
     if ((i = ffs_begin()) == EFFS_OK) {
         if ((i = object_stat(name, (struct xstat_s*)stat, 1, 0, 0)) > 0)
@@ -313,7 +310,7 @@
     iref_t i;
  
     tw(tr(TR_FUNC, TrApi, "ffs_xlstat('%s', ?) ?\n", name));
-	ttw(ttr(TTrApi, "ffs_xlstat('%s', ?) ?" NL, name)); 
+    ttw(ttr(TTrApi, "ffs_xlstat('%s', ?) ?" NL, name)); 
 
     if ((i = ffs_begin()) == EFFS_OK) {
         if ((i = object_stat(name, stat, 1, 0, 1)) > 0)
@@ -328,7 +325,7 @@
     iref_t i;
  
     tw(tr(TR_FUNC, TrApi, "ffs_fstat('%d', ?) ?\n", fdi));
-	ttw(ttr(TTrApi, "ffs_fstat('%d', ?) ?" NL, fdi)); 
+    ttw(ttr(TTrApi, "ffs_fstat('%d', ?) ?" NL, fdi)); 
 
     if ((i = ffs_begin()) == EFFS_OK) {
         if ((i = object_stat( 0, (struct xstat_s*) stat, 0, fdi, 0)) > 0)
@@ -346,7 +343,7 @@
     int size;
 
     tw(tr(TR_FUNC, TrApi, "ffs_symlink('%s', '%s') ?\n", pathname, src));
-	ttw(ttr(TTrApi, "ffs_symlink('%s', '%s') ?" NL, pathname, src)); 
+    ttw(ttr(TTrApi, "ffs_symlink('%s', '%s') ?" NL, pathname, src)); 
 
     // TASKBEGIN effs_t SYMLINK(path=pathname, src=src) iref_t i, dir; int size; char *name;
 
@@ -414,7 +411,7 @@
     iref_t i;
 
     tw(tr(TR_FUNC, TrApi, "ffs_remove('%s')\n", pathname));
-	ttw(ttr(TTrApi, "ffs_remove('%s') ?" NL, pathname)); 
+    ttw(ttr(TTrApi, "ffs_remove('%s') ?" NL, pathname)); 
 
     // TASKBEGIN effs_t REMOVE(path=pathname) iref_t i;
 
@@ -463,8 +460,8 @@
 
     tw(tr(TR_FUNC, TrApi, "ffs_fcontrol('%s', %d, 0x%x) ?\n",
           pathname, action, param));
-	ttw(ttr(TTrApi, "ffs_fcontrol('%s', %d, 0x%x) ?" NL, 
-			pathname, action, param)); 
+    ttw(ttr(TTrApi, "ffs_fcontrol('%s', %d, 0x%x) ?" NL, 
+	    pathname, action, param)); 
 
     // TASKBEGIN effs_t FCONTROL(path=pathname, value16=action, size=param) iref_t i;
 
@@ -518,7 +515,7 @@
     struct inode_s *ip;
 
     tw(tr(TR_FUNC, TrApi, "ffs_rename('%s', '%s') ?\n", pathname, newname));
-	ttw(ttr(TTrApi, "ffs_rename('%s', '%s') ?" NL, pathname, newname)); 
+    ttw(ttr(TTrApi, "ffs_rename('%s', '%s') ?" NL, pathname, newname)); 
 
     // TASKBEGIN effs_t RENAME(path=pathname, src=newname) iref_t i, oldi, dir; char *name; struct inode_s *ip;
 
@@ -600,8 +597,8 @@
     char *name;
 
     tw(tr(TR_FUNC, TrApi, "ffs_mkdir('%s')\n", pathname));
-	ttw(ttr(TTrApi, "ffs_mkdir('%s') ?" NL, pathname)); 
-	
+    ttw(ttr(TTrApi, "ffs_mkdir('%s') ?" NL, pathname)); 
+
     // TASKBEGIN effs_t MKDIR(path=pathname) iref_t i, dir; char *name;
 
     if (fs.initerror)
@@ -648,7 +645,7 @@
     int i;
 
     tw(tr(TR_FUNC, TrApi, "ffs_opendir('%s', ?)\n", name));
-	ttw(ttr(TTrApi, "ffs_opendir('%s', ?) ?" NL, name)); 
+    ttw(ttr(TTrApi, "ffs_opendir('%s', ?) ?" NL, name)); 
 
     if (dir == NULL)
         return EFFS_INVALID;
@@ -672,7 +669,7 @@
     iref_t i;
 
     tw(tr(TR_BEGIN, TrApi, "ffs_readdir(?, ?, ?) {\n"));
-	ttw(ttr(TTrApi, "ffs_readdir(?, ?, ?) ?" NL)); 
+    ttw(ttr(TTrApi, "ffs_readdir(?, ?, ?) ?" NL)); 
 
     if (dir == NULL || name == NULL || size < 0) {
         tw(tr(TR_END, TrApi, "} %d\n", EFFS_INVALID));
@@ -700,20 +697,20 @@
             struct ffs_blocking_s *fb)
 {
     effs_t i;
-	
+
     tw(tr(TR_BEGIN, TrApi, "ffs_format('%s', 0x%x) {\n", name, magic));
-	ttw(ttr(TTrApi, "ffs_format('%s', 0x%x) ?" NL, name, magic)); 
+    ttw(ttr(TTrApi, "ffs_format('%s', 0x%x) ?" NL, name, magic)); 
 
     // TASKBEGIN effs_t FORMAT(path=name, size=magic) iref_t i;
-	
+
     if (magic != 0x2BAD) {
         tw(tr(TR_END, TrApi, "} %d\n", EFFS_INVALID));
         return EFFS_INVALID;
     }
 
-	if (name == NULL) {
+    if (name == NULL) {
         name = "/ffs-5.54";
-	}
+    }
 
     if (*name != '/') {
         tw(tr(TR_END, TrApi, "} %d\n", EFFS_BADNAME));
@@ -759,7 +756,7 @@
     effs_t i;
 
     tw(tr(TR_BEGIN, TrApi, "ffs_preformat(0x%x) {\n", magic));
-	ttw(ttr(TTrApi, "ffs_preformat(0x%x) ?" NL, magic)); 
+    ttw(ttr(TTrApi, "ffs_preformat(0x%x) ?" NL, magic)); 
 
     // TASKBEGIN effs_t PREFORMAT(path="/", size=magic) effs_t i;
 
@@ -819,7 +816,7 @@
     struct inode_s *ip;
     
     tw(tr(TR_FUNC, TrApi, "ffs_open('%s', 0x%x) ?\n", pathname, option));
-	ttw(ttr(TTrApi, "ffs_open('%s', 0x%x) ?" NL, pathname, option)); 
+    ttw(ttr(TTrApi, "ffs_open('%s', 0x%x) ?" NL, pathname, option)); 
 
     // TASKBEGIN fd_t OPEN(path=pathname, value16=option) iref_t i, dir, dummy; char *name; fd_t other_fdi, fdi = 0; int error; struct inode_s *ip;
 
@@ -854,7 +851,7 @@
     // Open one file several times in RD is okay but only one time in WR
     if (i != EFFS_NOTFOUND && (other_fdi = get_fdi(i)) >= 0) {
         if (is_open_option(fs.fd[other_fdi].options, FFS_O_WRONLY) || 
-			is_open_option(option, FFS_O_WRONLY))
+	    is_open_option(option, FFS_O_WRONLY))
             return EFFS_LOCKED;
     }
 
@@ -907,7 +904,7 @@
             fs.link_child = 0;  
             journal_end(0);
 
-			// If any further segments exist then remove them now
+	    // If any further segments exist then remove them now
             if (fs.i_backup > 0) 
                 if ((error = object_remove(fs.i_backup)) < 0)
                     return error;
@@ -936,9 +933,9 @@
     }
 
     // Save data in file descriptor     
-	fs.fd[fdi].seghead = i;    
-	fs.fd[fdi].options = option;  
- 
+    fs.fd[fdi].seghead = i;    
+    fs.fd[fdi].options = option;  
+
     return fdi + FFS_FD_OFFSET;
 
     // TASKEND
@@ -967,7 +964,7 @@
     int error;
 
     tw(tr(TR_FUNC, TrApi, "ffs_close(%d) ?\n", fdi));  
-	ttw(ttr(TTrApi, "ffs_close(%d) ?" NL, fdi)); 
+    ttw(ttr(TTrApi, "ffs_close(%d) ?" NL, fdi)); 
 
     // TASKBEGIN effs_t CLOSE(fdi=fdi) iref_t i; int error;
 
@@ -1055,9 +1052,9 @@
             return error;
     }
 
-	size_done = 0;
-	size_remaining = amount;
-    
+    size_done = 0;
+    size_remaining = amount;
+
     do {       
         if (!fs.fd[fdi].dirty ) {   
             // Buffer is not dirty so find the chunk that fp points to.
@@ -1078,16 +1075,16 @@
             }
         }
        
-		fs.fd[fdi].dirty = 1;
-		fp_offset = fs.fd[fdi].fp - fs.fd[fdi].wfp;
+	fs.fd[fdi].dirty = 1;
+	fp_offset = fs.fd[fdi].fp - fs.fd[fdi].wfp;
 
         // Fill the buffer to max or just add the rest
         size = fs.chunk_size_max - fp_offset;
 
-		if (size_remaining <= fs.chunk_size_max - fp_offset)
+	if (size_remaining <= fs.chunk_size_max - fp_offset)
                 size = size_remaining;
-       
-		tw(tr(TR_FUNC, TrApi, "Copy data to buffer (size: %d)\n", size));
+
+	tw(tr(TR_FUNC, TrApi, "Copy data to buffer (size: %d)\n", size));
 
         memcpy(fs.fd[fdi].buf + fp_offset, (uint8*)src + size_done, 
                size);
@@ -1152,7 +1149,7 @@
 req_id_t ffs_seek_b(fd_t fdi, int offset, int whence, T_RV_RETURN *cp, 
                struct ffs_blocking_s *fb)
 {
-	effs_t error;
+    effs_t error;
     int fp_new;
 
     tw(tr(TR_FUNC, TrApi, "ffs_seek(%d, %d, %d) ?\n", fdi, offset, whence));
@@ -1311,4 +1308,3 @@
 {
     return ffs_fdatasync_b(fdi, cp, 0);
 }
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/services/ffs/mktarget.pl	Mon Jan 06 08:07:36 2014 +0000
@@ -0,0 +1,167 @@
+#!/usr/bin/perl -w
+#
+# mktarget.pl by Mads Meisner-Jensen (mmj@ti.com)
+#
+# Auto-generate target code from ffs.c source file.
+#
+
+$FFSPATH = shift;
+if (!defined($FFSPATH) || $FFSPATH eq "") {
+    $FFSPATH = ".";
+}
+
+$OUTPATH = shift;
+if (!defined($OUTPATH) || $OUTPATH eq "") {
+  $OUTPATH = $FFSPATH;
+}
+
+$verbose = 1;
+
+$STATE_OUTSIDE = 0;
+$STATE_IN_FUNCTION = 1;
+$STATE_IN_TASK = 2;
+$state = $STATE_OUTSIDE;
+
+
+############################################################################
+# Main
+############################################################################
+
+$verbose > 0 && print "mktarget.pl operating in directory '$FFSPATH'\n";
+
+open (FFS, "<$FFSPATH/ffs.c") || die "Failed to open 'ffs.c'";
+print $OUTPATH;
+open (TARGETC, ">$OUTPATH/ffs_target.c") || die "Failed to open 'ffs_target.c'";
+
+target_put("/**********************************************************\n");
+target_put(" *\n");
+target_put(" * This is an auto-generated file. Do NOT edit!\n");
+target_put(" *\n");
+target_put(" **********************************************************/\n\n\n");
+
+while (<FFS>)
+{
+    if ($state == $STATE_OUTSIDE)
+    {
+        target_put($_);
+        if (/^{\s*$/) {
+            $state = $STATE_IN_FUNCTION;
+        }
+    }
+    elsif ($state == $STATE_IN_FUNCTION)
+    {
+        if (/^\s*\/\/\s*TASKBEGIN\s*(\w+)\s*(\w+)\s*\((.*)\)(.*)$/m)
+        {
+            $state = $STATE_IN_TASK;
+
+            $rettype = $1;
+            $func = $2;
+            $funclc = lc($func);
+            
+            @args = split(',', $3);
+            @values = ();
+            @reqmembers = ();
+            foreach (@args) {
+                ($left, $right) = $_ =~ /(\w+)=(.+)/m;
+                push (@reqmembers, $left);
+                push (@values, $right);
+            }
+            
+            @vars = split(';', $4);
+            
+            task_begin();
+        }
+        else
+        {
+            target_put($_);
+            if (/^}\s*$/m) {
+                $state = $STATE_OUTSIDE;
+
+                # Write the task_* code after the function
+                target_put("\n");
+                target_put(@taskcode);
+                @taskcode = ();
+            }
+        }
+    }
+    elsif ($state == $STATE_IN_TASK)
+    {
+        if (/^.*TASKEND.*$/m)
+        {
+            $state = $STATE_IN_FUNCTION;
+
+            foreach (@values) {
+                if (/^[a-zA-Z]+/m) {
+                    task_put("#undef $_\n");
+                }
+            }
+            task_put("\n");
+#            task_put("    return EFFS_OK;\n");
+            task_put("}\n\n");
+        }
+        else {
+            task_put($_);
+        }
+    }
+    else
+    {
+        die "Bad state!";
+    }
+}
+
+close (FFS) || die;
+close (TARGETC) || die;
+
+sub task_put
+{
+    push (@taskcode, @_);
+}
+
+sub target_put
+{
+    print TARGETC @_;
+}
+
+sub task_begin
+{
+    $verbose > 0 && print "ffs_$funclc ($func)\n";
+    $verbose > 1 && print "  args = @args\n";
+    $verbose > 1 && print "    left = @values, right = @reqmembers\n";
+    $verbose > 1 && print "  vars = @vars\n";
+    $verbose > 1 && print "\n";
+
+    task_put("$rettype task_$funclc(struct ffs_req_s *p)\n");
+    task_put("{\n");
+    foreach (@vars) {
+        task_put("   $_;\n");
+    }
+    task_put("\n");
+    for $i (0..$#args) {
+        # If value starts with alpha char, e.g. a variable name
+        if ($values[$i] =~ /^[a-zA-Z]+/m) {
+            task_put("#define $values[$i] p->$reqmembers[$i]\n");
+        }
+    }
+
+    target_put("    {\n");
+    target_put("        struct ffs_req_s *req;\n");
+    target_put("        MSG_ALLOC(req);\n");
+
+    for $i (0..$#args) {
+        # Typecasting is necessary for the sake of the tms470 compiler
+        if ($reqmembers[$i] eq "src") {
+            target_put("        req->$reqmembers[$i] = (char *) $values[$i];\n");
+        }
+        else {
+            target_put("        req->$reqmembers[$i] = $values[$i];\n");
+        }
+    }
+    target_put("        req->request_id = request_id_get();\n");     
+    target_put("        req->fb = fb;\n");     
+    target_put("        req->cp = cp;\n");
+    target_put("        req->cmd = $func;\n");
+    target_put("        MSG_SEND(req);\n");
+    target_put("        return req->request_id;\n");
+    target_put("    }\n");
+
+}