[6b781c0] | 1 | /*
|
---|
[4872160] | 2 | * Copyright (c) 2007 Michal Kebrt
|
---|
| 3 | * Copyright (c) 2009 Vineeth Pillai
|
---|
[1590e23] | 4 | * Copyright (c) 2010 Jiri Svoboda
|
---|
[6b781c0] | 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 |
|
---|
[c5429fe] | 31 | /** @addtogroup boot_arm32
|
---|
[6b781c0] | 32 | * @{
|
---|
| 33 | */
|
---|
[4872160] | 34 | /** @file
|
---|
| 35 | * @brief bootloader output logic
|
---|
| 36 | */
|
---|
[6b781c0] | 37 |
|
---|
[4872160] | 38 | #include <arch/main.h>
|
---|
| 39 | #include <putchar.h>
|
---|
[7a99507] | 40 | #include <stddef.h>
|
---|
| 41 | #include <stdint.h>
|
---|
[4872160] | 42 | #include <str.h>
|
---|
| 43 |
|
---|
[9f8a07d3] | 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 =
|
---|
[e8975278] | 53 | (volatile uint32_t *) BBONE_SCONS_THR;
|
---|
[9f8a07d3] | 54 | volatile uint32_t *ssr =
|
---|
[e8975278] | 55 | (volatile uint32_t *) BBONE_SCONS_SSR;
|
---|
[9f8a07d3] | 56 |
|
---|
| 57 | /* Wait until transmitter is empty */
|
---|
[e8975278] | 58 | while (*ssr & BBONE_TXFIFO_FULL)
|
---|
| 59 | ;
|
---|
[9f8a07d3] | 60 |
|
---|
| 61 | /* Transmit byte */
|
---|
| 62 | *thr = (uint32_t) byte;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | #endif
|
---|
| 66 |
|
---|
[fcc6224] | 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. */
|
---|
[e8975278] | 81 | while ((*ssr & BBXM_THR_FULL) == 1)
|
---|
| 82 | ;
|
---|
[fcc6224] | 83 |
|
---|
| 84 | /* Transmit byte. */
|
---|
| 85 | *thr = (uint32_t) byte;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | #endif
|
---|
| 89 |
|
---|
[1590e23] | 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. */
|
---|
[f1fc83a] | 105 | while ((*utrstat & S3C24XX_UTXH_TX_EMPTY) == 0)
|
---|
[1590e23] | 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 |
|
---|
[8f9d70b] | 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,
|
---|
[e8975278] | 148 | BCM2835_UART0_LCRH_FEN | /* Enable FIFOs */
|
---|
| 149 | BCM2835_UART0_LCRH_WL8); /* Word length: 8 */
|
---|
[8f9d70b] | 150 | write32(BCM2835_UART0_CR,
|
---|
[e8975278] | 151 | BCM2835_UART0_CR_UARTEN | /* Enable UART */
|
---|
| 152 | BCM2835_UART0_CR_TXE | /* Enable TX */
|
---|
| 153 | BCM2835_UART0_CR_RXE); /* Enable RX */
|
---|
[8f9d70b] | 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 |
|
---|
[e8975278] | 163 | while (read32(BCM2835_UART0_FR) & BCM2835_UART0_FR_TXFF)
|
---|
| 164 | ;
|
---|
[8f9d70b] | 165 |
|
---|
| 166 | write32(BCM2835_UART0_DR, byte);
|
---|
| 167 | }
|
---|
| 168 | #endif
|
---|
| 169 |
|
---|
[1590e23] | 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 | {
|
---|
[9f8a07d3] | 176 | #ifdef MACHINE_beaglebone
|
---|
| 177 | scons_sendb_bbone(byte);
|
---|
| 178 | #endif
|
---|
[fcc6224] | 179 | #ifdef MACHINE_beagleboardxm
|
---|
| 180 | scons_sendb_bbxm(byte);
|
---|
| 181 | #endif
|
---|
[1590e23] | 182 | #ifdef MACHINE_gta02
|
---|
| 183 | scons_sendb_gta02(byte);
|
---|
| 184 | #endif
|
---|
| 185 | #ifdef MACHINE_integratorcp
|
---|
[12b0d51] | 186 | scons_sendb_icp(byte);
|
---|
[1590e23] | 187 | #endif
|
---|
[8f9d70b] | 188 | #ifdef MACHINE_raspberrypi
|
---|
| 189 | scons_sendb_raspi(byte);
|
---|
| 190 | #endif
|
---|
[1590e23] | 191 | }
|
---|
| 192 |
|
---|
| 193 | /** Display a character
|
---|
| 194 | *
|
---|
[28a5ebd] | 195 | * @param ch Character to display
|
---|
| 196 | *
|
---|
[1590e23] | 197 | */
|
---|
[28a5ebd] | 198 | void putuchar(const char32_t ch)
|
---|
[4872160] | 199 | {
|
---|
| 200 | if (ch == '\n')
|
---|
[1590e23] | 201 | scons_sendb('\r');
|
---|
| 202 |
|
---|
[4872160] | 203 | if (ascii_check(ch))
|
---|
[1590e23] | 204 | scons_sendb((uint8_t) ch);
|
---|
[4872160] | 205 | else
|
---|
[ed88c8e] | 206 | scons_sendb('?');
|
---|
[4872160] | 207 | }
|
---|
[6b781c0] | 208 |
|
---|
| 209 | /** @}
|
---|
| 210 | */
|
---|