/*************************************************************************** * Copyright (c) 2003-2010, Broadcom Corporation * All Rights Reserved * Confidential Property of Broadcom Corporation * * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. * * $brcm_Workfile: $ * $brcm_Revision: $ * $brcm_Date: $ * * Module Description: Image selector interface * * Revision History: * * $brcm_Log: $ * * ***************************************************************************/ #include "bstd.h" #include "ramheader.h" #include "image_selector.h" #include "bchp_sun_top_ctrl.h" #if defined(RSA_BITS) #define SIGNATURE_SIZE (RSA_BITS/8) #else #define SIGNATURE_SIZE 0x80 #endif #define IMAGE1_SELECTOR_MASK 0x100 #define IMAGE1_SELECTOR_ADDR (0xb0000000 + BCHP_SUN_TOP_CTRL_UNCLEARED_SCRATCH) extern unsigned int _ram_image_start; extern unsigned int _ram_image2_start; extern unsigned int flash_start; /* we always select image 0 unless boot order field says to select 1, even if image is not present we will select and return 0 and let later code decide if image is good. */ void * active_image_address(void) { void * image0; void * image1; unsigned int order0; unsigned int order1; boot_header_t * bh; flash_map_info_t *fmap; unsigned int * stage3_start; stage3_start = (unsigned int *)((unsigned int)&flash_start + ((unsigned int*)&flash_start)[4] + SIGNATURE_SIZE); fmap = (flash_map_info_t*)(stage3_start + 5); /* check for magic # */ if(fmap->fmap_magic == FMAP_MAGIC){ image0 = (void*)(fmap->image0_offset + FLASH_BASE); image1 = (void*)(fmap->image1_offset + FLASH_BASE); }else{ image0 = &_ram_image_start; image1 = &_ram_image2_start; } order0 = order1 = 0; bh = (boot_header_t*)image0; if(CHIP_ID == bh->chip_id){ order0 = bh->boot_order; } bh = (boot_header_t*)image1; if(CHIP_ID == bh->chip_id){ order1 = bh->boot_order; } /* reverse image selection in case image selector field is set */ if(0 != ((*(unsigned int*)IMAGE1_SELECTOR_ADDR) & IMAGE1_SELECTOR_MASK)){ if(order1 < order0){ image0 = image1; } }else{ if(order1 > order0){ image0 = image1; } } return image0; } /* Parse out dsp loader address given starting address of an active image. While active image must be valid address there may not be actual image at that location. The structure in flash would be as following: boot order - optional dta image - optional scm loader - must be present. Function will return address of scm loader or NULL if it was unable to find one. */ void * dsp_loader_address(void * active) { boot_header_t * bh; application_info_header_t * ah; scm_info_header_t * sh; bh = (boot_header_t *)active; if(CHIP_ID == bh->chip_id){ ah = (application_info_header_t *)((unsigned int)bh + sizeof(boot_header_t)); }else{ ah = (application_info_header_t *)active; } if((CHIP_ID == ah->chip_id) && (DTA_MAGIC == ah->dta_magic)){ sh = (scm_info_header_t *)((unsigned int)ah + sizeof(application_info_header_t) + ah->image_size + SIGNATURE_SIZE); }else{ sh = (scm_info_header_t *)ah; } if((CHIP_ID != sh->chip_id) || (SCM_MAGIC != sh->scm_magic)){ sh = NULL; } return (void*)sh; }