]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/open-amp.git/blob - lib/common/firmware.c
d296992a63546b47c95209ca76aaa5652e4a5204
[processor-sdk/open-amp.git] / lib / common / firmware.c
1 /*
2  * Copyright (c) 2014, Mentor Graphics Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  *    this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  *    this list of conditions and the following disclaimer in the documentation
12  *    and/or other materials provided with the distribution.
13  * 3. Neither the name of Mentor Graphics Corporation nor the names of its
14  *    contributors may be used to endorse or promote products derived from this
15  *    software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
30 /**************************************************************************
31  * FILE NAME
32  *
33  *       firmware.c
34  *
35  * COMPONENT
36  *
37  *         OpenAMP stack.
38  *
39  * DESCRIPTION
40  *
41  *
42  **************************************************************************/
44 #include <string.h>
45 #include "openamp/firmware.h"
47 /* Start and end addresses of firmware image for remotes. These are defined in the
48  * object files that are obtained by converting the remote ELF Image into object
49  * files. These symbols are not used for remotes.
50  */
51 extern unsigned char _binary_firmware1_start;
52 extern unsigned char _binary_firmware1_end;
54 extern unsigned char _binary_firmware2_start;
55 extern unsigned char _binary_firmware2_end;
57 #define FIRMWARE1_START  (void *)&_binary_firmware1_start
58 #define FIRMWARE1_END    (void *)&_binary_firmware1_end
60 #define FIRMWARE2_START  (void *)&_binary_firmware2_start
61 #define FIRMWARE2_END    (void *)&_binary_firmware2_end
63 /* Init firmware table */
65 const struct firmware_info fw_table[] = { {"firmware1",
66                                            (unsigned int)FIRMWARE1_START,
67                                            (unsigned int)FIRMWARE1_END},
68 {"firmware2", (unsigned int)FIRMWARE2_START,
69  (unsigned int)FIRMWARE2_END}
70 };
72 /**
73  * config_get_firmware
74  *
75  * Searches the given firmware in firmware table list and provides
76  * it to caller.
77  *
78  * @param fw_name    - name of the firmware
79  * @param start_addr - pointer t hold start address of firmware
80  * @param size       - pointer to hold size of firmware
81  *
82  * returns -  status of function execution
83  *
84  */
86 int config_get_firmware(char *fw_name, unsigned int *start_addr,
87                         unsigned int *size)
88 {
89         unsigned int idx;
90         for (idx = 0; idx < sizeof(fw_table) / (sizeof(struct firmware_info));
91              idx++) {
92                 if (!strncmp((char *)fw_table[idx].name, fw_name, sizeof(fw_table[idx].name))) {
93                         *start_addr = fw_table[idx].start_addr;
94                         *size =
95                             fw_table[idx].end_addr - fw_table[idx].start_addr +
96                             1;
97                         return 0;
98                 }
99         }
100         return -1;