Archive for the Computing Category

Patching squashfs-tools4.0 for Cygwin

I needed a copy of unsquashfs.exe to run under Cygwin, which took a couple patches. These patches are against the squashfs-tools4.0 source from sourceforge. The patches are directly derived from the changes for 3.4 by CHNRXN, and don’t really represent any original work of my own. A copy is also available on pastebin.com/R9EQcbQY.

diff -rupN squashfs4.0_org/squashfs-tools/global.h squashfs4.0/squashfs-tools/global.h
--- squashfs4.0_org/squashfs-tools/global.h 2009-03-16 00:03:54.000000000 -0400
+++ squashfs4.0/squashfs-tools/global.h 2010-09-02 14:46:26.732375000 -0400
@@ -44,4 +44,9 @@ typedef long long squashfs_fragment_inde
typedef squashfs_inode_t squashfs_inode;
typedef squashfs_block_t squashfs_block;

+#ifdef __CYGWIN__
+#include
+#define FNM_EXTMATCH (1 << 5)
+#endif
+
#endif
diff -rupN squashfs4.0_org/squashfs-tools/mksquashfs.c squashfs4.0/squashfs-tools/mksquashfs.c
--- squashfs4.0_org/squashfs-tools/mksquashfs.c 2009-04-05 17:22:48.000000000 -0400
+++ squashfs4.0/squashfs-tools/mksquashfs.c 2010-09-02 14:57:08.435500000 -0400
@@ -49,10 +49,14 @@
#include

#ifndef linux
+#ifndef __CYGWIN__
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#endif
+#ifndef __CYGWIN__
#include
+#endif
#else
#include
#include
@@ -3687,6 +3691,9 @@ void initialise_threads()

signal(SIGUSR1, sigusr1_handler);

+#ifdef __CYGWIN__
+ processors = atoi(getenv("NUMBER_OF_PROCESSORS"));
+#else
if(processors == -1) {
#ifndef linux
int mib[2];
@@ -3708,6 +3715,7 @@ void initialise_threads()
processors = get_nprocs();
#endif
}
+#endif

if((thread = malloc((2 + processors * 2) * sizeof(pthread_t))) == NULL)
BAD_ERROR("Out of memory allocating thread descriptors\n");
@@ -3962,7 +3970,6 @@ int excluded(struct pathnames *paths, ch
return FALSE;
}

-
*new = init_subdir();
if(stickypath)
*new = add_subdir(*new, stickypath);
diff -rupN squashfs4.0_org/squashfs-tools/read_fs.c squashfs4.0/squashfs-tools/read_fs.c
--- squashfs4.0_org/squashfs-tools/read_fs.c 2009-03-31 00:23:14.000000000 -0400
+++ squashfs4.0/squashfs-tools/read_fs.c 2010-09-02 14:45:20.998000000 -0400
@@ -40,9 +40,11 @@ extern unsigned int get_guid(unsigned in
#include

#ifndef linux
+#ifndef __CYGWIN__
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#endif
#else
#include
#endif
diff -rupN squashfs4.0_org/squashfs-tools/unsquashfs.c squashfs4.0/squashfs-tools/unsquashfs.c
--- squashfs4.0_org/squashfs-tools/unsquashfs.c 2009-04-05 17:23:06.000000000 -0400
+++ squashfs4.0/squashfs-tools/unsquashfs.c 2010-09-02 14:44:58.013625000 -0400
@@ -110,6 +110,7 @@ void update_progress_bar();

void sigwinch_handler()
{
+#ifndef __CYGWIN__
struct winsize winsize;

if(ioctl(1, TIOCGWINSZ, &winsize) == -1) {
@@ -119,6 +120,9 @@ void sigwinch_handler()
columns = 80;
} else
columns = winsize.ws_col;
+#else
+ columns = 80;
+#endif
}

@@ -1793,6 +1797,9 @@ void initialise_threads(int fragment_buf
EXIT_UNSQUASH("Failed to set signal mask in intialise_threads"
"\n");

+#ifdef __CYGWIN__
+ processors = atoi(getenv("NUMBER_OF_PROCESSORS"));
+#else
if(processors == -1) {
#ifndef linux
int mib[2];
@@ -1814,6 +1821,7 @@ void initialise_threads(int fragment_buf
processors = get_nprocs();
#endif
}
+#endif

if((thread = malloc((3 + processors) * sizeof(pthread_t))) == NULL)
EXIT_UNSQUASH("Out of memory allocating thread descriptors\n");
diff -rupN squashfs4.0_org/squashfs-tools/unsquashfs.h squashfs4.0/squashfs-tools/unsquashfs.h
--- squashfs4.0_org/squashfs-tools/unsquashfs.h 2009-03-28 22:29:02.000000000 -0400
+++ squashfs4.0/squashfs-tools/unsquashfs.h 2010-09-02 14:42:21.154250000 -0400
@@ -46,9 +46,11 @@
#include

#ifndef linux
+#ifndef __CYGWIN__
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#endif
#else
#include
#endif

Perhaps you’ve gotten the above error when starting iTunes. This vexed me for a while, as it was happening after a fresh install of Windows XP w/ SP3 from a legal CD (apparently from an illegal CD it’s quite common?). After some Googling, registry poking and downloading, I finally nailed the problem. I’ve written in up on a wiki page at http://www.tinymicros.com/wiki/iTunes_Gives_Warning_On_Startup.

This fix also fixed a problem I was having trying to install the HP software for my LaserJet CP2025dn.

If this works for you, please post a follow-up. [If you're a spammer, just continue on, because your post will never make it up here]

After having a fair amount of frustration trying to install Lucene from the installation guide provided on the MediaWiki pages, I documented what I had to go through to get it running. I believe this represents a better installation process than the documentation currently available.

It’s available here.

Make GMail your default Windows mail handler

I’ve been using Google’s GMail for a long time, and it’s become my primary mail client for both work and home. One of the things I got tired of was clicking a ‘mailto:’ link somewhere on a web page and having Outlook open up. I finally got annoyed enough to do some searching, and found this nifty little program called gAttach!.

It’s a small application that installs itself as the system mail handler. When a ‘mailto:’ link is clicked, it launches, logs into GMail (or optionally assumes that you already are), and creates an entry in your Drafts folder with the email address, and, if present in the ‘mailto:’ link, the subject.

It’s not quite *exactly* what I want, as I would prefer that focus then be switched to the browser and GMail tab, with the cursor positioned so I can start typing in the body. This may not be possible, I don’t know.

But in any case, it’s far better than launching an un-configured version of Microsoft Abortion. Er, I mean, Outlook.

[gAttach!]

XMOS introduces the 4 core XS1-G4 processor

XMOS has introduced it’s XS1-G4 multicore processor.

The XMOS architecture combines a number of processing cores, each with its own memory and I/O system, on a single chip. The processing cores are general-purpose in the sense that they can execute languages such as C; they also have direct support for concurrent processing (multi-threading), communication and I/O.

A high-performance switch supports communication between the processors, and inter-chip XLinks are provided so that systems can easily be constructed from multiple chips. Any thread can communicate with any other thread in the system using single-cycle communication instructions. The system switches can efficiently route short packets or streamed data.

The XMOS architecture makes it practical to use software to perform many functions that traditionally have been implemented in hardware, for example interfaces and I/O controllers. Both input and output operations can be timed to a local clock or an externally provided clock. The architecture is both multithreaded and event-driven. Threads can be used to define independent tasks; the event mechanism enables fast and controlled responses to a multitude of signals.

The architecture is designed to support any programming language, such as C. The full benefits of the instruction set may require extensions to standard languages, libraries, or the use of assembly language. We have designed XC, a version of C that supports I/O, multi-core and precision timing.

Each XS1-G XCore executes up to eight threads concurrently, at a speed of up to 400 MIPS. A thread has a dedicated register set enabling it to operate as a logical core. The 8 threads share a single 64 KByte unified memory with no access collisions. Integer and fixed point operations are provided for efficient DSP and cryptographic operations.

Each XS1-G XCore has 64 I/O pins that are programmed from software. Thread execution is deterministic and hence each thread can implement a hard real-time I/O task, regardless of the behaviour of other threads. I/O pins are grouped into logical ports of width 1, 4, 8, 16 and 32 bits. Each port incorporates serialisation/deserialisation, synchronisation with the external interface, and precision timing. Each XCore incorporates eight timers that measure time relative to a 100 MHz reference clock.

Each XS1-G XCore is connected to a switch via four internal links. Each link is capable of transferring data at 800 Mbits/second. The switch provides full connectivity between the cores on the chip, and also provides up to sixteen external XLinks. Each XLink is capable of transferring data at up to 400 Mbits/second.

Sounds fast! And XC is a C-like language that provides full support for the parallel architecture, so the time to get up to speed using these parts should be reduced.

There are currently two evaluation boards available, the $99 XC-1 card, and the $999 XS1-G development kit (ouch!).

To me, it looks like they are like a Parallax Propeller Chip on serious steroids. If they’re cost effective, it might just make the Propeller stop turning.

[XMOS]

IntellaSys has introduced an interesting looking part called the 40C18. The 40C18 has 40 cores on a single chip, with the cores arranged in a 4 x 10 pattern. Some cores have I/O, such as digital I/O pins, analog inputs and outputs, or interface to external memory, while other cores are purely computational. IntellaSys claims that the combined cores can deliver up to 26 billion operations per second.

Each core has 32 instructions, where each instruction is 5 bits. There are 64 words of RAM and 64 words of ROM per core, with each word being 18 bits. Words are divided into slots, for a total of 4 slots per word, with slot 3 being a ‘short slot’. It appears that this would allow at least 192 instructions, plus however the short slots are used.

The next is straight from the data sheet and says it better than I could:

Each core runs asynchronously, at the full native speed of the silicon. During interprocessor communication, synchronization happens automatically; the programmer does not have to create synchronization methods. Adjacent cores communicate through dedicated ports. A core waiting for data from a neighbor goes to sleep, dissipating less than one microwatt. Likewise, a core sending data to a neighbor not ready to receive it goes to sleep until that neighbor accepts it.

A wake up occurs almost instantly, upon the rising edge of the synchronizing signal. With the wake up logic controlling power use, there is no need for complex power control strategies. Power is conserved as a natural consequence of good program design. External I/O signals may also be used to wake up sleeping processors. The small size and low power make the SEAforth 40C18 a good value both in terms of MIPS per dollar and MIPS per milliwatt.

I/O ports on the SEAforth 40C18 are highly configurable because they are controlled by firmware. The 4-wire SPI port, the 2-wire serial ports, and the single-bit GPIO ports can be programmed to perform a large variety of functions. With the available processing power, wireless solutions become possible without the need for separate wireless chips. Ports can be programmed to support I2C, I2S, asynchronous serial, or synchronous serial ports. Serial ports can also be used to connect multiple SEAforth 40C18s.

In addition to serial I/O, two nodes have two dedicated parallel I/O ports. These can be used for parallel I/O, or when combined, can drive an external memory device.

It’s an interesting looking part, provided your application can benefit from small processes with a high degree of parallelism. DSP applications naturally come to mind, along with other small specialized control functions.

While most of my uses couldn’t take advantage of such an device, it runs Forth, so that makes it intrinsically cool. Check out the web page for development tools, the data sheets, and also the forthDrive processor, which is a 24 core version of the 40C18.

[IntellaSys]

Linux integer overflow signal handler example

I was chatting in #c on freenode.net the other night and someone was asking about detecting numeric overflows. Apparently they were interested in writing their own language as a learning exercise, and wanted some of the niceties that other languages offer, such as overflow detection.

After a quick bit of poking around, I found that GCC has the -ftrapv option, which will generate a trap on signed integer addition, subtraction, multiplication and division. Now that I knew a trap (or signal) could be generated, some code was needed to demonstrate it.

About 5 years ago I worked on a project that handled a bunch of signals. If a segment fault (SIGSEGV) was received, it would print a backtrace of the stack and display the processor registers. A bit of cutting and pasting and some minor updates, and it worked.

At that point, I figured I ought to make an example out of it, since there seems to be little in the way of readily available documentation for this sort of things. You can find tutorials on basic signal writing, but if you want to dump the stack or processor registers, you have to start digging through the source code of libc, glibc and gdb (which is pretty much how I figured out how to do this in the first place).

This example is available on my wiki, at http://www.tinymicros.com/wiki/Linux_Overflow_Signal_Handler_Example.

Comments and criticism are welcome.

Very interesting article on New Scientist on software that analyzes speech and facial expressions, and applying it to politicians.

Inspirational electioneering, straight talk and devious spin — new technology means it’s all getting easier to detect and dissect

http://technology.newscientist.com/channel/tech/mg19926746.200-software-spots-the-spin-in-political-speeches.html

Installing Cygwin/X and WindowMaker

I’ve been using the Cygwin shell for a 8 or 10 years. On a couple of occasions I have attempted to install the Cygwin X server packages, and it always seem to be more difficult than it should be. After a while I’d get tired of messing with it, and go back to using the standard non-graphical Cygwin shell.

Unfortunately, cutting and pasting between the non-graphical shell and Windows applications is a major pain in the rear. Having to click the upper left corner, select ‘Mark’, highlight the text, hit Enter, then paste it somewhere was just too many awkward mouse clicks. I longed for the nice X or KDE windows environment, where left-clicking and highlighting the text copied it, and center-clicking the mouse pasted it. Simple, fast, reliable.

Another thing I missed having was all my SSH sessions in one place. I use SSH a lot, into 3 or 4 different systems each day, sometimes with multiple windows open to each. Generally I used Tectia’s free SSH client, which is getting a little long in the tooth. Terminal emulation seems a little iffy, particularly when it comes to using the ‘Home’ and ‘End’ keys on the command line to jump to one end or the other. Being able to use a modern ssh client under an xterm session would solve that issue. And I got tired of having all those Tectia icons on the task bar.

I don’t remember the exact circumstance, but something prompted me to look into installing X again. I fired up the ‘setup.exe’ from the Cygwin.com site, selected X11 and the WindowMaker window manager and let it install.

After it finished, I attempted to start X the way I’m familiar with on my Linux boxes: open a shell and type ‘startx’. Nothing good happened, so a little poking around was required. I found that ‘startxwin.sh’ in the ‘/usr/X11R6/bin’ directory would bring it up, but not running WindowMaker. Instead, I was getting the default, twm. twm is a little too basic for my tastes, and the visual appeal is non-existent. I imagine there are some that like it, but not me.

A little more poking around revealed that I need to replace the ‘exec twm &’ with ‘exec wmaker &’ in ‘startxwin.sh’, and comment out the ‘xterm’ line. This is definitely an improvement, but I found two things I don’t like.

The first is that Alt-Tab was still moving between Windows windows, and not WindowMaker windows. A lot of searching found that -keyhook needs to be added to the XWin.exe line in ‘startxwin.sh’. Now Alt-Tab switches between Windows windows until the Cygwin window is active, then Alt-Tab moves between WindowMaker windows. To switch to a different Windows application requires clicking on the task bar icon. I find this acceptable.

The second is that I had a Cygwin shell still open and present on the task bar, along with the Cygwin/X icon. Closing the Cygwin shell resulted in shutting down Cygwin/X, even through the process was detached. I expected this is because it follows a typical Unix-like programming model, where the Cygwin shell is the parent process, Cygwin/X is the child process, and killing the parent kills the child.

I happened to notice that in addition to ‘startxwin.sh’ there is also a ‘startxwin.bat’. I made the same changes to it as the ‘startxwin.sh’ file, then created a shortcut to the batch file on the desktop. I also changed the default batch file icon by right clicking the batch file, selecting ‘Change Icon’, and pointing it to ‘%SystemDrive%\Cygwin\usr\X11R6\bin\XWin.exe’. This results in the batch file having the XWin.exe icon, which is a nice black ‘X’ on a transparent background.

So now we’re all good to go: We can start X without having an extra icon on the task bar, WindowMaker is started, Alt-Tab moves between WindowMaker Windows, and I have what I consider to be much more proper copy’n'paste behavior.

Below is a screen shot of the X11 packages I have installed. You’ll want to make sure these packages are selected in the ‘setup.exe’ program. They’re all under the ‘X11′ menu, at the bottom of the list.

Selected X11 Packages

Selected X11 Packages

Below is the ‘/usr/X11R6/bin/startxwin.sh’ with all the comments removed (for brevity).


#!/bin/sh
export DISPLAY=127.0.0.1:0.0
export PATH=/usr/X11R6/bin:"$PATH"
export XAPPLRESDIR=/usr/X11R6/lib/X11/app-defaults
export XCMSDB=/usr/X11R6/lib/X11/Xcms.txt
export XKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB
export XNLSPATH=/usr/X11R6/lib/X11/locale

rm -rf /tmp/.X11-unix
XWin -keyhook -clipboard -silent-dup-error &
exec wmaker &
exit

And also the '/usr/X11R6/bin/startxwin.bat' file:


@echo off
SET DISPLAY=127.0.0.1:0.0
SET CYGWIN_ROOT=\cygwin
SET RUN=%CYGWIN_ROOT%\bin\run -p /usr/X11R6/bin
SET PATH=.;%CYGWIN_ROOT%\bin;%CYGWIN_ROOT%\usr\X11R6\bin;%PATH%
SET XAPPLRESDIR=/usr/X11R6/lib/X11/app-defaults
SET XCMSDB=/usr/X11R6/lib/X11/Xcms.txt
SET XKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB
SET XNLSPATH=/usr/X11R6/lib/X11/locale

if not exist %CYGWIN_ROOT%\tmp\.X11-unix\X0 goto CLEANUP-FINISH
attrib -s %CYGWIN_ROOT%\tmp\.X11-unix\X0
del %CYGWIN_ROOT%\tmp\.X11-unix\X0

:CLEANUP-FINISH
if exist %CYGWIN_ROOT%\tmp\.X11-unix rmdir %CYGWIN_ROOT%\tmp\.X11-unix

if "%OS%" == "Windows_NT" goto OS_NT
echo startxwin.bat - Starting on Windows 95/98/Me
goto STARTUP

:OS_NT
echo startxwin.bat - Starting on Windows NT/2000/XP/2003
:STARTUP

%RUN% XWin -keyhook -clipboard -silent-dup-error
%RUN% wmaker

Hopefully the time I wasted trying to get Cygwin/X tuned the way I wanted will save someone else a few minutes. Or if you stumble across this post, encourage you to try Cygwin/X.

Google Chrome — Initial impressions

Today, on a whim, I installed Google’s new Chrome browser.  And I have to say I’m very impressed.  It is indeed very fast.  It has a nice clean user interface.  It’s very intuitive, without lots of hidden settings here and hidden things there to change.

There’s an interesting article on TechCrunch, Live From The Google Chrome Press Event.

So far, my only real complaint is that I miss the Firefox Adblock plug-in. Whether it’ll ever be supported or not, I don’t know. But I’ve sure gotten used to pages with no obnoxious ads and videos on them. Particularly CNN.com’s Money page, which has an auto-start video.

The other minor detail that’s simply a bit of retraining on my part is that I’ve also gotten used to typing ‘/’ to search a page in Firefox. Chrome, like IE and Opera, use control-F (Firefox does also, but ‘/’ is an alias for control-F).

In the process of authoring this article, I’ve run across another minor annoyance. If the currently active tab opens a new tab, the new tab is located immediately to the right of the currently active tab. I’m used to it opening at the far right, and there’s where I expect to look for the new tab. :(

One of Chrome’s really nice features is that each tab is a process unto itself. If a process crashes, it doesn’t take down the whole browser (something that rarely happens to me in Windows Firefox, but frequently in the Linux version). And with the Chrome Task Manager, should a tab run away or not respond, it can be killed without shutting down the other tabs. It also displays the amount of memory each tab is using.

Chrome can be downloaded from http://www.google.com/chrome.