April 2013

Identifying unknown hardware a Pi running FreeBSD

I’ve been building FreeBSD-CURRENT images for my Pi, and I’ve noticed I have this: ugen0.5: <vendor 0x7392> at usbus0 So, it turns out I have one of these plugged in, and it seems likely that the unknown USB device is ugen0.5.  So firstly, there is the question of “ugen”.  You can read about it here.  Essentially when FreeBSD finds a USB device it doesn’t have a specific driver for, it assigns it the ugen driver.   In my case, the driver is attached to device 0, endpoint 5. To get more info, I can use usbconfig. root@raspberry-pi:/home/tom # usbconfig -d ugen0.5 dump_info ugen0.5: <product 0x7811 vendor 0x7392> at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (500mA) The product code noted in by usbconfig, is 0x7811, which matches with the Edimax 7811. So to find out what “vendor 0x7392” is, I used http://usb-ids.gowdy.us/index.html. If you search in this file, you’ll find this: 7392 Edimax Technology Co., Ltd 7711 EW-7711UTn nLite Wireless Adapter [Ralink RT2870] 7717 EW-7717UN 802.11n Wireless Adapter [Ralink RT2870] 7718 EW-7718UN 802.11n Wireless Adapter [Ralink RT2870] 7722 EW-7722UTn 802.11n Wireless Adapter [Ralink RT307x] 7811 EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS] So, my device “ugen0.5” is the Edimax EW-7811Un.  It uses a Realtek  RTL8188CUS chipset.   Some Edimax devices are supported by the rum driver, but that driver appears to support the Ralink chipset, rather than Realtek.  If FreeBSD did support this chipset, it might be more likely to be supported by the urtw driver.  The man page doesn’t mention the 8188CUS Realtek chipset, however. In fact, you can look at the source for the WLAN USB drivers in FreeBSD here and you will find the source for the urtw driver here.  It supports the RTL 8187B. If you take a look in /sys/dev/usb/usbdevs, you will see a list of the USB devices FreeBSD knows about.  There are some Edimax devices, and the 7811 is listed: /* Edimax products */ 1556 product EDIMAX EW7318USG 0x7318 USB Wireless dongle 1557 product EDIMAX RT2870_1 0x7711 RT2870 1558 product EDIMAX EW7717 0x7717 EW-7717 1559 product EDIMAX EW7718 0x7718 EW-7718 1560 product EDIMAX EW7811UN 0x7811 EW-7811Un So, it appears that FreeBSD knows that it’s a ED7811UN, but RTL8188 chipset is not supported.

Creating a custom FreeBSD build for Raspberry Pi

The default FreeBSD kernel for Raspberry Pi can be found here in the FreeBSD source browser.  It’s everything you need to boot FreeBSD on a Pi, and includes GPIO support.  However, the Pi is a nice small computer, so it’s likely that you’ll want it to include options such as Wifi, and pf.  In my case, I wanted IPSEC and support for USB Serial via uftdi. In order to add drivers to the kernel, it’s useful to have a list of the drivers that can be added.  That exists here.  The man pages, are a useful place to look up what a specific driver does, what hardware it supports, etc. I added this stuff. # WLAN required for wireless device wlan device wlan_wep device wlan_ccmp device wlan_tkip # USB wireless support device ehci device uhci device ohci device wlan_amrr device firmware device urtw device zyd device ural device upgt device uath device run device rum # USB ethernet support device smcphy device mii device smsc # USB serial # device uftdi #proc filesystem options PROCFS #Process filesystem (requires PSEUDOFS) options PSEUDOFS #Pseudo-filesystem framework #pf device pf # IPsec interface. device enc I also renamed my kernel configuration ident RPI-B-WIFI The kernel options I added give me: WLAN support All the USB Wifi drivers pf, the packet filter the /proc filesystem the enc device, for IPSEC uftdi I copied this kernel configuration (name RPI-B-WIFI) to the right spot on my local source tree cp RPI-B-WIFI src/FreeBSD/head/sys/arm/conf/ Then I used the freebsd-arm-tools to create a 4GB disk image, with this kernel, a small swap, and the full ports tree: sh build-arm-image.sh -s4 -u -p -mtom@khubla.com -w512 -kRPI-B-WIFI

A simple FreeBSD GPIO Example

I’ve been making FreeBSD-Current builds for my Raspberry Pi.  Naturally I wanted to try out the GPIO support to find out just how simple it is to use.   Here’s an example, and the full code is here. int main (int argc, char *argv[]) { char *device = “/dev/gpioc0”; int gpiofd = open(device, O_RDWR); if (-1!=gpiofd) { // get total pins int maxpin=0; if (ioctl(gpiofd, GPIOMAXPIN, &maxpin) < 0) { perror(“ioctl(GPIOMAXPIN)”); exit(1); } else { printf(“GPIO has %d pins\n”,maxpin); // walk the pins printf(“pin# description capabilties flags\n”); for (int i = 0; i <= maxpin; i++) { struct gpio_pin pinStatus; pinStatus.gp_pin=i; int r = ioctl(gpiofd, GPIOGETCONFIG, &pinStatus); if ( r>= 0) { printf(“%i: %s 0x%x 0x%x\n”,i, pinStatus.gp_name, pinStatus.gp_caps, pinStatus.gp_flags); } else { printf(“failed to get status of pin %d with status %d\n”,i,r); } } } } else { printf(“failed to open device with error%d\n”,gpiofd); } }

freebsd-arm-tools

I’ve had the opportunity to make some updates to the freebsd-arm-tools.   If you’re interested in trying FreeBSD-current on a Raspberry Pi, I’ve posted a build at http://files.khubla.com/freebsd-raspberry-pi/ which has full Wifi and pf support.  If you’re interested, the kernel configuration is here. Installing the FreeBSD on the Pi is simple.  Firstly, get an image, such as this one http://files.khubla.com/freebsd-raspberry-pi/FreeBSD-HEAD-r249996-ARMv6-RPI-B-WIFI-3GB.img.tgz Extract the Image tar zxvf FreeBSD-HEAD-r249907-ARMv6-RPI-B-WIFI-4GB.img.tgz Unmount the SD card sudo diskutil unmount /dev/disk1s1 Burn the image to the SD card sudo dd if=FreeBSD-HEAD-r249907-ARMv6-RPI-B-WIFI-4GB.img of=/dev/rdisk1 bs=1m Unmount the SD again sudo diskutil unmount /dev/disk1s1 Then, boot the Pi from the SD card.   ssh to root is disabled, however you can log in as username “pi” with password “raspberry”, and su to root.