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
68extern const cfe_loader_t elfloader;
69extern const cfe_loader_t rawloader;
70extern const cfe_loader_t srecloader;
71
72/*  *********************************************************************
73    *  Loader list
74    ********************************************************************* */
75
76const cfe_loader_t * const cfe_loaders[] = {
77    &elfloader,
78    &rawloader,
79#if !CFG_MINIMAL_SIZE
80    &srecloader,
81#endif
82    NULL};
83
84/*  *********************************************************************
85    *  cfe_findloader(name)
86    *
87    *  Find a loader by name
88    *
89    *  Input parameters:
90    *  	   name - name of loader to find
91    *
92    *  Return value:
93    *  	   pointer to loader structure or NULL
94    ********************************************************************* */
95
96const cfe_loader_t *cfe_findloader(char *name)
97{
98    const cfe_loader_t * const *ldr;
99
100    ldr = cfe_loaders;
101
102    while (*ldr) {
103	if (strcmp(name,(*ldr)->name) == 0) return (*ldr);
104	ldr++;
105	}
106
107    return NULL;
108}
109
110
111/*  *********************************************************************
112    *  cfe_load_progam(name,args)
113    *
114    *  Look up a loader and call it.
115    *
116    *  Input parameters:
117    *  	   name - name of loader to run
118    *  	   args - arguments to pass
119    *
120    *  Return value:
121    *  	   return value
122    ********************************************************************* */
123
124int cfe_load_program(char *name,cfe_loadargs_t *la)
125{
126    const cfe_loader_t *ldr;
127    int res;
128
129    ldr = cfe_findloader(name);
130    if (!ldr) return CFE_ERR_LDRNOTAVAIL;
131
132    res = LDRLOAD(ldr,la);
133
134    return res;
135}
136