Booting nanoBSD on the Alix2c2 SBC

A friend and I recently purchased a couple of Alix2c2 SBCs from PC Engines with the intention of running FreeBSDs nanoBSD on them.

However, getting nanoBSD to boot on the Alix board turned out to require a few customizations which I will post here in the hope of saving others the trouble.

The Alix2c2 reports the following at boot time for the noname 1GB CF card from PC Engines:

PC Engines ALIX.2 v0.99
640 KB Base Memory
261120 KB Extended Memory

01F0 Master 044A CF 1GB                                  
Phys C/H/S 1966/16/63 Log C/H/S 983/32/63

Running diskinfo(8) on the CF in an USB CF card reader on another FreeBSD machine revealed the capacity of the card:

$ diskinfo /dev/da0
/dev/da0        512     1014644736      1981728 967     64      32

Gettng nanoBSD to boot on the Alix2c from the 1GB CF card required the following customizations to the nanoBSD configuration file:

# Drive geometry
NANO_DRIVE=ad0
NANO_MEDIASIZE=`expr 1014644736 / 512` # size from diskinfo(8) on the UBS CF card reader
NANO_HEADS=32 # heads from the logic CHS information at boot time
NANO_SECTS=63 # sects from the logic CHS information at boot time

# Boot loader
NANO_BOOT0CFG="-o nopacket -s 1 -m 3" # nopacket seems to be required by tinyBIOS

Before booting nanoBSD, hit ‘s’ on the Alix2c2 serial console during RAM testing and switch the BIOS to LBA mode and 9600 baud serial console (default is 38400 baud, but this wont work with boot0sio). Re-attach to the serial console with 9600 baud and reboot to verify the setup.

One Month of iPhone 3G

Having had my iPhone 3G for a month now, I think it’s time for a quick status report slash review slash list of annoyances – in no particular order:

Missing Status Bar Icon for Ringer/Silent Switch
A minor thing, sure, but I can not count how many times I have missed an SMS notification or an incoming call simply because I’ve forgotten to turn the ringer back on upon leaving a meeting. Of course, the switch on the side indicates the current ringer mode, but a visual indication in the top status bar on the display would be nice.

Occasional Crashes
More than a few times when the iPod application was playing music and Safari was busy downloading or scrolling a heavy weight web page, my iPhone crashed or locked up hard – requiring a manual restart (holding down Home and Sleep/Wake button for a few seconds) in order to get back to working condition. Rather annoying. [Update: This seems to have been fixed by update to iPhone OS 2.0.2]

Inconsistent Screen Locking
Locking the screen while the iPod is playing does not lock the volume keys on the side – often resulting in the volume keys being activated by accident while the iPhone is tucked away in my pocket, which is quite annoying. It would be nice to be able to configure this behaviour. Also, double-clicking the Home button while the screen is locked still brings up the iPod controls (if this feature is enabled in Settings) – again, it would be nice if it was configurable if the screen lock should disable double-clicking as well.

Lack of Calendar Synchronization
For some reason, Apple does not (yet?) allow third party applications to access the calendar on the iPhone, and since the built-in calendar can only synchronize with MobileMe and Exchange over the air, this leaves the calendar application pretty much useless if you do not use either of those for your calendar. I’d love to see the calendar opened either opened up for third party applications or at least a way to synchronize the calendar using less … ahem … expensive solutions (e.g. the calendar on my iPod Nano can read a standard *.ics file – the iPhone e-mail client can read a *.vcf file and import its contents into the Contacts application, but it can not open an *.ics file).

Despite the above annoyances I am still quite pleased with my iPhone 3G. It is by far the most advanced mobile device I have ever had, and it beats the features of my previous mobile phones with several lengths. I hope – perhaps I’m just being naive – that the rumoured 2.1 firmware will address some of the above mentioned issues.

Apple iPhone (3G) vs. FreeBSD, take I

No, this post won’t be able to tell you how to synchronize contacts, calendar, bookmarks etc. from your FreeBSD box to your iPhone or iPhone 3G, sorry – still working on that. It will, however, show you how to make FreeBSD recognize your iPhone as a camera device, so that you can download the photos taken with your iPhone to a FreeBSD host.

First of all, make sure you’re using a kernel with ugen(4) support – but either without uhid(4) support or FreeBSD 8-CURRENT in SVN revision 181482 or newer – or manually apply this patch:

[Update: I have just MFC’ed this patch to RELENG_7 (SVN revision 181636) and RELENG_6 (SVN revision 181637), so this patch will be included in FreeBSD 7.1 and 6.4].

Index: sys/dev/usb/usb_quirks.c
===================================================================
--- sys/dev/usb/usb_quirks.c	(revision 181481)
+++ sys/dev/usb/usb_quirks.c	(working copy)
@@ -106,6 +106,10 @@
 	ANY, { UQ_HID_IGNORE }},
  { USB_VENDOR_MGE, USB_PRODUCT_MGE_UPS2,
 	ANY, { UQ_HID_IGNORE }},
+ { USB_VENDOR_APPLE, USB_PRODUCT_APPLE_IPHONE,
+	ANY, { UQ_HID_IGNORE }},
+ { USB_VENDOR_APPLE, USB_PRODUCT_APPLE_IPHONE_3G,
+	ANY, { UQ_HID_IGNORE }},
 
  /* Devices which should be ignored by both ukbd and uhid */
  { USB_VENDOR_CYPRESS, USB_PRODUCT_CYPRESS_WISPY1A,
Index: sys/dev/usb/usbdevs
===================================================================
--- sys/dev/usb/usbdevs	(revision 181481)
+++ sys/dev/usb/usbdevs	(working copy)
@@ -853,6 +853,8 @@
 product APPLE IPOD_08		0x1208	iPod '08'
 product APPLE IPODVIDEO		0x1209	iPod Video
 product APPLE IPODNANO		0x120a	iPod Nano
+product APPLE IPHONE		0x1290	iPhone
+product APPLE IPHONE_3G		0x1292	iPhone 3G
 product APPLE ETHERNET		0x1402	Ethernet A1277
 
 /* Arkmicro Technologies */

Next, make sure you have graphics/gphoto2 and graphics/libgphoto2 (the latter needs to be 2.4.2_1 or later for the iPhone 3G to work) installed.

Plug in the USB cable from your iPhone and verify using dmesg(8) that it shows up as an ugen(4) device as shown below:

kernel: ugen1: <Apple Inc. iPhone, class 0/0, rev 2.00/0.01, addr 2> on uhub4

That’s it – you should now be able to access the photos on your iPhone using ghoto2(1) – just replace ‘Apple iPhone (PTP Mode)’ with ‘Apple iPhone 3G (PTP Mode)’ for the iPhone 3G:

$ gphoto2 --camera 'Apple iPhone (PTP Mode)' -L
There is no file in folder '/'.                                                
There is no file in folder '/store_00010002'.
There is no file in folder '/store_00010002/DCIM'.
There are 7 files in folder '/store_00010002/DCIM/100APPLE'.
#1     IMG_0007.JPG                   49 KB image/jpeg
#2     IMG_0013.JPG                  389 KB image/jpeg
#3     IMG_0022.JPG                   26 KB image/jpeg
#4     IMG_0026.JPG                  358 KB image/jpeg
#5     IMG_0027.JPG                  357 KB image/jpeg
#6     IMG_0028.JPG                  381 KB image/jpeg
#7     IMG_0029.JPG                  377 KB image/jpeg
There is no file in folder '/store_00010002/DCIM/999APPLE'.

See the gphoto2(1) man page for further usage instructions.

Of course, you can also use a graphical client such as graphics/gtkam as long as it uses libgphoto2 for camera access.

Life is too short for (cheap) hardware

I recently acquired a Revoltec Alu Book USB mass storage enclosure for a 2.5″ PATA HDD, which is based on the Myson CE8818 chipset and therefore matched by the (wrongly named, as this matches all CE8818 based devices) following USB quirk in FreeBSD -current:


{ USB_VENDOR_MYSON, USB_PRODUCT_MYSON_HEDEN, RID_WILDCARD,
UMASS_PROTO_SCSI | UMASS_PROTO_BBB,
NO_INQUIRY | IGNORE_RESIDUE
},

The enclosure worked fine for a while, but then started to fail under FreeBSD with heavy disk activity, spewing the following messages in dmesg:


kernel: umass0: on uhub4
root: Unknown USB device: vendor 0x04cf product 0x8818 bus uhub4
kernel: da0 at umass-sim0 bus 0 target 0 lun 0
kernel: da0: < > Removable Direct Access SCSI-2 device
kernel: da0: 40.000MB/s transfers
kernel: da0: 114473MB (234441648 512 byte sectors: 255H 63S/T 14593C)
...
kernel: (da0:umass-sim0:0:0:0): READ(10). CDB: 28 0 8 45 78 6f 0 0 48 0
kernel: (da0:umass-sim0:0:0:0): CAM Status: SCSI Status Error
kernel: (da0:umass-sim0:0:0:0): SCSI Status: Check Condition
kernel: (da0:umass-sim0:0:0:0): ILLEGAL REQUEST asc:20,0
kernel: (da0:umass-sim0:0:0:0): Invalid command operation code
kernel: (da0:umass-sim0:0:0:0): Unretryable error
kernel: g_vfs_done():da0s1a[READ(offset=71050477568, length=36864)]error = 22
kernel: vnode_pager_getpages: I/O read error
kernel: vm_fault: pager read error, pid 27989 (cp)

cp(1), which I used for reproducing the problem, said cp: /foo/bar/baz.txt: Bad address and the destination file was corrupt.

I investigated the possible course of the failure. A dying disk? A quirky chipset? A change in the FreeBSD umass(4) driver or something else?

After having spent weeks of debugging this periodical error, it eventually turned out to be a dying USB HDD enclosure.

Close examination of the PCB showed that some of the lines connecting the HDD connector to the chipset had clearly been repaired before shipping this unit, but no coat of varnish had been given afterwards – leading to corrosion of the PCB over time.

I have just replaced the USB HDD enclosure with a new one (from a different vendor, of course) – and I can no longer reproduce the above problem with the same HDD installed.

Lesson learned: Life is too short for dealing with (cheap) hardware.

CyberCity ADSL using a Cisco SOHO 77

While debugging connectivity issues on my recently installed CyberCity ADSL line, I came to suspect the ZyXEL router supplied to me by the ISP.

Erwin kindly offered to lend me a good old Cisco SOHO 77 ADSL router to test with, which meant I had to find out how to actually configure this device for use with CyberCity.

It didn’t take long, though – below my configuration for reference:

  • dsl654321 is my CyberCity user name
  • 11.22.33.44 is my public IP address
  • The example configuration contains a static PAT for all ports to 192.168.0.2
Current configuration : 2137 bytes
!
version 12.3
no service pad
service timestamps debug datetime localtime show-timezone
service timestamps log datetime localtime show-timezone
service password-encryption
!
hostname dsl654321
!
boot-start-marker
boot-end-marker
!
logging buffered 8192 debugging
enable secret 5 **removed**
!
clock timezone CET 1
clock summer-time CEST recurring last Sun Mar 2:00 last Sun Oct 3:00
ip subnet-zero
ip domain lookup source-interface Loopback0
ip name-server 212.242.40.3
ip name-server 212.242.40.51
!
ip dhcp pool soho77
   network 192.168.0.0 255.255.255.0
   dns-server 212.242.40.3 212.242.40.51
   default-router 192.168.0.1
   lease 0 1
!
interface Loopback0
 ip address 192.168.255.1 255.255.255.0
!
interface Tunnel0
 no ip address
!
interface Ethernet0
 ip address 192.168.0.1 255.255.255.0
 ip nat inside
 no keepalive
 no cdp enable
 hold-queue 100 out
!
interface ATM0
 no ip address
 no atm ilmi-keepalive
 dsl operating-mode ansi-dmt
 pvc 0/35
  encapsulation aal5mux ppp dialer
  dialer pool-member 1
!
interface Dialer0
 ip address negotiated
 ip nat outside
 encapsulation ppp
 dialer pool 1
 dialer-group 1
 ppp authentication pap callin
 ppp chap hostname dsl654321
 ppp chap password 7 **removed CyberCity Password**
!
ip nat inside source list 1 interface Dialer0 overload
ip nat inside source static 192.168.0.2 11.22.33.44 extendable
ip classless
ip route 0.0.0.0 0.0.0.0 Dialer0
no ip http server
!
access-list 1 permit 192.168.0.0 0.0.255.255
dialer-list 1 protocol ip permit
no cdp run
snmp-server engineID local 000000090200000427FD16B9
snmp-server community **removed** RO
snmp-server enable traps tty
banner motd ^C
***************************************
*                                     *
*   UNAUTHORISED ACCESS PROHIBITED    *
*                                     *
***************************************
^C
!
line con 0
 exec-timeout 60 0
 password 7 **removed**
 login
 transport output all
 stopbits 1
line vty 0 4
 exec-timeout 60 0
 password 7 **removed**
 login
 transport input all
 transport output all
!
scheduler max-task-time 5000
sntp server 212.242.32.206
end

FreeBSD Ports commit bit

Someone decided to punish me with a commit bit for FreeBSD Ports – ironically, that same person decided to punish himself by being my mentor :)

Erwin even handed me a sealed envelope containing a piece of paper with a large ‘1’ printed on it at our latest aarhus.pm meeting – I must admit, it took me a while to figure out that it was a ports commit bit!

Anyways, as FreeBSD Ports is in a freeze right now, preparing for the upcoming 6.3 and 7.0 releases, I guess I won’t be committing anything interesting for now…

Soekris BIOS upgrade using cu(1) and lsx(1)

Here’s a quick HOWTO for updating a Soekris net4801 BIOS using cu(1) and lsx(1) from comms/lrzsz under FreeBSD.

First, establish contact to the BIOS using something like ‘cu -l /dev/ttyU0 -s 19200’ adjusted to fit the device node and speed used in your setup. Then follow these steps:

  1. Press Ctrl+P to enter the Soekris BIOS monitor
  2. Type download -
  3. Press ~C
  4. Type lsx /path/to/b4801_131.bin

If the XMODEM transfer was successful, continue with the following steps:

  1. Type flashupdate
  2. Type reboot
  3. Press ~. to exit cu(1)

That’s it! The BIOS should now be updated :)

RS-232 level converter for the Linksys WRT54G

Some time ago I got my hands on a bunch of more or less broken Linksys 802.11 APs and wireless routers. They have been sitting in my closet until recently, when I decided to mock a bit with one of the WRT54G models.

First things first – I had to establish contact with the onboard firmware. Since the board didn’t respond on any of the ethernet interfaces I set out to construct an RS-232 level converter to use with the onboard 3.3V TTL serial interface.

Judging from google, people use all kinds of weird and somewhat complicated (not to mention quite expensive) circuits in order to convert the voltage levels of the WRT54G serial interface to RS-232 levels. I decided to go with my own simple, cheap and effective design based on the Maxim MAX3232 as shown below:

RS-232 Level Converter

The pinout of the IDC connector on the Linksys WRT54G – X3 in the diagram above – is as follows (thanks to Rod Whitby for posting information on the pinouts, saved me a bit of trial-and-error):

Pin # Description Pin # Description
1 3.3V 2 3.3V
3 Tx (ttyS1) 4 Tx (ttyS0)
5 Rx (ttyS1) 6 Rx (ttyS0)
7 NC 8 NC
9 GND 10 GND

The onboard firmware of the WRT54G provides a console on ttyS0 at 115200 1N8. Since the above pinout lacks RTS/CTS lines we have to rely on software flow control.

To connect to the console one might use a command like cu(1):

$ cu -l /dev/ttyU0 -s 115200

Below is a couple of action-shots of the circuit in use:

Action Shot 1

Action Shot 2

The next logical step is to get FreeBSD/mips up and running on this thing ;-)

System monitoring wallpaper

Several people have asked me about the system monitor running on the root window of my ThinkPad X60s’ X11 desktop – not many of them had spotted that is was actually just conky with an advanced configuration and a custom wallpaper:

Conky

My ~/.conkyrc can be downloaded from here. The panel at the bottom center is from FluxBox, my window manager of choice. The panel to the left is fbpager, a desktop pager for use with FluxBox.

Back from EuroBSDCon

This years EuroBSDCon was great fun! It was the second time I attended EuroBSDCon, and it was great meeting up with – what has come to my understanding is – the “usual crowd” again.

The talks this year were very high quality and the social and networking aspect was very enjoyable – ranging from Robert Watson’s talk about the TrustedBSD enhancements to the traditional Unix security model to my ZFS debug session with Pawel Jakub Dawidek.

I took a few, muddy photos at the conference – they can be found at the usual place. See you all next year in Strasbourg!