source: svn/newcon3bcm2_21bu/nexus/app/dta/image_write.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 4.0 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2008, 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: write image to flash.
15 *
16 * Revision History:
17 *
18 * $brcm_Log: $
19 *
20 *
21 ***************************************************************************/
22
23#include "bstd.h"
24#include "bdbg.h"
25
26#include "image_recv.h"
27#include "ram_header.h"
28
29BDBG_MODULE(image_write);
30
31/* JPF TODO Fix up for non_ucos environments */
32static unsigned int s_static_values[128] = { DEF_VERSION, DEF_VERSION,0 };
33
34#define RAM_DISPATCH_BASE       (&s_static_values[1])
35#define ROM_TEXT_BASE   (unsigned int)(&s_static_values[2])
36#define FLASH_BASE      (unsigned int)(&s_static_values[3])
37unsigned int ram0_start_address = (unsigned int)(&s_static_values[4]);
38unsigned int ram1_start_address = (unsigned int)(&s_static_values[5]);
39
40
41/* return value when image autheticated successfuly  else value is 0 */
42#define BCM_MAIN_PASSED 0x5abf632d
43/*
44   0x1dc8 is offset or authenticate_ram function from the start of
45   main function or start of security image, when security image is
46   built in release mode. 0x2230 is the same offset when image is build
47   in debug mode. SECURE_BASE depends on where security rom is placed.
48*/
49#define SECURE_BASE 0x9fc7c000
50#define AUTHENTICATE_RAM ((authenticate_t)(SECURE_BASE + 0x1dc8))
51
52typedef unsigned long (*authenticate_t)(unsigned long image_addr, unsigned long image_size, unsigned long signature_addr, unsigned long pubkey_idx);
53
54
55#if defined(DUMMY_AUTHENTICATE)
56#undef AUTHENTICATE_RAM
57#define AUTHENTICATE_RAM(x1, x2, x3, x4) BCM_MAIN_PASSED
58#endif
59
60
61#define RUNNING_TIME_STAMP (*(unsigned long*)(RAM_DISPATCH_BASE-4))
62extern void flash_install(uint32_t base, uint32_t offset, uint8_t * data, size_t len);
63static unsigned long authenticate_code(struct identifying_data6_t * code);
64
65bresult image_write(struct image_t * image)
66{
67    struct identifying_data6_t * ram0;   
68    struct identifying_data6_t * ram1;
69    struct identifying_data6_t * new_ram;
70    uint32_t ram_offset;
71
72    /* find running image */
73    ram0 = (struct identifying_data6_t *)&ram0_start_address;
74    ram1 = (struct identifying_data6_t *)&ram1_start_address;
75
76    if(RUNNING_TIME_STAMP == ram0->signing_time){
77        ram_offset = (unsigned long)ram1 - ROM_TEXT_BASE;
78    }else if(RUNNING_TIME_STAMP == ram1->signing_time){
79        ram_offset = (unsigned long)ram0 - ROM_TEXT_BASE;
80    }else{
81        ram_offset = (unsigned long)ram1 - ROM_TEXT_BASE;
82    }
83    new_ram = (struct identifying_data6_t *)image->data;
84    if ((ram0->signing_time == new_ram->signing_time) || 
85        (ram1->signing_time == new_ram->signing_time)) {
86
87        BDBG_WRN(("image already in flash"));
88        return berr_same_version;
89    }
90    if(BCM_MAIN_PASSED != authenticate_code(new_ram)){
91        BDBG_WRN(("authentication failed"));
92        return berr_verification_falure;
93    }
94
95    BDBG_WRN(("writing at 0x%x", ram_offset));
96#if 0 /* JPF TODO */
97    flash_install(FLASH_BASE, ram_offset, image->data, image->size);
98#endif
99    return b_ok;
100}
101
102unsigned long authenticate_code(struct identifying_data6_t * code)
103{
104    unsigned long res;
105    unsigned long code_address;
106    unsigned long code_size;
107    unsigned long signature_address;
108    unsigned long key_idx;
109
110    res = 0;
111    if(1 != code->key_identifier_flag){
112        goto ExitFunc;
113    }
114
115    code_address = (unsigned long)code;
116    code_size = code->length - 128;
117    signature_address = (unsigned long)code + code->signature_index;
118    key_idx = code->key_identifier[0];
119
120    if(0x40 > code_size){
121        goto ExitFunc;
122    }
123    if ((0 < key_idx) && (16 > key_idx)) {
124        res = AUTHENTICATE_RAM(code_address, code_size, signature_address, key_idx);
125    }
126ExitFunc:
127    return res;
128}
Note: See TracBrowser for help on using the repository browser.