Posts: 4
Joined: Thu Oct 12, 2017 9:21 pm

Making ttyAMA0 work with U-Boot

Mon Jun 25, 2018 9:11 pm


TL;DR I'd like to be able to use a custom 4.9 rpi kernel build with U-Boot and console=ttyAMA0,115200 as the only console.

I run a custom build using:
- raspberrypi firmware b1a7f4aea6cbd380319c2849ecc5988f9a4dba70 (kernel: Bump to 4.9.80)
- U-Boot 2017.11
- raspberrypi-kernel_1.20180313-1

I can't figure out how to make the serial console work over ttyAMA0 with this configuration.
I've run into a couple of issues:

1. On the first attempt to make this work if the firmware applies the pi3-disable-bt overlay there was no U-Boot output, just a black screen. I put this down to that maybe the space U-Boot allocates for the DT is not sufficient and U-Boot tripped up on the device tree passed by the firmware. Not knowing U-Boot enough to find the root cause in its source, I attempted to apply the overlay manually in U-Boot, which mostly worked.

Code: Select all

fdt addr ${fdt_addr};
fdt resize 1024;
fatload mmc 0:1 ${fdt_addr_r} overlays/pi3-disable-bt.dtbo;
fdt apply ${fdt_addr_r};
This runs without errors and comparing the before/after DTs with fdt list there is a seemingly good diff. (I have a diff, if that helps, just did not want to include it in the already legthy post)

2. After applying the overlay in U-Boot, the /chosen bootargs entry in the device tree still contains console=ttyS0,115200, since the firmware rewrites ttyAMA0 to ttyS0 unless the pi3-disable-bt overlay is applied before the DT is passed to the U-Boot. So that is to be fixed as well:

Code: Select all

fdt get value bootargs /chosen bootargs;
setexpr bootargs sub S0 AMA0 "${bootargs}";
fdt set /chosen bootargs "${bootargs}";
Now I thought I have a DT that the real kernel would happily take and use ttyAMA0 as the console.

Code: Select all

Kernel image @ 0x1000000 [ 0x000000 - 0x2f0350 ]
## Loading init Ramdisk from Legacy Image at 02100000 ...
   Image Name:   
   Image Type:   ARM Linux RAMDisk Image (uncompressed)
   Data Size:    63282179 Bytes = 60.4 MiB
   Load Address: 00000000
   Entry Point:  00000000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 2effb600
   Booting using the fdt blob at 0x2effb600
   reserving fdt memory region: addr=0 size=1000
   reserving fdt memory region: addr=2effb600 size=6a00
   Using Device Tree in place at 2effb600, end 2f004fff

Starting kernel ...
But this is the last output on the serial console. The system boots.

According to dmesg all seems well, but there's nothing I can do with the ttyAMA0 device.

Code: Select all

# omitting usb related entries
# dmesg | grep -Ei 'serial|tty' 
[    0.000000] Kernel command line: 8250.nr_uarts=1 bcm2708_fb.fbwidth=1280 bcm2708_fb.fbheight=720 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000  console=ttyAMA0,115200 ipv6.disable=1 consoleblank=0 vt.global_cursor_default=0
[    0.023940] Serial: AMBA PL011 UART driver
[    0.025932] uart-pl011 3f201000.serial: could not find pctldev for node /soc/[email protected]/uart0_pins, deferring probe
[    5.455232] Serial: 8250/16550 driver, 1 ports, IRQ sharing enabled
[    5.879744] uart-pl011 3f201000.serial: cts_event_workaround enabled
[    5.879772] 3f201000.serial: ttyAMA0 at MMIO 0x3f201000 (irq = 87, base_baud = 0) is a PL011 rev2
[    6.834894] console [ttyAMA0] enabled
[    6.918715] uart-pl011 3f201000.serial: no DMA platform data
[    7.407814] usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[    7.878077] usb 1-1.1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
I'm also adding a console on ttyAMA0 in /etc/inittab (Busybox) which seems to be running

Code: Select all

# ps | grep getty
  327 root     /sbin/getty -L ttyAMA0 115200
Yet, I see no output or the login prompt.

I compared the output of stty to another system where the firmware boots zImage directly and also applies the pi3-disable-bt overlay and the console over ttyAMA0 works.

Code: Select all

speed 115200 baud;stty: /dev/ttyAMA0
 line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt -echoctl -echoke

// WORKING (diff. system with same kernel, but not booted by U-Boot)
speed 115200 baud;stty: /dev/ttyAMA0
 line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = 
; eol2 = <undef>;
swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon ixoff
-iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon -iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke
I don't know where the differences stem from, but even after manually making changes to the non-working tty to match the working one there's no output.

If I simply use the "basic" device tree and ttyS0 as the only console, I can boot from U-Boot and use the serial console too, but since I don't need BT (kernel as well built without BT support) and would like to overclock as well I would prefer the console be put on the PL011 UART.

One possible culprit I thought of is that if I want to see U-Boot output at all, I need to set enable_uart=1 in config.txt. Maybe it mangles the DT in a way that after applying the overlay in U-Boot, ttyAMA0 is seemingly functional, but not quite?
See viewtopic.php?p=1317741#p1317741

Thanks for the help in advance.

Posts: 1
Joined: Sun Aug 12, 2018 8:14 pm

Re: Making ttyAMA0 work with U-Boot

Sun Aug 12, 2018 8:24 pm


I'm in the same boat as you. Although, I tried a different strategy:

I "manually" overlayed the rpi3-miniuart-bt.dtbo into the bcm2710-rpi-3-b.dtb.

The fusion generated a working dtb (I tried this dtb without uboot and booting directly to my Kernel, ttyAMA0, with pl011, was rotated to the GPIOs).

The problem was that this generated dtb doesn't rotate the pins to ttyAMA0 when UBOOT is used I'm still using the nr_uarts.8250=1 as a bootarg.

As shown in /proc/device-tree, my dtb is applied, but it seems that start.elf does something else when the generated dtb is loaded.

This something else is what I don't know right now.

Return to “Advanced users”

Who is online

Users browsing this forum: No registered users and 9 guests