source: svn/trunk/newcon3bcm2_21bu/dta/src/bootloader/image_selector.c

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

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 3.5 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2010, 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: $
11 * $brcm_Revision: $
12 * $brcm_Date: $
13 *
14 * Module Description: Image selector interface
15 *
16 * Revision History:
17 *
18 * $brcm_Log: $
19 *
20 *
21 ***************************************************************************/
22
23#include "bstd.h"
24#include "ramheader.h"
25#include "image_selector.h"
26#include "bchp_sun_top_ctrl.h"
27
28#if defined(RSA_BITS)
29#define SIGNATURE_SIZE (RSA_BITS/8)
30#else
31#define SIGNATURE_SIZE 0x80
32#endif
33
34#define IMAGE1_SELECTOR_MASK 0x100
35#define IMAGE1_SELECTOR_ADDR (0xb0000000 + BCHP_SUN_TOP_CTRL_UNCLEARED_SCRATCH)
36
37extern unsigned int _ram_image_start;
38extern unsigned int _ram_image2_start;
39extern unsigned int flash_start;
40/*
41   we always select image 0 unless boot order field says to select 1,
42   even if image is not present we will select and return 0 and let
43   later code decide if image is good.
44 */
45void * active_image_address(void)
46{
47    void * image0;
48    void * image1;
49    unsigned int order0;
50    unsigned int order1;
51    boot_header_t * bh;
52    flash_map_info_t *fmap;
53    unsigned int * stage3_start;
54
55    stage3_start = (unsigned int *)((unsigned int)&flash_start + ((unsigned int*)&flash_start)[4] + SIGNATURE_SIZE);
56    fmap = (flash_map_info_t*)(stage3_start + 5);
57
58    /* check for magic # */
59    if(fmap->fmap_magic == FMAP_MAGIC){
60        image0 = (void*)(fmap->image0_offset + FLASH_BASE);
61        image1 = (void*)(fmap->image1_offset + FLASH_BASE);
62    }else{
63        image0 = &_ram_image_start;
64        image1 = &_ram_image2_start;
65    }
66    order0 = order1 = 0;
67    bh = (boot_header_t*)image0;
68    if(CHIP_ID == bh->chip_id){
69        order0 = bh->boot_order;
70    }
71
72    bh = (boot_header_t*)image1;
73    if(CHIP_ID == bh->chip_id){
74        order1 = bh->boot_order;
75    }
76    /* reverse image selection in case image selector field is set */
77    if(0 != ((*(unsigned int*)IMAGE1_SELECTOR_ADDR) & IMAGE1_SELECTOR_MASK)){
78        if(order1 < order0){
79            image0 = image1;
80        }
81    }else{
82        if(order1 > order0){
83            image0 = image1;
84        }
85    }
86    return image0;
87}
88
89/*
90  Parse out dsp loader address given starting address of an active image.
91  While active image must be valid address there may not be actual image
92  at that location.
93  The structure in flash would be as following:
94  boot order - optional
95  dta image - optional
96  scm loader - must be present.
97  Function will return address of scm loader or NULL if it was unable to
98  find one.
99 */
100void * dsp_loader_address(void * active)
101{
102    boot_header_t * bh;
103    application_info_header_t * ah;
104    scm_info_header_t * sh;
105
106    bh = (boot_header_t *)active;
107    if(CHIP_ID == bh->chip_id){
108        ah = (application_info_header_t *)((unsigned int)bh + sizeof(boot_header_t));
109    }else{
110        ah = (application_info_header_t *)active;
111    }
112
113    if((CHIP_ID == ah->chip_id) && (DTA_MAGIC == ah->dta_magic)){
114        sh = (scm_info_header_t *)((unsigned int)ah + sizeof(application_info_header_t) + ah->image_size + SIGNATURE_SIZE);
115    }else{
116        sh = (scm_info_header_t *)ah;
117    }
118
119    if((CHIP_ID != sh->chip_id) || (SCM_MAGIC != sh->scm_magic)){
120        sh = NULL;
121    }
122    return (void*)sh;
123}
Note: See TracBrowser for help on using the repository browser.