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