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 arm32boot
|
---|
32 | * @{
|
---|
33 | */
|
---|
34 | /** @file
|
---|
35 | * @brief bootloader output logic
|
---|
36 | */
|
---|
37 |
|
---|
38 | #include <typedefs.h>
|
---|
39 | #include <arch/main.h>
|
---|
40 | #include <putchar.h>
|
---|
41 | #include <str.h>
|
---|
42 |
|
---|
43 | #ifdef MACHINE_beaglebone
|
---|
44 |
|
---|
45 | /** Send a byte to the am335x serial console.
|
---|
46 | *
|
---|
47 | * @param byte Byte to send.
|
---|
48 | */
|
---|
49 | static void scons_sendb_bbone(uint8_t byte)
|
---|
50 | {
|
---|
51 | volatile uint32_t *thr =
|
---|
52 | (volatile uint32_t *) BBONE_SCONS_THR;
|
---|
53 | volatile uint32_t *ssr =
|
---|
54 | (volatile uint32_t *) BBONE_SCONS_SSR;
|
---|
55 |
|
---|
56 | /* Wait until transmitter is empty */
|
---|
57 | while (*ssr & BBONE_TXFIFO_FULL);
|
---|
58 |
|
---|
59 | /* Transmit byte */
|
---|
60 | *thr = (uint32_t) byte;
|
---|
61 | }
|
---|
62 |
|
---|
63 | #endif
|
---|
64 |
|
---|
65 | #ifdef MACHINE_beagleboardxm
|
---|
66 |
|
---|
67 | /** Send a byte to the amdm37x serial console.
|
---|
68 | *
|
---|
69 | * @param byte Byte to send.
|
---|
70 | */
|
---|
71 | static void scons_sendb_bbxm(uint8_t byte)
|
---|
72 | {
|
---|
73 | volatile uint32_t *thr =
|
---|
74 | (volatile uint32_t *)BBXM_SCONS_THR;
|
---|
75 | volatile uint32_t *ssr =
|
---|
76 | (volatile uint32_t *)BBXM_SCONS_SSR;
|
---|
77 |
|
---|
78 | /* Wait until transmitter is empty. */
|
---|
79 | while ((*ssr & BBXM_THR_FULL) == 1) ;
|
---|
80 |
|
---|
81 | /* Transmit byte. */
|
---|
82 | *thr = (uint32_t) byte;
|
---|
83 | }
|
---|
84 |
|
---|
85 | #endif
|
---|
86 |
|
---|
87 | #ifdef MACHINE_gta02
|
---|
88 |
|
---|
89 | /** Send a byte to the gta02 serial console.
|
---|
90 | *
|
---|
91 | * @param byte Byte to send.
|
---|
92 | */
|
---|
93 | static void scons_sendb_gta02(uint8_t byte)
|
---|
94 | {
|
---|
95 | volatile uint32_t *utrstat;
|
---|
96 | volatile uint32_t *utxh;
|
---|
97 |
|
---|
98 | utrstat = (volatile uint32_t *) GTA02_SCONS_UTRSTAT;
|
---|
99 | utxh = (volatile uint32_t *) GTA02_SCONS_UTXH;
|
---|
100 |
|
---|
101 | /* Wait until transmitter is empty. */
|
---|
102 | while ((*utrstat & S3C24XX_UTXH_TX_EMPTY) == 0)
|
---|
103 | ;
|
---|
104 |
|
---|
105 | /* Transmit byte. */
|
---|
106 | *utxh = (uint32_t) byte;
|
---|
107 | }
|
---|
108 |
|
---|
109 | #endif
|
---|
110 |
|
---|
111 | #ifdef MACHINE_integratorcp
|
---|
112 |
|
---|
113 | /** Send a byte to the IntegratorCP serial console.
|
---|
114 | *
|
---|
115 | * @param byte Byte to send.
|
---|
116 | */
|
---|
117 | static void scons_sendb_icp(uint8_t byte)
|
---|
118 | {
|
---|
119 | *((volatile uint8_t *) ICP_SCONS_ADDR) = byte;
|
---|
120 | }
|
---|
121 |
|
---|
122 | #endif
|
---|
123 |
|
---|
124 | #ifdef MACHINE_raspberrypi
|
---|
125 |
|
---|
126 | static int raspi_init;
|
---|
127 |
|
---|
128 | static inline void write32(uint32_t addr, uint32_t data)
|
---|
129 | {
|
---|
130 | *(volatile uint32_t *)(addr) = data;
|
---|
131 | }
|
---|
132 |
|
---|
133 | static inline uint32_t read32(uint32_t addr)
|
---|
134 | {
|
---|
135 | return *(volatile uint32_t *)(addr);
|
---|
136 | }
|
---|
137 |
|
---|
138 | static void scons_init_raspi(void)
|
---|
139 | {
|
---|
140 | write32(BCM2835_UART0_CR, 0x0); /* Disable UART */
|
---|
141 | write32(BCM2835_UART0_ICR, 0x7f); /* Clear interrupts */
|
---|
142 | write32(BCM2835_UART0_IBRD, 1); /* Set integer baud rate */
|
---|
143 | write32(BCM2835_UART0_FBRD, 40); /* Set fractional baud rate */
|
---|
144 | write32(BCM2835_UART0_LCRH,
|
---|
145 | BCM2835_UART0_LCRH_FEN | /* Enable FIFOs */
|
---|
146 | BCM2835_UART0_LCRH_WL8); /* Word length: 8 */
|
---|
147 | write32(BCM2835_UART0_CR,
|
---|
148 | BCM2835_UART0_CR_UARTEN | /* Enable UART */
|
---|
149 | BCM2835_UART0_CR_TXE | /* Enable TX */
|
---|
150 | BCM2835_UART0_CR_RXE); /* Enable RX */
|
---|
151 | }
|
---|
152 |
|
---|
153 | static void scons_sendb_raspi(uint8_t byte)
|
---|
154 | {
|
---|
155 | if (!raspi_init) {
|
---|
156 | scons_init_raspi();
|
---|
157 | raspi_init = 1;
|
---|
158 | }
|
---|
159 |
|
---|
160 | while (read32(BCM2835_UART0_FR) & BCM2835_UART0_FR_TXFF);
|
---|
161 |
|
---|
162 | write32(BCM2835_UART0_DR, byte);
|
---|
163 | }
|
---|
164 | #endif
|
---|
165 |
|
---|
166 | /** Send a byte to the serial console.
|
---|
167 | *
|
---|
168 | * @param byte Byte to send.
|
---|
169 | */
|
---|
170 | static void scons_sendb(uint8_t byte)
|
---|
171 | {
|
---|
172 | #ifdef MACHINE_beaglebone
|
---|
173 | scons_sendb_bbone(byte);
|
---|
174 | #endif
|
---|
175 | #ifdef MACHINE_beagleboardxm
|
---|
176 | scons_sendb_bbxm(byte);
|
---|
177 | #endif
|
---|
178 | #ifdef MACHINE_gta02
|
---|
179 | scons_sendb_gta02(byte);
|
---|
180 | #endif
|
---|
181 | #ifdef MACHINE_integratorcp
|
---|
182 | scons_sendb_icp(byte);
|
---|
183 | #endif
|
---|
184 | #ifdef MACHINE_raspberrypi
|
---|
185 | scons_sendb_raspi(byte);
|
---|
186 | #endif
|
---|
187 | }
|
---|
188 |
|
---|
189 | /** Display a character
|
---|
190 | *
|
---|
191 | * @param ch Character to display
|
---|
192 | */
|
---|
193 | void putchar(const wchar_t ch)
|
---|
194 | {
|
---|
195 | if (ch == '\n')
|
---|
196 | scons_sendb('\r');
|
---|
197 |
|
---|
198 | if (ascii_check(ch))
|
---|
199 | scons_sendb((uint8_t) ch);
|
---|
200 | else
|
---|
201 | scons_sendb(U_SPECIAL);
|
---|
202 | }
|
---|
203 |
|
---|
204 | /** @}
|
---|
205 | */
|
---|