Sunday, March 16, 2014

Bird in the Hand

So... previously I managed to get the versatile finch instant messenger program running on IZ2S, but failed to connect to anything with it.  Recompiling and running it with --debug led me to an old uclibc 0.9.29 bug where it defines but does not support some getaddrinfo() hint flags like AI_NUMERICSERV and AI_ADDRCONFIG.  Using them locks up the program (or the thread in the case of finch) on the dns lookup.  I patched the uclibc netdb.h header file to not define the unsupported flags, then hacked the glib resolver function to skip over those flags and instead use IPV4 only on the zipit.  This fixed my glib resolver test program, and got me a working nslookup applet, but failed to fix the finch.  I gave up -- again -- and did some work on the Links browser instead.

Eventually I got the idea to search for the "DNS query queued" debug message inside the finch libpurple code.  Sure enough, despite the fact that finch requires the enormous glib to build, it goes straight to the libc getaddrinfo() function instead of wading through the extra bloat of the glib resolver wrapper.  If only the finch devs would see the light and bypass all of glib then maybe I could build a cut down finch with a subset of plugins that actually fits on the internal zipit flash.  Anyhow, I patched libpurple just like glib, rebuilt everything and the new finch was able to connect to IRC from my IZ2S zipit.  You can see my test session running on the half hidden right side window in this screenshot.
When I configured finch it gave me a warning that some IM protocols would have reduced functionality without gnutls, so I decided to build that while I was still working on the finch executable.  Sadly, I don't remember which IM protocols wanted it so the libgnutls remains untested, but included for completeness.

While building, I also found pkgconfig, which is a nifty slim replacement for the bloated pkg-config program, and will surely make compiling certain large packages with the native IZ2S and openwrt compilers much easier.  It's a clear win over my previous cheesy pkg-config shell script.

Here's the new finch with the patched glib and libpurple shared libraries along with a few other libs that should be enough to get it going on a basic IZ2S zipit.  I included a wrapper script that should also work if you want to boot iz2jffs and run finch from the SD card.

finch-iz2s-resolve.zip

Here's the gnutls libs.

gnutls-iz2s.zip

And the nslookup applet.


nslookup-iz2s.zip

And finally, I've included the unstripped glib along with the pkgconfig utility as an add on for the native IZ2S compiler.  This stuff should go in the usr/local directory on your SD card if you want to compile with it.

glib-iz2s.zip

I still need to build an openwrt pkgconfig executable...


Sunday, March 2, 2014

The Latin Crush

I discovered my iz2s build of finch runs just fine -- no segfaults -- but it never seems to make a connection to the IRC server.  Running it with --debug pointed me towards the threaded DNS resolver function, which never seemed to finish.  So, suspecting glib, I built a small test function and it didn't work either.  Then I noticed the nslookup busybox applet wasn't working either, which put the problem in uclibc.  The internet said there were some unsupported (but reported) flags in the getaddrinfo function in the ancient uclibc used by iz2s.  I patched around it and managed to fix my test program, which could substitute for the broken nslookup applet, but the threaded versions of the function used in finch and glib still don't weem to work.  Oh well.  I'll figure it out someday.

Meanwhile over on the zipit IRC channel, slug_ was busy reworking the ssl functionality in the openwrt build of the links browser, attempting to reduce the jffs disk space required for links by backing the ssl code out to a shared lib and then pointing links at some other random shared lib already on the jffs.  I like the idea, but not so much the implementation because it's totally broken on iz2s.  I'd rather try and fix the openssl compatibility layer in polarssl and/or patch the links https.c file to use it.  Unfortunately that idea is still on the back burner.  But meanwhile, all this somehow got me thinking about shrinking the png files used by the links font system.  I got motivated and ran my cut down latin15 links font set through pngcrush --brute, then rebuilt links to see what would happen.  Turns out, it saved me 40K bytes on the jffs, so I'll take it.

But I didn't stop there.  I got to thinking again about using TTF fonts for links, so I bit the bullet and compiled the links code on the zipit itself in preparation for a heavy gdb session to track down the source of the segfault that stopped me cold the last time I tried this.  Turns out I never got into the gdb session.  I ran links via ssh and noticed the error message, looked it up in the code, and found a self induced segfault due to my shoddy character width calculations on the TTF mono-spaced font.  Oops.

So I fixed that and now it runs.  The good news is the executable comes out to a very reasonable 534K with ssl included via static linking.  Nice.  And as expected, the tiny fonts required by the zipit are much cleaner and far more readable than the original scaled down png fonts. 
I think I can approximate the coverage of the original built-in png fonts on the jffs with just two dejavu fonts (mono and proportional spaced) for only 80K bytes over the current TTF font included on the jffs, possibly more if I need bold and italics.  That gives a savings of maybe 200-250K over the pngcrushed links build, and it might just save my eyes.  Plus I'll have a decent set of fonts on the jffs to work with for other apps like the flipclock.  Even pspmaps might work on the jffs if I keep the map images in /tmp when the SD card is absent.

As you can see in the picture, I still need to do plenty of adjustments to make the TTF glyph metrics match what links was doing with the png files.  That'll take some time because I probably also need to measure the RAM footprint of multiple preloaded TTF font sizes vs the runtime resizing of the png fonts to get something optimal for the 32MB RAM in the zipit.

Update:  Getting closer..  I got multiple fonts and sizes going and I fixed some problems with the spacing and non-printable control characters.  Judging by the link highlight rectangle in the picture below, spacing could possibly use a bit more work.  And if I can figure out why some text isn't printing in the title bar, status bar, and dialog boxes I can probably release an executable package.

Update 2: I fixed the bug with the text in the title bar status bar and dialogs.


I also restored the bold font support and did some comparisons to the original links.  The ttf and png versions used a similar amount of memory with the same mix of bold, normal, and monospace fonts when rendering this test page.

I find the original png fonts (below) a bit fuzzy, especially at the smaller sizes best suited for the zipit screen.

Anyhow, here's the pngcrushed Links executable.  I might try to make it smaller with some more advanced pngcrush settings mentioned on the zipit IRC channel.

links-iz2s-latincrush.zip

I'm hoping to add the font-include-latin-crushed.h file to the openwrt-zipit links package on github, real soon now.

Here's a links-ttf executable.  Probably riddled with bugs, but at least it proves the concept is viable.

links-ttf-iz2s-beta1.zip

And here's a tiny Latin1 ttf font viewer program with source code that might be handy someday if I ever decide to scour the internet for smaller font files.

ttfview-iz2s.zip

Update 3:  I fixed the segfault in Links when selecting languages.  Here you can see it not crashing in that section of the menu.  You can also see the Bepa Roman ttf fonts support more glyphs than I did with my Latin1 built-in-font executables.  If I could figure out what all those characters were, maybe I could restore some more of the original 33 languages on the menu...  Actually, it really demonstrates that I need to move the menu language support into runtime loaded optional shared libs so you can install your own language(s) to go with your own ttf fonts.  If only the standard solution for that wasn't such bloatware.

This screenshot also showcases some new mini scrollbars and a new menu color scheme that I've been testing in the ttf package with more contrast for better readability with the tiny font.  You can't see it here but I also added a blue block cursor in the ttf package for the menu text entry fields.  The original underline cursor was always difficult for me to locate with my bad eyes.

Anyhow, I repackaged some new executables with the segfault fix.

links-iz2s-latincrush2.zip
links-ttf-iz2s-beta2.zip

Update 4:

I added slug's title and statusbar hiding code from the openwrt build for a little extra screen space in the links ttf executable.  Every little bit helps.  So here's the new executable and the modified links source code.

links-ttf-iz2s-beta3.zip
links-ttf-src3.tgz