Mercurial > ecos
annotate packages/services/objloader/current/src/loader_fs.c @ 2890:f8dd12428f1d
* cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
src/relocate_arm.c: Eliminate dependency on CYGPKG_IO_FILEIO when
the filesystem loader is not required.
* src/relocate_arm.c : Added relocation software for the ARM .
* src/relocate_i386.c : Added a structure containing the relocation names
for every architecture. Only used (and compiled in) for pretty printing.
* src/relocate_ppc.c :
* include/relocate_arm.h : New header file for src/relocate_arm.c
* cdl/objloader.cdl: Added the option to relocate for the ARM.
* src/objloader.c :
* src/objelf.c : Erased some redundant debug printout and improved the
readability of the rest.
* src/loader_memory.c : Added the code to allow the objloader package
to load libraries from ROM memory, instead from a file system. The various
sections of the library are the copied from ROM to RAM and relocated.
* include/loader_memory.h : New header file for src/loader_memory.c
* src/objloader.c : Added a line to include the loader_memory header
file and code to flush the cache when calling cyg_ldr_find_symbol().
* cdl/objloader.cdl: Added one check boxe for each of the supported ways
of loading libraries (two for now) so that the user can compile out the
loading methods not used.
| author | jld |
|---|---|
| date | Fri, 03 Jul 2009 14:49:44 +0000 |
| parents | 74dbf4c3f2e1 |
| children |
| rev | line source |
|---|---|
| 2011 | 1 /* ================================================================= |
| 2 * | |
| 3 * loader_fs.c | |
| 4 * | |
| 5 * Routines to read a library from a file system. | |
| 6 * | |
| 7 * ================================================================= | |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
8 * ####ECOSGPLCOPYRIGHTBEGIN#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
9 * ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
10 * This file is part of eCos, the Embedded Configurable Operating System. |
|
2890
f8dd12428f1d
* cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents:
2729
diff
changeset
|
11 * Copyright (C) 2005, 2008 Free Software Foundation, Inc. |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
12 * |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
13 * eCos is free software; you can redistribute it and/or modify it under |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
14 * the terms of the GNU General Public License as published by the Free |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
15 * Software Foundation; either version 2 or (at your option) any later |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
16 * version. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
17 * |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
18 * eCos is distributed in the hope that it will be useful, but WITHOUT |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
20 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
21 * for more details. |
| 2011 | 22 * |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
23 * You should have received a copy of the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
24 * along with eCos; if not, write to the Free Software Foundation, Inc., |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
26 * |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
27 * As a special exception, if other files instantiate templates or use |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
28 * macros or inline functions from this file, or you compile this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
29 * and link it with other works to produce a work based on this file, |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
30 * this file does not by itself cause the resulting work to be covered by |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
31 * the GNU General Public License. However the source code for this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
32 * must still be made available in accordance with section (3) of the GNU |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
33 * General Public License v2. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
34 * |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
35 * This exception does not invalidate any other reasons why a work based |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
36 * on this file might be covered by the GNU General Public License. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
37 * ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2243
diff
changeset
|
38 * ####ECOSGPLCOPYRIGHTEND#### |
| 2011 | 39 * ================================================================= |
| 40 * #####DESCRIPTIONBEGIN#### | |
| 41 * | |
| 2243 | 42 * Author(s): Anthony Tonizzo (atonizzo@gmail.com) |
| 2011 | 43 * Contributors: nickg@ecoscentric.com |
| 44 * Date: 2005-05-13 | |
| 45 * Purpose: | |
| 46 * Description: | |
| 47 * | |
| 48 * ####DESCRIPTIONEND#### | |
| 49 * | |
| 50 * ================================================================= | |
| 51 */ | |
| 52 | |
| 53 #include <cyg/infra/diag.h> // For diagnostic printing. | |
| 54 #include <pkgconf/io_fileio.h> | |
| 55 #include <sys/stat.h> | |
| 56 #include <stdlib.h> | |
| 57 #include <stdio.h> | |
| 58 #include <string.h> | |
| 59 | |
| 60 #include <pkgconf/objloader.h> | |
| 61 #include <cyg/objloader/elf.h> | |
| 62 #include <cyg/objloader/objelf.h> | |
| 63 #include <cyg/objloader/loader_fs.h> | |
| 64 | |
|
2890
f8dd12428f1d
* cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents:
2729
diff
changeset
|
65 static size_t |
| 2243 | 66 cyg_ldr_fs_read(PELF_OBJECT p, size_t s, size_t n, void *mem) |
| 2011 | 67 { |
| 2243 | 68 return fread(mem, s, n, (FILE*)p->ptr); |
| 2011 | 69 } |
| 70 | |
|
2890
f8dd12428f1d
* cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents:
2729
diff
changeset
|
71 static cyg_int32 |
| 2243 | 72 cyg_ldr_fs_seek(PELF_OBJECT p, cyg_uint32 offs) |
| 2011 | 73 { |
| 2243 | 74 return fseek((FILE*)p->ptr, offs, SEEK_SET); |
| 75 } | |
| 76 | |
|
2890
f8dd12428f1d
* cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents:
2729
diff
changeset
|
77 static cyg_int32 |
| 2243 | 78 cyg_ldr_fs_close(PELF_OBJECT p) |
| 79 { | |
| 80 return fclose((FILE*)p->ptr); | |
| 2011 | 81 } |
| 82 | |
| 83 PELF_OBJECT | |
| 2243 | 84 cyg_ldr_open_library_fs(char *ptr) |
| 2011 | 85 { |
| 2243 | 86 FILE *fp = fopen(ptr, "rb"); |
| 87 if (fp == NULL) | |
| 2011 | 88 { |
| 89 cyg_ldr_last_error = "FILE NOT FOUND"; | |
| 90 return (void*)0; | |
| 91 } | |
| 92 | |
| 93 // Create a file object to keep track of this library. | |
| 2243 | 94 PELF_OBJECT e_obj = (PELF_OBJECT)malloc(sizeof(ELF_OBJECT)); |
| 95 CYG_ASSERT(e_obj != 0, "Cannot malloc() e_obj"); | |
| 96 if (e_obj == 0) | |
| 2011 | 97 { |
| 98 cyg_ldr_last_error = "ERROR IN MALLOC"; | |
| 2243 | 99 fclose(fp); |
| 2011 | 100 return (void*)0; |
| 101 } | |
| 2243 | 102 memset(e_obj, 0, sizeof(ELF_OBJECT)); |
| 2011 | 103 e_obj->ptr = (CYG_ADDRWORD)fp; |
| 104 e_obj->mode = CYG_LDR_MODE_FILESYSTEM; | |
| 105 | |
| 106 // Handlers for the file system open. | |
| 107 e_obj->read = cyg_ldr_fs_read; | |
| 108 e_obj->seek = cyg_ldr_fs_seek; | |
| 109 e_obj->close = cyg_ldr_fs_close; | |
| 110 return e_obj; | |
| 111 } | |
| 112 | |
| 113 void | |
| 2243 | 114 cyg_ldr_close_library_fs(PELF_OBJECT p) |
| 2011 | 115 { |
| 116 } | |
| 117 |
