source: SVN/cambria/redboot/packages/devs/eth/intel/npe/npeDl/current/src/IxNpeDlImageMgr.c @ 1

Last change on this file since 1 was 1, checked in by Tim Harvey, 2 years ago

restored latest version of files from server backup

Signed-off-by: Tim Harvey <tharvey@…>

File size: 5.6 KB
Line 
1/**
2 * @file IxNpeDlImageMgr.c
3 *
4 * @author Intel Corporation
5 * @date 09 January 2002
6 *
7 * @brief This file contains the implementation of the private API for the
8 *        IXP400 NPE Downloader ImageMgr module
9 *
10 *
11 * @par
12 * IXP400 SW Release version 2.3
13 *
14 * -- Copyright Notice --
15 *
16 * @par
17 * Copyright (c) 2001-2005, Intel Corporation.
18 * All rights reserved.
19 *
20 * @par
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
23 * are met:
24 * 1. Redistributions of source code must retain the above copyright
25 *    notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above copyright
27 *    notice, this list of conditions and the following disclaimer in the
28 *    documentation and/or other materials provided with the distribution.
29 * 3. Neither the name of the Intel Corporation nor the names of its contributors
30 *    may be used to endorse or promote products derived from this software
31 *    without specific prior written permission.
32 *
33 *
34 * @par
35 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
36 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * SUCH DAMAGE.
46 *
47 *
48 * @par
49 * -- End of Copyright Notice --
50*/
51
52
53/*
54 * Put the system defined include files required.
55 */
56#include "IxOsal.h"
57
58/*
59 * Put the user defined include files required.
60 */
61#include "IxNpeDlImageMgr_p.h"
62#include "IxNpeDlMacros_p.h"
63
64/*
65 * define the flag which toggles the firmare inclusion
66 */
67#define IX_NPE_MICROCODE_FIRMWARE_INCLUDED 1
68#include "IxNpeMicrocode.h"
69
70/*
71 * Indicates the start of an NPE Image, in new NPE Image Library format.
72 * 2 consecutive occurances indicates the end of the NPE Image Library
73 */
74#define NPE_IMAGE_MARKER 0xfeedf00d
75
76/*
77 * Typedefs whose scope is limited to this file.
78 */
79
80/*
81 * NPE Image Header definition, used in new NPE Image Library format
82 */
83typedef struct
84{
85    UINT32 marker;
86    UINT32 id;
87    UINT32 size;
88} IxNpeDlImageMgrImageHeader;
89
90/* module statistics counters */
91typedef struct
92{
93    UINT32 invalidSignature;
94    UINT32 imageIdListOverflow;
95    UINT32 imageIdNotFound;
96} IxNpeDlImageMgrStats;
97
98
99/*
100 * Variable declarations global to this file only.  Externs are followed by
101 * static variables.
102 */
103static IxNpeDlImageMgrStats ixNpeDlImageMgrStats;
104
105/* default image */
106#ifndef IX_NPEDL_READ_MICROCODE_FROM_FILE
107static UINT32 *IxNpeMicroCodeImageLibrary = (UINT32 *)IxNpeMicrocode_array;
108#endif
109
110
111/*
112 * Function definition: ixNpeDlImageMgrStatsShow
113 */
114void
115ixNpeDlImageMgrStatsShow (void)
116{
117    ixOsalLog (IX_OSAL_LOG_LVL_USER,
118               IX_OSAL_LOG_DEV_STDOUT,
119               "\nixNpeDlImageMgrStatsShow:\n"
120               "\tInvalid Image Signatures: %u\n"
121               "\tImage Id List capacity too small: %u\n"
122               "\tImage Id not found: %u\n\n",
123               ixNpeDlImageMgrStats.invalidSignature,
124               ixNpeDlImageMgrStats.imageIdListOverflow,
125               ixNpeDlImageMgrStats.imageIdNotFound,
126               0,0,0);
127}
128
129
130/*
131 * Function definition: ixNpeDlImageMgrStatsReset
132 */
133void
134ixNpeDlImageMgrStatsReset (void)
135{
136    ixNpeDlImageMgrStats.invalidSignature = 0;
137    ixNpeDlImageMgrStats.imageIdListOverflow = 0;
138    ixNpeDlImageMgrStats.imageIdNotFound = 0;
139}
140
141
142/*
143 * Function definition: ixNpeDlImageMgrImageFind
144 */
145IX_STATUS
146ixNpeDlImageMgrImageFind (
147    UINT32 *imageLibrary,
148    UINT32 imageId,
149    UINT32 **imagePtr,
150    UINT32 *imageSize)
151{
152    IxNpeDlImageMgrImageHeader *image;
153    UINT32 offset = 0;
154
155    /* If user didn't specify a library to use, use the default
156     * one from IxNpeMicrocode.h
157     */
158    if (imageLibrary == NULL)
159    {
160#ifdef IX_NPEDL_READ_MICROCODE_FROM_FILE
161        if (ixNpeMicrocode_binaryArray == NULL)
162        {
163            printk (KERN_ERR "ixp400.o:  ERROR, no Microcode found in memory\n");
164            return IX_FAIL;
165        }
166        else
167        {
168            imageLibrary = ixNpeMicrocode_binaryArray;
169        }
170#else
171        imageLibrary = IxNpeMicroCodeImageLibrary;
172#endif /* IX_NPEDL_READ_MICROCODE_FROM_FILE */
173    }
174
175    while (*(imageLibrary+offset) == NPE_IMAGE_MARKER)
176    {
177        image = (IxNpeDlImageMgrImageHeader *)(imageLibrary+offset);
178        offset += sizeof(IxNpeDlImageMgrImageHeader)/sizeof(UINT32);
179       
180        if (image->id == imageId)
181        {
182            *imagePtr = imageLibrary + offset;
183            *imageSize = image->size;
184            return IX_SUCCESS;
185        }
186        /* 2 consecutive NPE_IMAGE_MARKER's indicates end of library */
187        else if (image->id == NPE_IMAGE_MARKER)
188        {
189            IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
190                                   "imageId not found in image library header\n");
191            ixNpeDlImageMgrStats.imageIdNotFound++;
192            /* reached end of library, image not found */
193            return IX_FAIL;
194        }
195        offset += image->size;
196    }
197
198    /* If we get here, our image library may be corrupted */
199    IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
200                           "image library format may be invalid or corrupted\n");
201    return IX_FAIL;
202}
203
Note: See TracBrowser for help on using the repository browser.