| 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: Stage 1 C entry point. |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: $ |
|---|
| 19 | * |
|---|
| 20 | * |
|---|
| 21 | ***************************************************************************/ |
|---|
| 22 | |
|---|
| 23 | /* copy memory block from word aligned src to word aligned destination |
|---|
| 24 | with word aligned size. All pointer and size must be 4 bytes aligned */ |
|---|
| 25 | extern void aligned_copy(void * src, void * dst, unsigned int n); |
|---|
| 26 | |
|---|
| 27 | extern unsigned int _stage2_start; |
|---|
| 28 | extern unsigned int _stage2_size; |
|---|
| 29 | extern unsigned int __start_s2; |
|---|
| 30 | extern unsigned int key1[]; |
|---|
| 31 | |
|---|
| 32 | #define KSEG0_KSEG1(x) ((0x20000000) | (unsigned long)(x)) |
|---|
| 33 | #if defined(RSA_BITS) |
|---|
| 34 | #define SIGNATURE_SIZE (RSA_BITS/8) |
|---|
| 35 | #else |
|---|
| 36 | #define SIGNATURE_SIZE 0x80 |
|---|
| 37 | #endif |
|---|
| 38 | unsigned int stage2_signature[SIGNATURE_SIZE/4]; |
|---|
| 39 | unsigned int key1_copy[SIGNATURE_SIZE/4]; |
|---|
| 40 | |
|---|
| 41 | #define XPT_OTP_MC1_BASE 0xb053802c |
|---|
| 42 | |
|---|
| 43 | void print_string(void) |
|---|
| 44 | { |
|---|
| 45 | /* New B0 scramble function needs print_string to compile */ |
|---|
| 46 | } |
|---|
| 47 | /* write character on serial port */ |
|---|
| 48 | extern void _writeasm(int c); |
|---|
| 49 | |
|---|
| 50 | int signature_check(unsigned long in, unsigned long size, unsigned long signature, unsigned long public_key); |
|---|
| 51 | |
|---|
| 52 | void stage1_main(void) |
|---|
| 53 | { |
|---|
| 54 | void * stage2_signature_address; |
|---|
| 55 | int rc; |
|---|
| 56 | stage2_signature_address = (void*)((unsigned int)&_stage2_start + (unsigned int)&_stage2_size); |
|---|
| 57 | /* |
|---|
| 58 | we must validate key1 somehow. |
|---|
| 59 | */ |
|---|
| 60 | aligned_copy(stage2_signature_address, stage2_signature, SIGNATURE_SIZE); |
|---|
| 61 | aligned_copy(key1, key1_copy, SIGNATURE_SIZE); |
|---|
| 62 | rc = signature_check(KSEG0_KSEG1(&__start_s2), (unsigned long)&_stage2_size, (unsigned long)stage2_signature, (unsigned long)key1_copy); |
|---|
| 63 | if(0 != rc){ |
|---|
| 64 | /* signature is invalid */ |
|---|
| 65 | _writeasm('-'); |
|---|
| 66 | /* halt if bootloader verification is enabled */ |
|---|
| 67 | if((*(unsigned int*)XPT_OTP_MC1_BASE) & 4) |
|---|
| 68 | __asm__("wait"); |
|---|
| 69 | } |
|---|
| 70 | /* exit back to assembly and start stage two execution */ |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | #include "signature.c" |
|---|
| 74 | |
|---|
| 75 | /* Please do not remove! */ |
|---|
| 76 | /* Local Variables: */ |
|---|
| 77 | /* mode: C */ |
|---|
| 78 | /* indent-tabs-mode: nil */ |
|---|
| 79 | /* End: */ |
|---|