Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tty/serial: add arm/arm64 semihosting earlycon

Add earlycon support for the arm/arm64 semihosting debug serial
interface. This allows enabling a debug console when early_params are
processed. This is based on the arm64 earlyprintk smh support and is
intended to replace it.

Signed-off-by: Rob Herring <robh@kernel.org>
Cc: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Rob Herring and committed by
Greg Kroah-Hartman
d50d7269 0d3c673e

+74
+2
Documentation/kernel-parameters.txt
··· 899 899 must already be setup and configured. Options are not 900 900 yet supported. 901 901 902 + smh Use ARM semihosting calls for early console. 903 + 902 904 earlyprintk= [X86,SH,BLACKFIN,ARM] 903 905 earlyprintk=vga 904 906 earlyprintk=efi
+10
drivers/tty/serial/Kconfig
··· 73 73 your boot loader (lilo or loadlin) about how to pass options to the 74 74 kernel at boot time.) 75 75 76 + config SERIAL_EARLYCON_ARM_SEMIHOST 77 + bool "Early console using ARM semihosting" 78 + depends on ARM64 || ARM 79 + select SERIAL_EARLYCON 80 + help 81 + Support for early debug console using ARM semihosting. This enables 82 + the console before standard serial driver is probed. This is enabled 83 + with "earlycon=smh" on the kernel command line. The console is 84 + enabled when early_param is processed. 85 + 76 86 config SERIAL_SB1250_DUART 77 87 tristate "BCM1xxx on-chip DUART serial support" 78 88 depends on SIBYTE_SB1xxx_SOC=y
+1
drivers/tty/serial/Makefile
··· 6 6 obj-$(CONFIG_SERIAL_21285) += 21285.o 7 7 8 8 obj-$(CONFIG_SERIAL_EARLYCON) += earlycon.o 9 + obj-$(CONFIG_SERIAL_EARLYCON_ARM_SEMIHOST) += earlycon-arm-semihost.o 9 10 10 11 # These Sparc drivers have to appear before others such as 8250 11 12 # which share ttySx minor node space. Otherwise console device
+61
drivers/tty/serial/earlycon-arm-semihost.c
··· 1 + /* 2 + * Copyright (C) 2012 ARM Ltd. 3 + * Author: Marc Zyngier <marc.zyngier@arm.com> 4 + * 5 + * Adapted for ARM and earlycon: 6 + * Copyright (C) 2014 Linaro Ltd. 7 + * Author: Rob Herring <robh@kernel.org> 8 + * 9 + * This program is free software: you can redistribute it and/or modify 10 + * it under the terms of the GNU General Public License version 2 as 11 + * published by the Free Software Foundation. 12 + * 13 + * This program is distributed in the hope that it will be useful, 14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 + * GNU General Public License for more details. 17 + * 18 + * You should have received a copy of the GNU General Public License 19 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 + */ 21 + #include <linux/kernel.h> 22 + #include <linux/console.h> 23 + #include <linux/init.h> 24 + #include <linux/serial_core.h> 25 + 26 + #ifdef CONFIG_THUMB2_KERNEL 27 + #define SEMIHOST_SWI "0xab" 28 + #else 29 + #define SEMIHOST_SWI "0x123456" 30 + #endif 31 + 32 + /* 33 + * Semihosting-based debug console 34 + */ 35 + static void smh_putc(struct uart_port *port, int c) 36 + { 37 + #ifdef CONFIG_ARM64 38 + asm volatile("mov x1, %0\n" 39 + "mov x0, #3\n" 40 + "hlt 0xf000\n" 41 + : : "r" (&c) : "x0", "x1", "memory"); 42 + #else 43 + asm volatile("mov r1, %0\n" 44 + "mov r0, #3\n" 45 + "svc " SEMIHOST_SWI "\n" 46 + : : "r" (&c) : "r0", "r1", "memory"); 47 + #endif 48 + } 49 + 50 + static void smh_write(struct console *con, const char *s, unsigned n) 51 + { 52 + struct earlycon_device *dev = con->data; 53 + uart_console_write(&dev->port, s, n, smh_putc); 54 + } 55 + 56 + int __init early_smh_setup(struct earlycon_device *device, const char *opt) 57 + { 58 + device->con->write = smh_write; 59 + return 0; 60 + } 61 + EARLYCON_DECLARE(smh, early_smh_setup);