/*- * Open Firmware interfacing Copyright (c) 2004 Tim Kelly/Dialectronics * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /*- * other code Copyright (c) 2000 Tsubai Masanari. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include int of_mfs_open(char *, struct open_file *); int of_mfs_close(struct open_file *); int of_mfs_read(struct open_file *, void *, size_t, size_t *); int of_mfs_write(struct open_file *, void *, size_t, size_t *); off_t of_mfs_seek(struct open_file *, off_t, int); int of_mfs_stat(struct open_file *, struct stat *); static int OF_fd; static int MFS_fd; static int loadAddr; int of_mfs_open(char *path, struct open_file *f) { int chosen, result, oldLoad, len, handle; int read, start; char bootpath[128], *cp, buf[128]; char bootargs[128], *bootstr; char loadstr[128] = "load ", *dest, *cookie; printf("\nof_mfs.c: open\n"); printf("path: %s\n", path); if ((chosen = OF_finddevice("/chosen")) == -1) return ENXIO; bzero(bootpath, sizeof bootpath); bzero(bootargs, sizeof bootargs); OF_getprop(chosen, "bootpath", bootpath, sizeof bootpath); OF_getprop(chosen, "bootargs", bootargs, sizeof bootargs); printf("bootpath: %s\n", bootpath); printf("bootargs: %s\n", bootargs); cp = bootargs; cp += strlen(bootargs); for (; *cp != ','; cp--) { if (cp == bootargs) { cp = NULL; break; } } if (cp != 0) { /* full path to kernel given but path was stripped */ printf("full path\n"); bootstr = bootargs; } else { /* use path relative to bootloader */ #ifdef HAVE_STAND_STRRCHR cp = strrchr(bootpath, ','); #else cp = bootpath; cp += strlen(bootpath); for (; *cp != ','; cp--) { if (cp == bootpath) { cp = NULL; break; } } #endif if (cp == NULL) return ENXIO; strlcpy(cp + 1, path, sizeof(bootpath)); //bootpath + sizeof (bootpath) - (cp + 1)); bootstr = bootpath; } loadAddr = 0x1000000; dest = loadstr+5; strlcpy(dest, bootstr, sizeof loadstr); printf("loading %s...\n", bootstr); OF_fd = OF_open(bootstr); if (OF_fd == -1) { printf("couldn't open %s!\n", bootstr); // OF_enter(); return ENOENT; } if ((handle = OF_finddevice(bootstr)) == -1) { printf("can't convert instance to package\n"); return ENOENT; } if (OF_getprop(handle, "device_type", buf, sizeof buf) < 0) { printf("can't get device_type\n"); len = OF_package_to_path(handle, buf, sizeof buf); printf("handle path: %s\n", buf); return ENOENT; } printf("\n%s opened...\n", bootstr); result = OF_call_method("load", OF_fd, 1, 1, loadAddr, &len); if (!strcmp(buf, "network")) { // OF 1.0.5 enet bug writes 0x200 bytes twice, or something MFS_fd += 0x200; // dynamically check? } /* else { if (!strcmp(buf, "block")) { start = loadAddr; while ((read = OF_read(OF_fd, &start, 0x400000))>0) { len += read; //start += read; } } else { printf("unable to determine device type in of_mfs_open\n"); return ENOENT; } } */ MFS_fd = loadAddr; //cookie = (char*) MFS_fd; if (len < 1) { printf("load failed!"); return ENOENT; } printf("%u bytes loaded!\n", len); return 0; } int of_mfs_close(struct open_file *f) { OF_close(OF_fd); MFS_fd = 0; return 0; } int of_mfs_read(struct open_file *f, void *start, size_t size, size_t *resid) { int len; // file is at a memory address; MFS_fd points to next byte to be read bcopy((char *)MFS_fd, start, size); len = size; size -= len; MFS_fd += len; if (resid) *resid = size; if (len > 0) return 0; else return -1; } int of_mfs_write(struct open_file *f, void *start, size_t size, size_t *resid) { printf("of_mfs.c: write not supported.\n"); return ENXIO; } off_t of_mfs_seek(struct open_file *f, off_t offset, int where) { switch (where) { case SEEK_SET: printf("of_mfs.c:SEEK_SET\n"); MFS_fd = loadAddr + offset; return 0; case SEEK_CUR: printf("of_mfs.c:SEEK_CUR\n"); case SEEK_END: printf("of_mfs.c:SEEK_END\n"); default: return -1; } } int of_mfs_stat(struct open_file *f, struct stat *sb) { return 0; }