From c40965aa2936942a4adf72e7bf590e491892e236 Mon Sep 17 00:00:00 2001 From: ian Date: Thu, 15 May 2014 21:41:32 +0000 Subject: [PATCH] MFC r261786, r261789 Rework the EARLY_PRINTF mechanism. Instead of defining a special eprintf() routine, now a platform can provide a pointer to an early_putc() routine which is used instead of cn_putc(). Control can be handed off from early printf support to standard console support by NULLing out the pointer during standard console init. Convert two while(1); statements into proper panics. git-svn-id: svn://svn.freebsd.org/base/stable/10@266197 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/arm/arm/machdep.c | 4 +-- sys/arm/at91/uart_dev_at91usart.c | 59 +++++++++++++++++++------------ sys/kern/kern_cons.c | 9 +++++ sys/kern/subr_prf.c | 22 ------------ sys/sys/systm.h | 4 +-- 5 files changed, 50 insertions(+), 48 deletions(-) diff --git a/sys/arm/arm/machdep.c b/sys/arm/arm/machdep.c index f0b5e37b8..0181e217e 100644 --- a/sys/arm/arm/machdep.c +++ b/sys/arm/arm/machdep.c @@ -1056,10 +1056,10 @@ initarm(struct arm_boot_params *abp) #endif if (OF_install(OFW_FDT, 0) == FALSE) - while (1); + panic("Cannot install FDT"); if (OF_init((void *)dtbp) != 0) - while (1); + panic("OF_init failed with the found device tree"); /* Grab physical memory regions information from device tree. */ if (fdt_get_mem_regions(mem_regions, &mem_regions_sz, &memsize) != 0) diff --git a/sys/arm/at91/uart_dev_at91usart.c b/sys/arm/at91/uart_dev_at91usart.c index 1e673edf3..3f02a4e8f 100644 --- a/sys/arm/at91/uart_dev_at91usart.c +++ b/sys/arm/at91/uart_dev_at91usart.c @@ -228,6 +228,27 @@ static struct uart_ops at91_usart_ops = { .getc = at91_usart_getc, }; +#ifdef EARLY_PRINTF +/* + * Early printf support. This assumes that we have the SoC "system" devices + * mapped into AT91_BASE. To use this before we adjust the boostrap tables, + * you'll need to define SOCDEV_VA to be 0xdc000000 and SOCDEV_PA to be + * 0xfc000000 in your config file where you define EARLY_PRINTF + */ +volatile uint32_t *at91_dbgu = (volatile uint32_t *)(AT91_BASE + AT91_DBGU0); + +static void +eputc(int c) +{ + + while (!(at91_dbgu[USART_CSR / 4] & USART_CSR_TXRDY)) + continue; + at91_dbgu[USART_THR / 4] = c; +} + +early_putc_t * early_putc = eputc; +#endif + static int at91_usart_probe(struct uart_bas *bas) { @@ -244,6 +265,22 @@ at91_usart_init(struct uart_bas *bas, int baudrate, int databits, int stopbits, int parity) { +#ifdef EARLY_PRINTF + if (early_putc != NULL) { + printf("Early printf yielding control to the real console.\n"); + early_putc = NULL; + } +#endif + + /* + * This routine is called multiple times, sometimes right after writing + * some output, and the last byte is still shifting out. If that's the + * case delay briefly before resetting, but don't loop on TXRDY because + * we don't want to hang here forever if the hardware is in a bad state. + */ + if (!(RD4(bas, USART_CSR) & USART_CSR_TXRDY)) + DELAY(1000); + at91_usart_param(bas, baudrate, databits, stopbits, parity); /* Reset the rx and tx buffers and turn on rx and tx */ @@ -276,28 +313,6 @@ at91_usart_putc(struct uart_bas *bas, int c) WR4(bas, USART_THR, c); } -#ifdef EARLY_PRINTF -/* - * Early printf support. This assumes that we have the SoC "system" devices - * mapped into AT91_BASE. To use this before we adjust the boostrap tables, - * You'll need to define SOCDEV_VA to be 0xdc000000 and SOCDEV_PA to be - * 0xfc000000 in your config file where you define EARLY_PRINTF - */ -volatile uint32_t *at91_dbgu = (volatile uint32_t *)(AT91_BASE + AT91_DBGU0); - -void -eputc(int c) -{ - - if (c == '\n') - eputc('\r'); - - while (!(at91_dbgu[USART_CSR / 4] & USART_CSR_TXRDY)) - continue; - at91_dbgu[USART_THR / 4] = c; -} -#endif - /* * Check for a character available. */ diff --git a/sys/kern/kern_cons.c b/sys/kern/kern_cons.c index 72b384f01..ad2ba2015 100644 --- a/sys/kern/kern_cons.c +++ b/sys/kern/kern_cons.c @@ -464,6 +464,15 @@ cnputc(int c) struct consdev *cn; char *cp; +#ifdef EARLY_PRINTF + if (early_putc != NULL) { + if (c == '\n') + early_putc('\r'); + early_putc(c); + return; + } +#endif + if (cn_mute || c == '\0') return; STAILQ_FOREACH(cnd, &cn_devlist, cnd_next) { diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index 9c7379fa3..28e33a4b4 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -1122,25 +1122,3 @@ hexdump(const void *ptr, int length, const char *hdr, int flags) printf("\n"); } } -#ifdef EARLY_PRINTF -/* - * Support for calling an alternate printf early in boot (like before - * cn_init() can be called). Platforms need to define eputc that want - * to use this. - */ -static void -early_putc_func(int ch, void *arg __unused) -{ - eputc(ch); -} - -void -eprintf(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - kvprintf(fmt, early_putc_func, NULL, 10, ap); - va_end(ap); -} -#endif diff --git a/sys/sys/systm.h b/sys/sys/systm.h index cf360f6cf..ac1556876 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -197,8 +197,8 @@ void init_param2(long physpages); void init_static_kenv(char *, size_t); void tablefull(const char *); #ifdef EARLY_PRINTF -void eprintf(const char *, ...) __printflike(1, 2); -void eputc(int ch); +typedef void early_putc_t(int ch); +extern early_putc_t *early_putc; #endif int kvprintf(char const *, void (*)(int, void*), void *, int, __va_list) __printflike(1, 0); -- 2.45.0