Skip to content

Instantly share code, notes, and snippets.

@sarnold
Last active July 8, 2020 11:17
Show Gist options
  • Save sarnold/2e244fa8580ec715321a515c72535d4f to your computer and use it in GitHub Desktop.
Save sarnold/2e244fa8580ec715321a515c72535d4f to your computer and use it in GitHub Desktop.
Setup Udoo Neo with mainline kernel and u-boot, connect with usb serial/ethernet

Create a mainline SDCard for Udoo Neo boards

Following the general process documented here (for the Udoo board) we can also create the equivalent card for the basic Neo board variants using mainline u-boot and linux-stable (with one or two minor changes). Note the card has a single partition for the rootfs and no /boot partition.

Since the state of vendor-specific support for various boards in mainline can be highly variable, we'll add the same features for Neo boards that are commonly found for the other "reference" boards documented on the Linux On Arm wiki above so we can follow the same process and use the same variables in the uEnv.txt file.

Note

The vendor u-boots (udoo and Freescale) have more supported board subtypes but their use of uEnv.txt is quite different than that described here.

First you'll need to clone both U-boot and the Linux kernel, and retrieve the u-boot (ala RCN) patch. You'll also need a cross-compiler; you can follow the Udoo wiki page above or build one with crossdev.

Bootloader: U-Boot

Download:

$ cd ~/src/
$ git clone https://github.com/u-boot/u-boot
$ cd u-boot/
$ git checkout v2017.ll-rc4 -b v2017.ll-rc4-neo

Patches:

$ wget http://dev.gentoo.org/~nerdboy/files/0001-ARM-udoo-neo-uEnv.txt-bootz-single-partition-config-v2017.11-rc4.patch
$ patch -p1 < 0001-ARM-udoo-neo-uEnv.txt-bootz-single-partition-config-v2017.11-rc4.patch

Configure and Build:

$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- udoo_neo_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

Note

Be sure and use the correct compiler triplet for CROSS_COMPILE above, and make sure the cross compiler bin directory is in the front of your path.

Linux Kernel

We'll use the RCN scripts to build the kernel, modules, device tree binaries and copy them to the deploy directory.

Download:

$ cd ~/src/
$ git clone https://github.com/RobertCNelson/armv7-multiplatform
$ cd armv7-multiplatform/
$ git checkout origin/v4.12.x -b v4.12.x-neo
$ ./build_kernel.sh

Choose one of the filesystems from the wiki page or use a Gentoo stage 3 (or your own custom rootfs that matches your toolchain). Note that the Debian and Ubuntu options from the rcn-ee.com URL are fully supported with both the standard upstream repositories and the rcn-ee repositories (the latter includes many kernel images and embedded tools).

Debian 9 login

debian: temppwd

Ubuntu 16.04 LTS login

ubuntu: temppwd

Setup microSD card

For these instruction we are assuming, DISK=/dev/mmcblk0, lsblk is very useful for determining the device id. If you are using a USB card reader, the device is most likely /dev/sdX, so replace mmcblk0 with sdX, where X is the correct device for your card reader. Make sure you use the correct device!!

$ export DISK=/dev/mmcblk0
$ cd ~/src
$ sudo dd if=/dev/zero of=${DISK} bs=1M count=10
$ sudo dd if=./u-boot/SPL of=${DISK} seek=1 bs=1k
$ sudo dd if=./u-boot/u-boot.img of=${DISK} seek=69 bs=1k

Follow the wiki page for Udoo, but with the following exceptions.

Note that ext4 64-bit metadata does not work, so use this command to format the rootfs:

$ mkfs.ext4 -L rootfs -O ^metadata_csum,^64bit /dev/<YOUR DEVICE>

Since we want the serial console to actually work for logins, and we also want "normal" device names for ethernet/wifi, we'll make the following small adjustments.

  • edit uEnv.txt and add the following line
cmdline=uart_from_osc clk_ignore_unused console=tty0 console=tty1 net.ifnames=0 console=ttymxc0,115200
  • add the following serial config file to /etc/init/

Contents of /media/rootfs/etc/init/serial.conf:

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
exec /sbin/getty 115200 ttymxc0

Gadget Serial and Ethernet

If you don't have the Neo serial breakout or your own FTDI to hook up, then you probably need the USB serial interface. After you've made the SDCard, make the following changes before you boot:

  • make a systemd service for the "g_cdc" module
  • enable it

The above module will enable both usb0 and ttyACM0 on your host machine. You also need to add the following to /etc/securetty if it's not there already:

# USB Gadget serial
ttyGS0
ttyGS1

To make the gadget serial login actually work, we need to create a service file for systemd so it knows there's a new serial getty. Create the following file with these contents:

$ cat /etc/systemd/system/usbcon.service
[Unit]
Description=USB console on ttyGS0

ConditionKernelCommandLine=usbcon

[Service]
Type=oneshot
RemainAfterExit=yes

ExecStart=/sbin/modprobe g_cdc
ExecStart=/bin/systemctl start serial-getty@ttyGS0.service

ExecStop=/bin/systemctl stop serial-getty@ttyGS0.service

[Install]
WantedBy=getty.target

Next, add the following parameters to your uEnv.txt file:

optargs=usbcon console=ttyGS0,115200

Finally, enable the systemd service:

$ sudo systemctl enable usbcon

Now your new serial getty will run on boot as long as "usbcon" is present in your kernel args. It may have line-wrapping weirdness, but if you wait for it to boot up and open a console with ttyACM0 115200, hit enter and you should get a login prompt.

Depending on which network interface you need to use, you may also want to setup the /etc/network/interfaces file for Debian/Ubuntu; if you're using Gentoo or your own custom rootfs then you know what to do...

If you only have a serial console login, then you should use the above config and reboot using a micro USB cable for power (as opposed to the barrel jack). Then you can configure the host computer's usb0 network interface to allow your Neo to install some extra packages using your desktop as a gateway.

The gadget ethernet device can be configured just like any other, whether manually, with a script, or your distro’s config tools. Currently this is not fully automated (as compared to BeagleBone) so you'll need to manually start both ends for now.

To use the legacy gadget ethernet interface add the following to the interfaces file:

$ cat /etc/network/interfaces
auto lo
iface lo inet loopback

#auto eth0
#iface eth0 inet dhcp

# Ethernet/RNDIS gadget (g_ether)
allow-hotplug usb0
auto usb0
iface usb0 inet static
    address 192.168.7.2
    netmask 255.255.255.0
    network 192.168.7.0
    gateway 192.168.7.1
    dns-nameservers <your DNS server address>

If you have ethernet and want to use it, configure eth0, otherwise use the USB ethernet config above. If you setup USB serial above, then you already have the module set if usbcon is enabled, otherwise add the following to your modules file:

$ cat /etc/modules

g_cdc

Note

If the usb0 interface is not ready on boot-up, then log into your serial console and bring it up manually with this command: $ sudo ifup usb0

To bring up the host side and allow internet access you can use something like this script:

# cat ~/bin/bbnet
#! /bin/sh
#
ifconfig usb0 192.168.7.1 netmask 255.255.255.0 up
route add -net 192.168.7.0 netmask 255.255.255.0 usb0
iptables -t nat -F
iptables -t nat -A POSTROUTING -j SNAT -o eth0 --to <your eth0 IP address>
echo 1 > /proc/sys/net/ipv4/ip_forward

and substitute your local host-side ethernet address.

The above package repos already support the onboard wireless in the default kernel configs as well as with firmware and setup packages if desired. For example, the following packages can be used to connect the wifi to your AP via a web setup:

$ sudo apt-get update
$ sudo apt-get install bash-completion screen less
$ sudo service apache2 stop
$ sudo apt-get install firmware-ti-connectivity comitup

The comitup package provides a web interface to configure the wifi to connect to a local wifi hotspot and save the configuration. Once the package is installed, it will fire up a hotspot called comitup-NNNN, where <nnnn> is a persistent 4-digit number. The website is accessible on that hotspot as ht​tp://comitup.local or ht​tp://comitup-<nnnn>.local from any device which supports [Bonjour/ZeroConf/Avahi] zeroconf. For other devices, use a Zeroconf browser (Android, Windows) to determine the IP address of the "Comitup Service", and browse to http://<ipaddress>. In most cases, this address will be http://10.42.0.1/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment