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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
1 /* =================================================================
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
2 *
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
3 * loader_fs.c
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
4 *
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
5 * Routines to read a library from a file system.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
6 *
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
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
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
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
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
39 * =================================================================
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
40 * #####DESCRIPTIONBEGIN####
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
41 *
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
42 * Author(s): Anthony Tonizzo (atonizzo@gmail.com)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
43 * Contributors: nickg@ecoscentric.com
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
44 * Date: 2005-05-13
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
45 * Purpose:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
46 * Description:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
47 *
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
48 * ####DESCRIPTIONEND####
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
49 *
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
50 * =================================================================
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
51 */
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
52
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
53 #include <cyg/infra/diag.h> // For diagnostic printing.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
54 #include <pkgconf/io_fileio.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
55 #include <sys/stat.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
56 #include <stdlib.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
57 #include <stdio.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
58 #include <string.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
59
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
60 #include <pkgconf/objloader.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
61 #include <cyg/objloader/elf.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
62 #include <cyg/objloader/objelf.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
63 #include <cyg/objloader/loader_fs.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
64
2890
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
65 static size_t
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
66 cyg_ldr_fs_read(PELF_OBJECT p, size_t s, size_t n, void *mem)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
67 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
68 return fread(mem, s, n, (FILE*)p->ptr);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
69 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
70
2890
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
71 static cyg_int32
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
72 cyg_ldr_fs_seek(PELF_OBJECT p, cyg_uint32 offs)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
73 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
74 return fseek((FILE*)p->ptr, offs, SEEK_SET);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
75 }
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
76
2890
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
77 static cyg_int32
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
78 cyg_ldr_fs_close(PELF_OBJECT p)
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
79 {
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
80 return fclose((FILE*)p->ptr);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
81 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
82
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
83 PELF_OBJECT
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
84 cyg_ldr_open_library_fs(char *ptr)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
85 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
86 FILE *fp = fopen(ptr, "rb");
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
87 if (fp == NULL)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
88 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
89 cyg_ldr_last_error = "FILE NOT FOUND";
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
90 return (void*)0;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
91 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
92
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
93 // Create a file object to keep track of this library.
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
94 PELF_OBJECT e_obj = (PELF_OBJECT)malloc(sizeof(ELF_OBJECT));
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
95 CYG_ASSERT(e_obj != 0, "Cannot malloc() e_obj");
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
96 if (e_obj == 0)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
97 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
98 cyg_ldr_last_error = "ERROR IN MALLOC";
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
99 fclose(fp);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
100 return (void*)0;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
101 }
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
102 memset(e_obj, 0, sizeof(ELF_OBJECT));
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
103 e_obj->ptr = (CYG_ADDRWORD)fp;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
104 e_obj->mode = CYG_LDR_MODE_FILESYSTEM;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
105
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
106 // Handlers for the file system open.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
107 e_obj->read = cyg_ldr_fs_read;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
108 e_obj->seek = cyg_ldr_fs_seek;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
109 e_obj->close = cyg_ldr_fs_close;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
110 return e_obj;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
111 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
112
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
113 void
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2011
diff changeset
114 cyg_ldr_close_library_fs(PELF_OBJECT p)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
115 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
116 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
117