diff options
author | pancake <pancake@dazo> | 2007-04-20 18:20:22 +0200 |
---|---|---|
committer | pancake <pancake@dazo> | 2007-04-20 18:20:22 +0200 |
commit | b1d0ce2848a79664374f802954b1e4390b11da6d (patch) | |
tree | 4f465ca029401b9afef0372ff1e0c60a43d87b40 /src/fpid.c | |
download | 0xFFFF-b1d0ce2848a79664374f802954b1e4390b11da6d.tar.bz2 |
* Initial commit of 0xFFFF.0.1
This tree contains the same as the 0.1 tarball
Diffstat (limited to 'src/fpid.c')
-rw-r--r-- | src/fpid.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/fpid.c b/src/fpid.c new file mode 100644 index 0000000..93bf205 --- /dev/null +++ b/src/fpid.c @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2007 + * pancake <pancake@youterm.com> + * + * 0xFFFF is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 0xFFFF is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0xFFFF; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "main.h" +#include <stdio.h> +#include <string.h> + +char *fpid_file(char *filename) +{ + FILE *fd; + char buf[512]; + unsigned char *b = (unsigned char *)&buf; + char *piece = NULL; + long size; + + // 2nd : +0x34 = 2NDAPE + // secondary: +0x04 = NOLOScnd + // x-loader : +0x14 = X-LOADER + // xloader8 : +0x0c = NOLOXldr + // kernel : +0x00 = 0000 a0e1 0000 a0e1 + // initfs : <2M...be sure with 3M 0x300000 + + fd = fopen(filename, "r"); + if (fd == NULL) { + printf("Cannot open file '%s'\n", filename); + return NULL; + } + fread(buf, 512, 1, fd); + fseek(fd, 0, SEEK_END); + size = ftell(fd); + fclose(fd); + +#if 0 + if (!memcmp(b+0x34, "2NDAPE", 6)) + return PIECE_2ND; + else +#endif + if (!memcmp(b+0x04, "NOLOScnd", 8)) + return pieces[PIECE_SECONDARY]; + else + if (!memcmp(b+0x14, "X-LOADER", 8)) + return pieces[PIECE_XLOADER]; + else + if (!memcmp(b+0x0c, "NOLOXldr", 8)) // TODO: this is xloader800, not valid on 770? + return pieces[PIECE_XLOADER]; + else + if (!memcmp(b+0x00, "\x00\x00\xa0\xe1\x00\x00\xa0\xe1", 8)) + return pieces[PIECE_KERNEL]; + else + if (!memcmp(b+0x00, "\x85\x19\x01\xe0", 4)) { + /*/ is jffs2 */ + if (size < 0x300000) + return pieces[PIECE_INITFS]; + return pieces[PIECE_ROOTFS]; + } + + return piece; +} |