1 | /*
|
---|
2 | * Copyright (c) 2007 Michal Kebrt
|
---|
3 | * Copyright (c) 2009 Vineeth Pillai
|
---|
4 | * Copyright (c) 2010 Jiri Svoboda
|
---|
5 | * All rights reserved.
|
---|
6 | *
|
---|
7 | * Redistribution and use in source and binary forms, with or without
|
---|
8 | * modification, are permitted provided that the following conditions
|
---|
9 | * are met:
|
---|
10 | *
|
---|
11 | * - Redistributions of source code must retain the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer.
|
---|
13 | * - Redistributions in binary form must reproduce the above copyright
|
---|
14 | * notice, this list of conditions and the following disclaimer in the
|
---|
15 | * documentation and/or other materials provided with the distribution.
|
---|
16 | * - The name of the author may not be used to endorse or promote products
|
---|
17 | * derived from this software without specific prior written permission.
|
---|
18 | *
|
---|
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
29 | */
|
---|
30 |
|
---|
31 | /** @addtogroup boot_arm32
|
---|
32 | * @{
|
---|
33 | */
|
---|
34 | /** @file
|
---|
35 | * @brief bootloader output logic
|
---|
36 | */
|
---|
37 |
|
---|
38 | #include <arch/main.h>
|
---|
39 | #include <putchar.h>
|
---|
40 | #include <stddef.h>
|
---|
41 | #include <stdint.h>
|
---|
42 | #include <str.h>
|
---|
43 |
|
---|
44 | #ifdef MACHINE_beaglebone
|
---|
45 |
|
---|
46 | /** Send a byte to the am335x serial console.
|
---|
47 | *
|
---|
48 | * @param byte Byte to send.
|
---|
49 | */
|
---|
50 | static void scons_sendb_bbone(uint8_t byte)
|
---|
51 | {
|
---|
52 | volatile uint32_t *thr =
|
---|
53 | (volatile uint32_t *) BBONE_SCONS_THR;
|
---|
54 | volatile uint32_t *ssr =
|
---|
55 | (volatile uint32_t *) BBONE_SCONS_SSR;
|
---|
56 |
|
---|
57 | /* Wait until transmitter is empty */
|
---|
58 | while (*ssr & BBONE_TXFIFO_FULL)
|
---|
59 | ;
|
---|
60 |
|
---|
61 | /* Transmit byte */
|
---|
62 | *thr = (uint32_t) byte;
|
---|
63 | }
|
---|
64 |
|
---|
65 | #endif
|
---|
66 |
|
---|
67 | #ifdef MACHINE_beagleboardxm
|
---|
68 |
|
---|
69 | /** Send a byte to the amdm37x serial console.
|
---|
70 | *
|
---|
71 | * @param byte Byte to send.
|
---|
72 | */
|
---|
73 | static void scons_sendb_bbxm(uint8_t byte)
|
---|
74 | {
|
---|
75 | volatile uint32_t *thr =
|
---|
76 | (volatile uint32_t *)BBXM_SCONS_THR;
|
---|
77 | volatile uint32_t *ssr =
|
---|
78 | (volatile uint32_t *)BBXM_SCONS_SSR;
|
---|
79 |
|
---|
80 | /* Wait until transmitter is empty. */
|
---|
81 | while ((*ssr & BBXM_THR_FULL) == 1)
|
---|
82 | ;
|
---|
83 |
|
---|
84 | /* Transmit byte. */
|
---|
85 | *thr = (uint32_t) byte;
|
---|
86 | }
|
---|
87 |
|
---|
88 | #endif
|
---|
89 |
|
---|
90 | #ifdef MACHINE_gta02
|
---|
91 |
|
---|
92 | /** Send a byte to the gta02 serial console.
|
---|
93 | *
|
---|
94 | * @param byte Byte to send.
|
---|
95 | */
|
---|
96 | static void scons_sendb_gta02(uint8_t byte)
|
---|
97 | {
|
---|
98 | volatile uint32_t *utrstat;
|
---|
99 | volatile uint32_t *utxh;
|
---|
100 |
|
---|
101 | utrstat = (volatile uint32_t *) GTA02_SCONS_UTRSTAT;
|
---|
102 | utxh = (volatile uint32_t *) GTA02_SCONS_UTXH;
|
---|
103 |
|
---|
104 | /* Wait until transmitter is empty. */
|
---|
105 | while ((*utrstat & S3C24XX_UTXH_TX_EMPTY) == 0)
|
---|
106 | ;
|
---|
107 |
|
---|
108 | /* Transmit byte. */
|
---|
109 | *utxh = (uint32_t) byte;
|
---|
110 | }
|
---|
111 |
|
---|
112 | #endif
|
---|
113 |
|
---|
114 | #ifdef MACHINE_integratorcp
|
---|
115 |
|
---|
116 | /** Send a byte to the IntegratorCP serial console.
|
---|
117 | *
|
---|
118 | * @param byte Byte to send.
|
---|
119 | */
|
---|
120 | static void scons_sendb_icp(uint8_t byte)
|
---|
121 | {
|
---|
122 | *((volatile uint8_t *) ICP_SCONS_ADDR) = byte;
|
---|
123 | }
|
---|
124 |
|
---|
125 | #endif
|
---|
126 |
|
---|
127 | #ifdef MACHINE_raspberrypi
|
---|
128 |
|
---|
129 | static int raspi_init;
|
---|
130 |
|
---|
131 | static inline void write32(uint32_t addr, uint32_t data)
|
---|
132 | {
|
---|
133 | *(volatile uint32_t *)(addr) = data;
|
---|
134 | }
|
---|
135 |
|
---|
136 | static inline uint32_t read32(uint32_t addr)
|
---|
137 | {
|
---|
138 | return *(volatile uint32_t *)(addr);
|
---|
139 | }
|
---|
140 |
|
---|
141 | static void scons_init_raspi(void)
|
---|
142 | {
|
---|
143 | write32(BCM2835_UART0_CR, 0x0); /* Disable UART */
|
---|
144 | write32(BCM2835_UART0_ICR, 0x7f); /* Clear interrupts */
|
---|
145 | write32(BCM2835_UART0_IBRD, 1); /* Set integer baud rate */
|
---|
146 | write32(BCM2835_UART0_FBRD, 40); /* Set fractional baud rate */
|
---|
147 | write32(BCM2835_UART0_LCRH,
|
---|
148 | BCM2835_UART0_LCRH_FEN | /* Enable FIFOs */
|
---|
149 | BCM2835_UART0_LCRH_WL8); /* Word length: 8 */
|
---|
150 | write32(BCM2835_UART0_CR,
|
---|
151 | BCM2835_UART0_CR_UARTEN | /* Enable UART */
|
---|
152 | BCM2835_UART0_CR_TXE | /* Enable TX */
|
---|
153 | BCM2835_UART0_CR_RXE); /* Enable RX */
|
---|
154 | }
|
---|
155 |
|
---|
156 | static void scons_sendb_raspi(uint8_t byte)
|
---|
157 | {
|
---|
158 | if (!raspi_init) {
|
---|
159 | scons_init_raspi();
|
---|
160 | raspi_init = 1;
|
---|
161 | }
|
---|
162 |
|
---|
163 | while (read32(BCM2835_UART0_FR) & BCM2835_UART0_FR_TXFF)
|
---|
164 | ;
|
---|
165 |
|
---|
166 | write32(BCM2835_UART0_DR, byte);
|
---|
167 | }
|
---|
168 | #endif
|
---|
169 |
|
---|
170 | /** Send a byte to the serial console.
|
---|
171 | *
|
---|
172 | * @param byte Byte to send.
|
---|
173 | */
|
---|
174 | static void scons_sendb(uint8_t byte)
|
---|
175 | {
|
---|
176 | #ifdef MACHINE_beaglebone
|
---|
177 | scons_sendb_bbone(byte);
|
---|
178 | #endif
|
---|
179 | #ifdef MACHINE_beagleboardxm
|
---|
180 | scons_sendb_bbxm(byte);
|
---|
181 | #endif
|
---|
182 | #ifdef MACHINE_gta02
|
---|
183 | scons_sendb_gta02(byte);
|
---|
184 | #endif
|
---|
185 | #ifdef MACHINE_integratorcp
|
---|
186 | scons_sendb_icp(byte);
|
---|
187 | #endif
|
---|
188 | #ifdef MACHINE_raspberrypi
|
---|
189 | scons_sendb_raspi(byte);
|
---|
190 | #endif
|
---|
191 | }
|
---|
192 |
|
---|
193 | /** Display a character
|
---|
194 | *
|
---|
195 | * @param ch Character to display
|
---|
196 | *
|
---|
197 | */
|
---|
198 | void putuchar(const char32_t ch)
|
---|
199 | {
|
---|
200 | if (ch == '\n')
|
---|
201 | scons_sendb('\r');
|
---|
202 |
|
---|
203 | if (ascii_check(ch))
|
---|
204 | scons_sendb((uint8_t) ch);
|
---|
205 | else
|
---|
206 | scons_sendb('?');
|
---|
207 | }
|
---|
208 |
|
---|
209 | /** @}
|
---|
210 | */
|
---|