1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
/*
* arch/arm/cpu/armv8/common/firmware/plat/gxb/mailbox.c
*
* Copyright (C) 2015 Amlogic, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <stdio.h>
#include <string.h>
#include <io.h>
#include <stdint.h>
#include <asm/arch/romboot.h>
#include <mailbox.h>
#include <asm/arch/secure_apb.h>
void mb_send_data(uint32_t val, uint32_t port)
{
unsigned long base_addr = SEC_HIU_MAILBOX_SET_0;
unsigned long set_addr;
if (port > 5) {
serial_puts("Error: Use the error port num!\n");
return;
}
set_addr = base_addr + port*3*4;
if (!val) {
serial_puts("Error: mailbox try to send zero val!\n");
return;
}
writel(val, set_addr);
return;
}
uint32_t mb_read_data(uint32_t port)
{
unsigned long base_addr = SEC_HIU_MAILBOX_STAT_0;
uint32_t val;
if (port > 5) {
serial_puts("Error: Use the error port num!\n");
return 0;
}
val = readl(base_addr + port*3*4);
if (val)
return val;
else {
// print_out("Warning: read mailbox val=0.\n");
return 0;
}
}
void mb_clear_data(uint32_t val, uint32_t port)
{
uint32_t base_addr = SEC_HIU_MAILBOX_CLR_0;
unsigned long clean_addr = base_addr + port*3*4;
if (port > 5) {
serial_puts("Error: Use the error port num!\n");
return;
}
if (!val) {
serial_puts("Warning: clean val=0.\n");
return;
}
writel(val,clean_addr);
return;
}
void send_bl30x(uint32_t addr, uint32_t size, const uint8_t * sha2, \
uint32_t sha2_length, const char * name)
{
int i;
*(unsigned int *)MB_SRAM_BASE = size;
if (0 == strcmp("bl301", name)) {
/*bl301 must wait bl30 run*/
serial_puts("Wait bl30...");
while (0x3 != ((readl(AO_SEC_SD_CFG15) >> 20) & 0x3)) {}
serial_puts("Done\n");
}
serial_puts("Sending ");
serial_puts(name);
//serial_puts("time=0x%x size=0x%x\n", readl(0xc1109988),size);
mb_send_data(CMD_DATA_LEN, 3);
do {} while(mb_read_data(3));
memcpy((void *)MB_SRAM_BASE, (const void *)sha2, sha2_length);
mb_send_data(CMD_SHA, 3);
do {} while(mb_read_data(3));
for (i = 0; i < size; i+=1024) {
serial_puts(".");
if (size >= i + 1024)
memcpy((void *)MB_SRAM_BASE,(const void *)(unsigned long)(addr+i),1024);
else if(size > i)
memcpy((void *)MB_SRAM_BASE,(const void *)(unsigned long)(addr+i),(size-i));
mb_send_data(CMD_DATA, 3);
do {} while(mb_read_data(3));
}
mb_send_data(CMD_OP_SHA, 3);
do {} while(mb_read_data(3));
serial_puts("OK. \nRun ");
serial_puts(name);
serial_puts("...\n");
/* The BL31 will run after this command */
mb_send_data(CMD_END,3);//code transfer end.
}
|