1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  Loader API 				File: cfe_loader.c
5    *
6    *  This is the main API for the program loader.  CFE supports
7    *  multiple "installable" methods for loading programs, allowing
8    *  us to deal with a variety of methods for moving programs
9    *  into memory for execution.
10    *
11    *  Author:  Mitch Lichtenberg (mpl@broadcom.com)
12    *
13    *********************************************************************
14    *
15    *  Copyright 2000,2001,2002,2003
16    *  Broadcom Corporation. All rights reserved.
17    *
18    *  This software is furnished under license and may be used and
19    *  copied only in accordance with the following terms and
20    *  conditions.  Subject to these conditions, you may download,
21    *  copy, install, use, modify and distribute modified or unmodified
22    *  copies of this software in source and/or binary form.  No title
23    *  or ownership is transferred hereby.
24    *
25    *  1) Any source code used, modified or distributed must reproduce
26    *     and retain this copyright notice and list of conditions
27    *     as they appear in the source file.
28    *
29    *  2) No right is granted to use any trade name, trademark, or
30    *     logo of Broadcom Corporation.  The "Broadcom Corporation"
31    *     name may not be used to endorse or promote products derived
32    *     from this software without the prior written permission of
33    *     Broadcom Corporation.
34    *
35    *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
36    *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
37    *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38    *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
39    *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
40    *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
41    *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
42    *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
43    *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
44    *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
45    *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
46    *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
47    *     THE POSSIBILITY OF SUCH DAMAGE.
48    ********************************************************************* */
49
50#include "lib_types.h"
51#include "lib_string.h"
52#include "lib_printf.h"
53
54#include "cfe_error.h"
55
56#include "cfe.h"
57#include "cfe_fileops.h"
58
59#include "cfe_loader.h"
60
61#include "bsp_config.h"
62
63
64/*  *********************************************************************
65    *  Externs
66    ********************************************************************* */
67
68#if CFG_LDR_ELF
69extern const cfe_loader_t elfloader;
70#endif
71extern const cfe_loader_t rawloader;
72#if CFG_LDR_SREC
73extern const cfe_loader_t srecloader;
74#endif
75
76/*  *********************************************************************
77    *  Loader list
78    ********************************************************************* */
79
80const cfe_loader_t * const cfe_loaders[] = {
81#if CFG_LDR_ELF
82    &elfloader,
83#endif
84    &rawloader,
85#if CFG_LDR_SREC
86    &srecloader,
87#endif
88    NULL};
89
90/*  *********************************************************************
91    *  cfe_findloader(name)
92    *
93    *  Find a loader by name
94    *
95    *  Input parameters:
96    *  	   name - name of loader to find
97    *
98    *  Return value:
99    *  	   pointer to loader structure or NULL
100    ********************************************************************* */
101
102const cfe_loader_t *cfe_findloader(char *name)
103{
104    const cfe_loader_t * const *ldr;
105
106    ldr = cfe_loaders;
107
108    while (*ldr) {
109	if (strcmp(name,(*ldr)->name) == 0) return (*ldr);
110	ldr++;
111	}
112
113    return NULL;
114}
115
116
117/*  *********************************************************************
118    *  cfe_load_progam(name,args)
119    *
120    *  Look up a loader and call it.
121    *
122    *  Input parameters:
123    *  	   name - name of loader to run
124    *  	   args - arguments to pass
125    *
126    *  Return value:
127    *  	   return value
128    ********************************************************************* */
129
130int cfe_load_program(char *name,cfe_loadargs_t *la)
131{
132    const cfe_loader_t *ldr;
133    int res;
134
135    ldr = cfe_findloader(name);
136    if (!ldr) return CFE_ERR_LDRNOTAVAIL;
137
138    res = LDRLOAD(ldr,la);
139
140    return res;
141}
142