source: svn/trunk/newcon3bcm2_21bu/magnum/portinginterface/xvd/7552/bxvd_image.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 7.0 KB
Line 
1/***************************************************************************
2 *    Copyright (c) 2004-2009, Broadcom Corporation
3 *    All Rights Reserved
4 *    Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: bxvd_image.c $
11 * $brcm_Revision: Hydra_Software_Devel/9 $
12 * $brcm_Date: 12/8/09 1:53p $
13 *
14 * Module Description:
15 *       This module contains the code for the XVD FW image
16 *   interface.
17 *
18 * Revision History:
19 *
20 * $brcm_Log: /magnum/portinginterface/xvd/7401/bxvd_image.c $
21 *
22 * Hydra_Software_Devel/9   12/8/09 1:53p davidp
23 * SW7405-3531: Decoder EOC value incorrrectly calculated during
24 * authenticated FW load.
25 *
26 * Hydra_Software_Devel/8   11/13/07 3:09p nilesh
27 * PR36450: FW Image Load now uses inner offset as defined in firmware
28 * file instead of a hard coded value
29 *
30 * Hydra_Software_Devel/7   9/6/07 5:35p nilesh
31 * PR29915: Added BERR_TRACE wrapper around all return codes
32 *
33 * Hydra_Software_Devel/6   8/20/07 11:33a nilesh
34 * PR34118: Removed compilation warning
35 *
36 * Hydra_Software_Devel/5   8/16/07 4:04p nilesh
37 * PR34118: Added support for loading an authenticated FW image using
38 * XVD's built in BIMG interface
39 *
40 * Hydra_Software_Devel/4   12/4/06 12:04p nilesh
41 * PR26289: Changed error reporting during firmware load
42 *
43 * Hydra_Software_Devel/3   11/17/06 4:52p nilesh
44 * PR25868: Merged authenticated image support to mainline
45 *
46 * Hydra_Software_Devel/PR25868/2   11/16/06 5:01p nilesh
47 * PR25868: Removed false authenticated firmware error message
48 *
49 * Hydra_Software_Devel/PR25868/1   11/16/06 3:36p nilesh
50 * PR25868: Added error checking, cleaned up incorrect comments
51 *
52 * Hydra_Software_Devel/2   11/13/06 2:02p nilesh
53 * PR25365: Merged BIMG support to mainline
54 *
55 * Hydra_Software_Devel/PR25365/1   11/10/06 11:06a nilesh
56 * PR25365: Added BIMG support
57 *
58 * Hydra_Software_Devel/1   10/30/06 2:43p pblanco
59 * PR25365: Initial check in
60 *
61 ****************************************************************************/
62#include "bstd.h"
63#include "bkni.h"
64#include "bxvd_image.h"
65#include "bxvd_image_priv.h"
66
67BDBG_MODULE(BXVD_IMAGE);
68
69/* This file contains the reference implementation for XVD's BIMG
70 * firmware retrieval interface.  It provides access to the AVD Core's
71 * inner and outer ELF firmware images using the standard BIMG
72 * interface.  This interface can be overridden by the application by
73 * setting the pImgInterface and pImgContext pointers accordingly.  If
74 * a custom interface/context is used, to save code space, you can
75 * also define BXVD_USE_CUSTOM_IMAGE=1 during compilation to prevent
76 * the default firmware images from being linked in. 
77 *
78 * If a custom interface is provided, the custom BIMG_Next() call MUST
79 * adhere to the following rules:
80 *
81 * - Chunk #0 ALWAYS returns a header of type BXVD_AvdImgHdr.  The
82 *   length should be sizeof(BXVD_AvdImgHdr)
83 *
84 * - Chunk #1-n is the actual firmware image. The provided length can
85 *   be any size, but MUST be the same for all chunks.  The caller
86 *   will know how many bytes of the image is valid
87 *
88 * See
89 * http://twiki-01.broadcom.com/bin/view/Bseavsw/XVDNdsSvpDesign#Updating_XVD_to_use_the_BIMG_Int
90 * for details */
91
92#if !(BXVD_USE_CUSTOM_IMAGE)
93static BERR_Code BXVD_IMAGE_Open(void *context,
94                                 void **image,
95                                 unsigned image_id)
96{
97        BXVD_IMAGE_ContextEntry *pContextEntry = NULL;
98        BXVD_IMAGE_Container *pImageContainer = NULL;
99
100        BDBG_ENTER(BXVD_IMAGE_Open);
101
102        BDBG_ASSERT(context);
103        BDBG_ASSERT(image);
104       
105        /* Validate the firmware ID range */
106        BDBG_MSG(("Validating image ID range"));
107        if (image_id >= BXVD_IMAGE_FirmwareID_Max)
108        {
109                BDBG_ERR(("Invalid image id %d", image_id));
110                return BERR_TRACE(BERR_INVALID_PARAMETER);
111        }
112
113        /* Validate the image referenced by firmware ID exists in the context */
114        pContextEntry = ((BXVD_IMAGE_ContextEntry**)context)[image_id];
115       
116        if (pContextEntry == NULL) {
117                /* A NULL entry does not necessarily mean a hard error
118                 * since we could be trying to load authenticated
119                 * firmware.  So, we fail silently here and expect
120                 * this error to be reported by the caller depending
121                 * on the situation */
122                return BERR_INVALID_PARAMETER;         
123        }
124       
125        /* Allocate an image container struct */
126        BDBG_MSG(("Allocating image container"));
127        pImageContainer = (BXVD_IMAGE_Container*) BKNI_Malloc(sizeof(BXVD_IMAGE_Container));
128        if (pImageContainer == NULL) {
129                BDBG_ERR(("Cannot allocate image container"));
130                return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
131        }
132        BKNI_Memset(pImageContainer, 0, sizeof(BXVD_IMAGE_Container));
133       
134        /* Fill in the image container struct */
135        if ((image_id == BXVD_IMAGE_FirmwareID_eAuthenticated_AVD0) ||
136            (image_id == BXVD_IMAGE_FirmwareID_eAuthenticated_AVD1))
137        {
138           /* The image data is the binary output of the svp_relocate
139            * tool, where the header is followed by relocated
140            * firmware.  We copy the header into our container and
141            * then set the pImageData to start immediately after the
142            * header */
143           BKNI_Memcpy(&pImageContainer->imageHeader, 
144                       pContextEntry->pImageData, 
145                       sizeof(BXVD_AvdImgHdr));
146           pImageContainer->pImageData = (void*) ((uint32_t) pContextEntry->pImageData + sizeof(BXVD_AvdImgHdr));
147        }
148        else
149        {
150           pImageContainer->imageHeader.uiImageSize = *(pContextEntry->puiImageSize);
151           pImageContainer->imageHeader.uiRelocationBase = *(pContextEntry->puiImageOffset);
152           pImageContainer->pImageData = pContextEntry->pImageData;   
153        }
154
155        *image = pImageContainer;
156
157        BDBG_LEAVE(BXVD_IMAGE_Open);
158        return BERR_TRACE(BERR_SUCCESS);
159}
160
161static BERR_Code BXVD_IMAGE_Next(void *image,
162                                 unsigned chunk,
163                                 const void **data,
164                                 uint16_t length)
165{
166        BXVD_IMAGE_Container *pImageContainer = (BXVD_IMAGE_Container*) image;
167
168        BDBG_ENTER(BXVD_IMAGE_Next);
169        BDBG_ASSERT(image);
170        BDBG_ASSERT(data);
171        BSTD_UNUSED(length);
172
173        if (chunk == 0) {
174                BDBG_MSG(("Returning image chunk[%d]: %d bytes of image header", chunk, length));
175
176                /* Validate length requested is same as our header size */
177                if (length != sizeof(BXVD_AvdImgHdr)) {
178                        BDBG_ERR(("Incorrect image header length requested"));
179                        return BERR_TRACE(BERR_INVALID_PARAMETER);                     
180                }
181               
182                /* Return a pointer to the header */
183                *data = &pImageContainer->imageHeader;
184        } else {       
185                BDBG_MSG(("Returning image chunk[%d]: %d bytes of image data", chunk, length));
186                *data = (void *)((uint8_t *)(pImageContainer->pImageData) + (chunk-1)*length);
187        }
188
189        BDBG_LEAVE(BXVD_IMAGE_Next);
190
191        return BERR_TRACE(BERR_SUCCESS); 
192}
193
194static void BXVD_IMAGE_Close(void *image)
195{
196        /* Free the image container struct */
197        BDBG_ENTER(BXVD_IMAGE_Close);
198        if (image != NULL) {
199                BKNI_Free(image);
200        }
201        BDBG_LEAVE(BXVD_IMAGE_Close);
202        return;
203}
204
205const BIMG_Interface BXVD_IMAGE_Interface = 
206{
207        BXVD_IMAGE_Open,
208        BXVD_IMAGE_Next,
209        BXVD_IMAGE_Close
210};
211#endif                                                                                                                                                                           
Note: See TracBrowser for help on using the repository browser.