# HG changeset patch # User Michael Spacefalcon # Date 1390795930 0 # Node ID 48a254ca4493fcef2e0b528019750cd7fc8ed86f # Parent 43642cf7c98c5032cdb7e8b238e3488f7aa8203c TIFFS IVA: mokoffs wrapper written diff -r 43642cf7c98c -r 48a254ca4493 .hgignore --- a/.hgignore Mon Jan 27 03:46:11 2014 +0000 +++ b/.hgignore Mon Jan 27 04:12:10 2014 +0000 @@ -6,6 +6,7 @@ \.srec$ ^ffstools/tiffs-rd/tiffs$ +^ffstools/tiffs-wrappers/mokoffs$ ^gsm-fw/build\.conf$ ^gsm-fw/config\.stamp$ diff -r 43642cf7c98c -r 48a254ca4493 ffstools/tiffs-wrappers/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ffstools/tiffs-wrappers/Makefile Mon Jan 27 04:12:10 2014 +0000 @@ -0,0 +1,18 @@ +CC= gcc +CFLAGS= -O2 +PROGS= mokoffs +INSTBIN=/usr/local/bin + +MOKOFFS_OBJS= installpath.o mokoffs.o + +all: ${PROGS} + +mokoffs: ${MOKOFFS_OBJS} + ${CC} ${CFLAGS} -o $@ ${MOKOFFS_OBJS} + +install: ${PROGS} + mkdir -p ${INSTBIN} + install -c ${PROGS} ${INSTBIN} + +clean: + rm -f *.o *.out *errs ${PROGS} diff -r 43642cf7c98c -r 48a254ca4493 ffstools/tiffs-wrappers/installpath.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ffstools/tiffs-wrappers/installpath.c Mon Jan 27 04:12:10 2014 +0000 @@ -0,0 +1,7 @@ +/* + * Our mokoffs and pirffs wrappers exec the main tiffs binary; in order + * to do it efficiently without execvp etc, we hard-code the pathname + * where that binary is installed. + */ + +char tiffs_prog_pathname[] = "/usr/local/bin/tiffs"; diff -r 43642cf7c98c -r 48a254ca4493 ffstools/tiffs-wrappers/mokoffs.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ffstools/tiffs-wrappers/mokoffs.c Mon Jan 27 04:12:10 2014 +0000 @@ -0,0 +1,86 @@ +/* + * mokoffs is a wrapper around tiffs: we pass the user's command along, + * together with any options, but insert the 64x7 FFS organization argument + * automatically. + */ + +#include +#include +#include +#include +#include + +extern char tiffs_prog_pathname[]; + +char *imgfile; +char *aopt, *ropt; +int fflag; +char **passon_argv; +int passon_argc; +int output_argc; +char **output_argv; + +main(argc, argv) + char **argv; +{ + extern int optind; + extern char *optarg; + int c; + char **sp, **dp; + + while ((c = getopt(argc, argv, "+a:fr:")) != EOF) + switch (c) { + case 'a': + aopt = optarg; + continue; + case 'f': + fflag++; + continue; + case 'r': + ropt = optarg; + continue; + default: +usage: fprintf(stderr, + "usage: %s [global-options] ...\n", + argv[0]); + exit(1); + } + if (argc - optind < 2) + goto usage; + imgfile = argv[optind++]; + passon_argv = argv + optind; + passon_argc = argc - optind; + + output_argc = passon_argc + 3; + if (fflag) + output_argc++; + if (aopt) + output_argc += 2; + if (ropt) + output_argc += 2; + output_argv = malloc(sizeof(char *) * (output_argc + 1)); + if (!output_argv) { + perror("malloc for tiffs argument list"); + exit(1); + } + dp = output_argv; + *dp++ = "tiffs"; + if (fflag) + *dp++ = "-o0x380000"; + if (aopt) { + *dp++ = "-a"; + *dp++ = aopt; + } + if (ropt) { + *dp++ = "-r"; + *dp++ = ropt; + } + *dp++ = imgfile; + *dp++ = "64x7"; + for (sp = passon_argv; *sp; sp++) + *dp++ = *sp; + *dp = 0; + execvp(tiffs_prog_pathname, output_argv); + perror(tiffs_prog_pathname); + exit(1); +}