PocketBeagle on Arch

This forum is for supported devices using an ARMv7 Texas Instruments (TI) SoC.

PocketBeagle on Arch

Postby summers » Sun Mar 11, 2018 11:29 am

Have just managed to boot a pocket beagle on arch!

Hardware: http://beagleboard.org/pocket

It basically boots on the am33x image, but some changes needed.

First uboot needs this patch added: https://lists.denx.de/pipermail/u-boot/2018-March/322188.html. The patch is already upstream on uboot, don't know if it will come out on 2018-03 uboot; but if not it should be in the one after.

This means that uboot recognises the name the board has in flash (A335PBGL), and then automatically selects the pocket beagle device tree. The current device tree for the pocket beagle is one that Robert Nelson did, its not mainline but is in the arch image. Now I'd expect there to quickly be a mainline device tree, Roberts device trees are huge:

$this->bbcode_second_pass_code('', '-rw-r--r-- 1 root root 56866 Mar 7 02:13 am335x-boneblack.dtb
-rw-r--r-- 1 root root 121484 Mar 7 02:13 am335x-pocketbeagle.dtb')

So when the kernel tree has a working device tree, I guess we should switch to that.

Next problem, out of the box, the PocketBeagle only has the usb-otg connection enabled, so there is no ethernet port mounted on the board. This means that the default image should bring up usb gadgets, I've configured so that both a usb serial connection and an ethernet connection come up using libcomposite. This isn't the nicest interface but it works.

My gut feeling, we should make this change to the default am33x tree, e.g. it would be better on the beagle bone black if the usb connections came up be default. For the black this isn't essential, but is nice; for the pocket its essential.

I'll give details below of the changes I made in detail. Can we add the Pocket Beagle to the boards supported?
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm

Re: PocketBeagle on Arch

Postby summers » Sun Mar 11, 2018 1:06 pm

So more details. First uboot changes.

I started from uboot source code, 2018.03-rc4. The above patch:

https://lists.denx.de/pipermail/u-boot/2018-March/322188.html

Applied cleanly.

I tried applying the ArchArm patch:

https://archlinuxarm.org/packages/armv7h/uboot-beaglebone/files/0001-arch-linux-arm-modifications.patch

But that wasn't clean, checked the code, and many of the ArchArm patches have already been applied in the rc4 release.

Hence went with just 2018.03-rc4 + the PocketBeagle patch. I complied in the standard arch way, on a beagleboneblack:

$this->bbcode_second_pass_code('', ' make distclean
make am335x_boneblack_defconfig
make')

Then installed the MLO and u-boot.img as usual. This then booted fine. So I guess we should review the ArchArm patch - as I didn't use it and it doesn't seem needed.
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm

Re: PocketBeagle on Arch

Postby summers » Sun Mar 11, 2018 1:30 pm

Next we need to bring up the usb gadgets, we do this via libcomposite, so need to make sure that module gets loaded:

$this->bbcode_second_pass_code('', 'echo libcomposite > /etc/modules-load.d/usb_otg.conf')

libcomposite has a clumsy filesystem way of bringing up usb gadgets, so created a script to populate in /etc/libcomposite.conf

$this->bbcode_second_pass_code('', '#!/bin/bash
cd /sys/kernel/config/usb_gadget/
mkdir usbg
cd usbg
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB2
mkdir strings/0x409
echo "fedcba9876543210" > strings/0x409/serialnumber
echo "PocketBeagle" > strings/0x409/manufacturer
echo "USB OTG" > strings/0x409/product
mkdir -p configs/c.1/strings/0x409
echo "Config 1: ECM network" > configs/c.1/strings/0x409/configuration
echo 250 > configs/c.1/MaxPower
mkdir functions/acm.usb0
ln -s functions/acm.usb0 configs/c.1/
mkdir -p functions/ecm.usb0
# echo $HOST > functions/ecm.usb0/host_addr # use this to set the far end mac address - address random otherwise
# echo $SELF > functions/ecm.usb0/dev_addr # use this to set our mac address - address random otherwise
ln -s functions/ecm.usb0 configs/c.1/
ls /sys/class/udc > UDC
')
Note I only brought up a acm & ecm modern u_ kernel modules for serial and ethernet. This gets away from the legacy g_ kernel modules. Now for interfacing through to windows, wonder if we should also bring up a rndis style ethernet. Me as I just use linux, and think CDC is the way of doing thing, I just used the above.

This script needs running by systemd, so need to add that. Create the file: /etc/systemd/system/usb-otg.d/usb-otg/usb-otg.service

$this->bbcode_second_pass_code('', '[Unit]
Description=Configure the usb gadget services using libcomposite
After=systemd-modules-load

[Service]
Type=oneshot
ExecStart=/etc/libcomposite.conf
')

and add it to services started:

$this->bbcode_second_pass_code('', 'ln -s /etc/systemd/system/usb-otg.d/usb-otg.service /etc/systemd/system/multi-user.target.wants/')

The After line is so hopefully the code is run after the libcomposite module is loaded.

On the serial connection, we need to have getty running:

$this->bbcode_second_pass_code('', 'ln -s /usr/lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@ttyGS0.service')

Ideally we would have dhcpd running on the ethernet - but that code needs debugging, systemd is giving an error right now so I'll have to check that out and report back.
Last edited by summers on Fri Mar 30, 2018 12:01 pm, edited 2 times in total.
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm

Re: PocketBeagle on Arch

Postby summers » Mon Mar 12, 2018 10:51 am

I should also say something about network configuration, as its different from usual. Usually a machine with an Ethernet port, you plug into your router. Your router is expecting machines to connect, and so will do routing, and also give out ip details by running dhcpd.

Now the PocketBeagle only gets plugged in via its USB connection to a computer. Even if the router has a usb connection, usually it won't bring up a network on usb - they don't expect a usb gadget being plugged in, only a memory stick. Computers on the other had, typically do have the software needed to bring up a usb ethernet connection; but they don't normally give out ip details.

So with the PocketBeagle we reverse the set up, rather than asking for ip details via dhcp, we need to give ip details - as thats what the host computer is expecting.

We do this by creating the file /etc/systemd/network/usb0.network
$this->bbcode_second_pass_code('', '[Match]
Name=usb0

[Network]
DNS=192.168.2.1

[Address]
Address=192.168.7.2/30

[Route]
Gateway=192.168.7.1
')
So it brings the usb ethernet up with address 192.168.7.2 and expects the computer on the far end to give the interface the number 192.168.7.1. The 192.168.7.x range is what the beagle bone black used, its a good range, as most home routers are down on 192.168.1.x. Note that I've put in the DNS section the ip number of my router - so everyone that sets this up would need to do this. Now we could go for a generic DNS like google with 8.8.8.8, and that may be better.

Now this should bring up the interface, but for me it wasn't working - I think because the script above bringing up libcomposite, takes about 14s to complete. As this wasn't bringing up the interface, its why at the end of that script I bring up the interface by hand. However the rest of the systemd networkd stuff works, routing to 192.168.7.1 is set up, as is DNS. So at some stage we'll need to work out why networkd wasn't bringing up usb0.

And now to the bit I havn't got working, dhcpd. The above brings up the interface on the PocketBeagle, but we also need to bring up the interface on the host computer into which we are plugged. Now that computer, on seeing a new ethernet connection, usually brings up dhcp on it - to see how its configured. Hence we need to run dhcpd on usb0.

The configuration is done in /etc/dhcpd.conf:
$this->bbcode_second_pass_code('', 'subnet 192.168.7.0 netmask 255.255.255.252 {
range 192.168.7.1 192.168.7.1;
}')
Now we'll need to start dhcpd, so that needs installing - and we need to create something to start this up in systemd. This is the bit that isn't working right now - so I'll have to leave that hanging ...
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm

Re: PocketBeagle on Arch

Postby summers » Wed Mar 21, 2018 8:57 pm

And now for the last few bits. I wanted a few days to see if I could find the problem with dhcpd. The command works fine on the pocket beagle, but on the beagle bone black gives a strange systemd error - why isn't clear, need to keep digging there.

Anyway in /etc/libcomposite.conf the last two lines setting the usb0 ethernet up aren't needed, /etc/systemd/network/usb0.network does the job file.

Now dhcpd, we only want to run on usb0, so if this is used on the other beagle products, dhcp doesn't run on eth0.

So first off create: /etc/systemd/system/dhcpd4\@.service
$this->bbcode_second_pass_code('', '[Unit]
Description=IPv4 DHCP server on %I
Wants=network-online.target
After=network-online.target

[Service]
Type=forking
PIDFile=/run/dhcpd4.pid
ExecStart=/usr/bin/dhcpd -4 -q -pf /run/dhcpd4.pid %I
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target')

The network-online.target seems needed - as if dhcpd comes up before the usb0 interface is created by libcomposite - then it fails. libcomposite seems kicked off very late in the boot, "systemd-analyze blame" says "695ms usb-otg.service". So comparing startup of libcomposite and dhcpd:
$this->bbcode_second_pass_code('', 'systemd-analyze critical-chain usb-otg.service
The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.

usb-otg.service +695ms
`-basic.target @6.570s
`-sockets.target @6.558s
`-dbus.socket @6.543s
`-sysinit.target @6.515s
`-systemd-timesyncd.service @5.819s +683ms
`-systemd-tmpfiles-setup.service @5.401s +381ms
`-local-fs.target @5.342s
`-local-fs-pre.target @5.323s
`-lvm2-monitor.service @1.771s +3.530s
`-lvm2-lvmetad.service @2.463s
`-lvm2-lvmetad.socket @1.379s
`--.mount @839ms
`-system.slice @839ms
`--.slice @839ms
systemd-analyze critical-chain dhcpd4@usb0.service
The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.

dhcpd4@usb0.service +370ms
`-network-online.target @23.263s
`-systemd-networkd-wait-online.service @3.473s +19.770s
`-systemd-networkd.service @3.206s +242ms
`-systemd-udevd.service @2.764s +416ms
`-systemd-tmpfiles-setup-dev.service @2.506s +216ms
`-systemd-sysusers.service @2.028s +323ms
`-systemd-remount-fs.service @1.369s +529ms
`-systemd-journald.socket @1.195s
`--.mount @839ms
`-system.slice @839ms
`--.slice @839ms
')
So maybe some optimisation to do. So finally to set up dhcpd on usb0
$this->bbcode_second_pass_code('', 'ln -s /etc/systemd/system/dhcpd4@.service /etc/systemd/system/multi-user.target.wants/dhcpd4@usb0.service')
Now although there is a device tree for the pocketbeagle, it isn't mainline. I hope to get time to write this, and submit to mainline.

On the BeagleBoneBlack the errors I get btw:
$this->bbcode_second_pass_code('', 'Mar 21 21:01:23 BBB systemd[1]: Starting Configure the usb gadget services using libcomposite...
Mar 21 21:01:24 BBB kernel: usb0: HOST MAC 48:6f:73:74:50:43
Mar 21 21:01:24 BBB systemd-networkd[148]: usb0: IPv6 successfully enabled
Mar 21 21:01:24 BBB kernel: usb0: MAC 42:61:64:55:53:42
Mar 21 21:01:24 BBB systemd-networkd[148]: usb0: Could not bring up interface: Cannot assign requested address
Mar 21 21:01:25 BBB systemd[1]: Starting IPv4 DHCP server on usb0...
Mar 21 21:01:25 BBB systemd[1]: Started Configure the usb gadget services using libcomposite.
Mar 21 21:01:25 BBB dhcpd[192]: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file
Mar 21 21:01:25 BBB dhcpd[192]: Source compiled to use binary-leases
Mar 21 21:01:25 BBB dhcpd[192]: Wrote 1 leases to leases file.
Mar 21 21:01:25 BBB dhcpd[192]:
Mar 21 21:01:25 BBB dhcpd[192]: No subnet declaration for usb0 (no IPv4 addresses).
Mar 21 21:01:25 BBB dhcpd[192]: ** Ignoring requests on usb0. If this is not what
Mar 21 21:01:25 BBB dhcpd[192]: you want, please write a subnet declaration
Mar 21 21:01:25 BBB dhcpd[192]: in your dhcpd.conf file for the network segment
Mar 21 21:01:25 BBB dhcpd[192]: to which interface usb0 is attached. **
Mar 21 21:01:25 BBB dhcpd[192]:
Mar 21 21:01:25 BBB dhcpd[192]:
Mar 21 21:01:25 BBB dhcpd[192]: Not configured to listen on any interfaces!
Mar 21 21:01:25 BBB dhcpd[192]:
Mar 21 21:01:25 BBB dhcpd[192]: If you think you have received this message due to a bug rather
Mar 21 21:01:25 BBB dhcpd[192]: than a configuration issue please read the section on submitting
Mar 21 21:01:25 BBB dhcpd[192]: bugs on either our web page at www.isc.org or in the README file
Mar 21 21:01:25 BBB dhcpd[192]: before submitting a bug. These pages explain the proper
Mar 21 21:01:25 BBB dhcpd[192]: process and the information we find helpful for debugging.
Mar 21 21:01:25 BBB dhcpd[192]:
Mar 21 21:01:25 BBB dhcpd[192]: exiting.
Mar 21 21:01:25 BBB systemd[1]: dhcpd4@usb0.service: Control process exited, code=exited status=1
Mar 21 21:01:25 BBB systemd[1]: dhcpd4@usb0.service: Failed with result 'exit-code'.
Mar 21 21:01:26 BBB systemd[1]: Failed to start IPv4 DHCP server on usb0.
')
So its networkd failing to bring up usb0 for some reason ....

And networkctl status:
$this->bbcode_second_pass_code('', 'networkctl status usb0
* 3: usb0
Link File: /usr/lib/systemd/network/99-default.link
Network File: /etc/systemd/network/usb0.network
Type: gadget
State: off (configuring)
Path: platform-musb-hdrc.0
Driver: g_ether
HW Address: 42:61:64:55:53:42
DNS: 192.168.2.1
')
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm

Re: PocketBeagle on Arch

Postby summers » Fri Mar 30, 2018 12:07 pm

OK update on getting the usb ethernet to come up automatically, that wasn't working on the BBB. It didn't make much sense on the BBB, clearly a race condition, as rerunning the systemd network - and the interface came up as expected. Anyway the race condition didn't make much sense, and didn't happen on the PocketBeagle. Anyway after a few days, a "pacman -Suy" cured the problem on the BBB, what was changed I have no idea.

So I've changed the post above, to only bring up the ethernet ip using networkd, as one should in systemd.

Checked in the PocketBeagle patch for uboot came out on 2018-03; and alas it didn't make it - so I expect it next time. This means that uboot still needs the above patch to work on the Pocket Beagle.
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm


Return to Texas Instruments (TI)

Who is online

Users browsing this forum: No registered users and 1 guest