Baud games#
Sun, 07 Jan 2018 11:46:21 +0000
Epiphany (n): (1) January 6 observed as a church festival in commemoration of the coming of the Magi as the first manifestation of Christ to the Gentiles or in the Eastern Church in commemoration of the baptism of Christ; (2) a moment of sudden and great revelation or realization.
Milestone
This week in NixWRT was typified by lots of trying stuff that didn't work followed by an unexpected achievement: I have a shell running on the actual hardware!
When we left off last week , if you will recall, we had a kernel that
booted most of the way to mounting the root filesystem and
executing init
but not quite, and for some odd reason it booted a
little bit further if I lied to it about the console device. Since then:
- becaause only about half the time its failure mode was "reboot" and the other half it was "hang requiring someone to physically push the reset button" I wrote a small and shonky kernel patch to allow enabling the watchdog timer at boot. This makes remote development much more pleasant. Or indeed, possible.
- I learnt quite a lot (though probaby not enough to be dangerous) about how the kernel boots . Specifically, that it attempts to open
/dev/console
on the root filesystem before it has even mounted the root filesystem you asked it to mount - and that apparently this should never fail . Turns out this is probably even true - although the logic in the Makefile is a bit weird and I haven't fully understood it, one ofinitramfs.o
ornoinitramfs.o
sets up a ramfs containing (your specified cpio archive) or (a device node for/dev/console
) as root, and then you can open the console device before you have mounted the actual root filesystem. I don't know why initramfs is dependent on the initrd config (they are two quite different things), but I took that option out to be sure.
- None of this is at all new, of course, but it is newer than last time I really dug into Linux booting which was back when LILO was normal and rdev was still even a thing.
- But it still wasn't actually working, so I decided to try downgrading to 4.4 on the basis that that's what the newest and spangliest version of OpenWRT^WLEDE uses. This time it got as far as displaying
ar933x-uart: ttyATH0 at MMIO 0x18020000 (irq = 11, base_baud = 1562500) is a ARy
- slightly earlier in the boot sequence - and then started printing gibberish. "Aha", says I, "that looks like wrong baud rate, maybe it only thinks it knows how to speak at 250000", and indeed, when I switched fromconsole=250000
toconsole=115200
- and changed the Arduino baud rate to match - I had a shell prompt!
- 24 hours later it occured to me to wonder if the problem we started with is that 4.14 also can't talk at 250000 but is just differently broken, so I tried switching to 115200 there as well, and bingo - that worked too. tl;dr it all turned out to be very simple.
This is simultaneously a victory and a complete PITA, because there's no way to change the baud rate in this feature-impoverished branch of u-boot , so every time I reboot I have to change speed back and forth to talk to the bootloader. It would be nice if we could get it to work at 250000 (perhaps the u-boot console code has some pointers), or find a way to make u-boot speak more slowly, and I will probably look at that at some point.
Other things to do
- The next priority is to try porting the OpenWRT ag71xx ethernet driver so it can speak to the network: whether I embark on the (rather high-risk ) attempt to reinstall u-boot will depend mostly on how much the ensuing baud rate twiddling annoys me.
- convert to musl or uclibc for smaller binaries
- flesh out the filesystem a bit so we can run anything useful
- try it on the actual target device and not the Yun (which as I keep saying, is not mine) - or if it turns out I've completely toasted that router, pick up a cheap GL-AR150 or something)
- forward port to nixpkgs master (after #30882 has landed)
[ Postemporaneous edit: the next thrilling installment in this series is now up at https://ww.telent.net/2018/1/15/in_the_nix_of_time ]