Inspired by Bodge-its Mendel Repstrap, I am building a repstrap which overlaps as much as possible with Mendels Bill of Materials. The idea being that I can print the needed 3d parts, with the repstrap, then dismantle the repstrap and build Mendel, without having to have bought lots of extra parts and materials.
Author: Giles Bathgate
How to write an operating system (Part 2)
You may have read my previous post about writing a Hello World operating system. Although I did post this on April 1st it wasn’t actually a prank, and it does actually work.
I decided to improve the code. With the following replacement for main.c we can print “Hello World!” on the screen in a more developer friendly way.
char * vidmem = (char*)0xB8000;
int pos = 0;
void putc(char ch){
vidmem[pos++] = ch;
vidmem[pos++] = 0x7;
}
void puts(char* s){
int c;
for(c = 0; s[c] != ''; c++)
putc(s[c]);
}
int main(){
puts("Hello World!");
}
Now this is all very good, but suppose you need to check that some number in your os is some value that you expected, we are going to have to write a function to convert the number into an ascii representation before displaying it on the screen, we can’t use the itoa() function of the standard c library, because we didn’t compile it into our OS. We need to instead roll our own itoa function.
int strsize(char* str){
int i;
for(i = 0;str[i]!='';i++);
return i;
}
char* strrev(char* str){
char* tmp;
int i = strsize(str) - 1;
int j = 0;
while(i>=0){
tmp[j] = str[i];
i--;
j++;
}
tmp[j] = '';
return tmp;
}
char* toDigit(int n){
char digits[10] = "0123456789";
char* str;
int i = 0;
while(n/10){
str[i] = digits[n%10];
i++;
n/=10;
}
str[i] = digits[n%10];
i++;
str[i] = '';
return strrev(str);
}
This initial attempt might have worked, however its riddled with errors, which I have since learned about. For example returning a pointer to a stack variable, is probably not a good idea!
When I originally wrote this I hadn’t seen the Kerrigan an Ritchie implementation thier implementation is much better has more features, and less bugs. After re-writing the code my final version of main.c was as follows
Continue reading How to write an operating system (Part 2)
Portugal
I just got back from a Holiday in Portugal with Joey. We had a wonderful time in the sun being really lazy and enjoying swimming and sun bathing. On the first day it was really foggy which was weird but also quite nice since we didn’t get the fully impact of the sun while we acclimatised. The first real day of our holiday we spent on Priaia de Caveiero (Caveiero Beach), It was a small beach which meant it was quite quiet. The next day we went to the Slide and Splash Water Park.
Boat Trip
Praia de Paradiso (Paradise Beach)
Praia de Cranerios (Cranerios Beach)
SC101T Linux Cluster
I recently aquired a Netgear SC101T Network storage device. After discovering that the device is not a NAS and instead was a SAN device I was at first a little disappointed. Furthermore the device uses a proprietry file system and a proprietry protocol called zSAN to access the device. Well fortunately someone has developed an SC101-NBD linux userspace driver that translates the proprietry zSAN protocol into linux nbd (Network Block Device) protocol. After downloading and compiling the driver at first nothing worked, and I found the reason to be that the driver was developed for the SC101 not the SC101T. After a bit of hunting around I found that someone had posted the following fix in on the driver support group forum.
The fix is pretty simple. In psan.c the functions ‘psan_query_disk’ and ‘psan_query_root’ pass an info’ value of ‘1’ into the ‘psan_get_t’ struct. Doing so seems to cause the ‘select’ to fail in the ‘wait_for_packet’ function. Changing the value passed into ‘info’ to ‘0’ seems to allow the device, disks and partitions to be discovered fine – I’m now currently watching my linux box mkfs.ext3 /dev/nbd0
I followed the instructions and re-compiled the driver, this time it worked. Issuing a
sudo ut listall
Gave the following output
===============================================================================
VERSION : 1.1.3 ROOT IP ADDR : 192.168.2.5
TOTAL(MB): 610480 # PARTITIONS : 1
FREE (MB): 64
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PARTITION LABEL IP ADDR SIZE (MB)
F1A2F2EA-7C87-11DE-ACB7-0013A9D715B7 linux1 192.168.2.6 610407
===============================================================================
VERSION : 1.1.3 ROOT IP ADDR : 192.168.2.3
TOTAL(MB): 610480 # PARTITIONS : 1
FREE (MB): 133594
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PARTITION LABEL IP ADDR SIZE (MB)
2B4F7D24-67FE-11DE-8CC5-0013A9D715B7 linux0 192.168.2.4 476877
===============================================================================
This lists the partitions on the device that had been previously created using the Windows™ software. A partition can be attached by issuing
sudo ut attach F1A2F2EA-7C87-11DE-ACB7-0013A9D715B7 /dev/nbd0
So this provides block device access to the partition, to use the partition obviously one has to put a file system on it. The difference with this SAN based device and say a local hard disk device, is that a local harddisk is only accessed by one machine at a time. Since I wanted to access the device from multiple machines something like ext2fs is not suitable. What is much more suitable is gfs2 which is actually designed for SAN storage devices. To install gfs2 on debian based distributions you can run
sudo apt-get install gfs2-tools
mkfs.gfs2 -j 5 -t storage:linux0 /dev/nbd0
To actually mount the device the lock manager also has to be configured.
<?xml version="1.0"?>
<cluster name="storage" config_version="1">
<clusternodes>
<clusternode name="korma" nodeid="1">
<fence>
<method name="human">
<device name="last_resort" ipaddr="korma"/>
</method>
</fence>
</clusternode>
<clusternode name="tikka" nodeid="2">
<fence>
<method name="human">
<device name="last_resort" ipaddr="tikka"/>
</method>
</fence>
</clusternode>
</clusternodes>
<fencedevices>
<fencedevice name="last_resort" agent="fence_manual"/>
</fencedevices>
</cluster>
Music Player Daemon on the MusicPal
Some time ago I recived a MusicPal as a gift. Out of the box the device is great fun, and made a very good present. The device is designed to work as an internet radio, It can connect to a wireless network and stream radio from various internet radio stations. However the device does have a few limitations when you want to play your own music. The device can connect to Media servers that use the UPnP Media Devices Protocol and the device is operated using two rotary knobs. For me the combination of these two features is the major design flaw in the product. I don’t want to walk over to the device, twiddle some knobs and play a tune that is on my laptop, instead I want to select songs from my laptop and queue them up for playing on the device. There are two remote control applications for the MusicPal, one which is accessible through a web interface, and another which is Windows™ software. However both of the remote control applications are useless, all one can do is pause music, you can’t select a new song to be played, change the position of playback or even fast-forward and rewind!
Well a while ago, I found a blog from someone who goes by the name of Nerdy Toad who was trying to run Music Player Deamon on his MusicPal. At the time he had only managed to make a test sinewave come out of the devices internal speaker, and we worked together to see if we could get output from the line-out of the device. We were somewhat unsuccessful. However, about half a year later, someone called Maz took our research further. He was able not only to get sound fully working on the device, he was also able to patch Music Player Deamon to work on the device aswell.
For anyone else who has a MusicPal and wants to use it in conjunction with Linux you will need to do the following. First you have to enable the telnet interface for the device. You can enable it via a hidden web interface page:
http://musicpal/admin/cgi-bin/debug
You can then telnet to the device, login as root, and issue the following command.
wget http://musicpal.v3v.de/cifs/cifs.ko
This will get you a kernel module will will allow you to access a samba share on the device. This is important because the device has very limited disk space, and so its preferable to put mpd, config files, etc. In a samba share. Of course you will probably have your mp3 files in a samba share aswell. You will need to create an smb.conf on the machine that you will be sharing files from, (not the MusicPal). This is my smb.conf
[global]
server string = masala
security = SHARE
guest account = giles
[mpd]
comment = mpd
path = /home/giles/mpd
guest ok = Yes
read only = No
[music]
comment = Music
path = /home/giles/Music
guest ok = Yes
In my setup I have mpd on the machine sharing music, this is because of the limited space on the MusicPal, so still on this machine download the mpd binary
wget http://musicpal.v3v.de/mpd-testing/mpd.tar.gz
Then expand the gzip into the mpd directory. You will have to modify the mpd.conf file so that the directories are correct. Once you have done all this, you can mount the shares from the MusicPal telnet session
mount -t cifs //192.168.2.4/mpd /tmp/mnt/mpd
mount -t cifs //192.168.2.4/music /tmp/mnt/mpd/music
Finally from the telnet session you can launch mpd. Back on the client you should now be able to connect to mpd via your favorite mpd client program.
Webcam in Linux on Sony VGN-BX61MN
For anyone interested in using linux on this laptop, the following should be of help. The camera is labeled as Motion Eye but lsusb reports the device as:
05ca:1839 Ricoh Co., Ltd Visual Communication Camera VGP-VCC6 [R5U870]
After alot of messing around and installing defunct kernel modules, that seem to work, but actually include the wrong firmware versions. I found that the work being done by Alex Hixon on a generic R5U87x driver to be the most up to date. Previously the project rolled its own kernel module to support the camera, However the current version works by providing userspace tools to upload firmware to the device so that the standard uvcvideo driver in the kernel can communicate with the camera.
Unfortunately there wasn’t much around in the way of a howto to explain how to use the code. So I had to figure out the following for myself.
First of all install git and some other project dependencies
sudo apt-get install git libglib2.0-dev libusb-dev
Now you can download the source
git clone https://github.com/p6/R5U87X.git
Change into the source directory and issue the following three commands.
cd R5U87X
make clean
make
make rules
sudo make install
If your user isn’t part of the video group you will probably have to modify /etc/group and make yourself a member of that group otherwise you might experience Permission Denied errors.
After you have rebooted you can test using mplayer
mplayer tv:// -tv driver=v4l2
Also make sure you can record because uploading the wrong firmware will in some cases allow you to see output but not record it.
mencoder tv:// -tv driver=v4l2:device=/dev/video0 -nosound -ovc lavc -o test.avi
If you want to clean things up afterwards you can run the following commands
sudo apt-get --purge remove git libglib2.0-dev libusb-dev
sudo apt-get --purge autoremove
rm -r R5U87X
You may find the above steps also work for the following devices:
05ca:1830 Ricoh Co., Ltd Visual Communication Camera VGP-VCC2 [R5U870]
05ca:1832 Ricoh Co., Ltd Visual Communication Camera VGP-VCC3 [R5U870]
05ca:1833 Ricoh Co., Ltd Visual Communication Camera VGP-VCC2 [R5U870]
05ca:1834 Ricoh Co., Ltd Visual Communication Camera VGP-VCC2 [R5U870]
05ca:1835 Ricoh Co., Ltd Visual Communication Camera VGP-VCC5 [R5U870]
05ca:1836 Ricoh Co., Ltd Visual Communication Camera VGP-VCC4 [R5U870]
05ca:1837 Ricoh Co., Ltd Visual Communication Camera VGP-VCC4 [R5U870]
05ca:1839 Ricoh Co., Ltd Visual Communication Camera VGP-VCC6 [R5U870]
05ca:183a Ricoh Co., Ltd Visual Communication Camera VGP-VCC7 [R5U870]
05ca:183b Ricoh Co., Ltd Visual Communication Camera VGP-VCC8 [R5U870]
05ca:183e Ricoh Co., Ltd Visual Communication Camera VGP-VCC9 [R5U870]
Propellerhead Record
Head over to recordyou.com and you will be able to download and authorize Record RC4 until September 9 when they hit the official release day.
Creating Tiny Windows executables with TCC
I recently compiled a small executable program writtern in C with the Visual Studio C++ Express. The output was a 56K executable, which ok is pretty small, but actually in terms of programs its really large.
So I looked into compiling my program with the TinyCC compiler.
First I downloaded the compiler, however it quickly came apparent that the libraries and includes that come with the compiler were just a minimal set. What I needed was the includes from MinGW. Its only necceccery to download the Windows 32 API package.
My program needed to be linked with winsock2 so first i needed to run
tiny_impdef c:windowssystem32ws2_32.dll
This will generate a ws2_32.def file. I was then able to simply compile the program with.
tcc program.c ws2_32.def
The output of which is an executable of 1K. I asume because the compiler itself is small, and the compiler compiles itself that it would produce rather small executables. I have yet to test compiling the same program using mingw and GCC -Os.
Amestedam
I went to Amsterdam last weekend with Joey, Trish and Chris. The flight over from Bradford-Leeds Airport was fairly quick and painless, however we did have trouble finding our Hotel which apparently had moved (it was a Boat Hotel)
The first night we were there we met these two English girls from Weston-Super Mare, they were quite drunk and really funny. We were supposed to all meet up in the Facebook Friends of the Amstel Botel Group, but haven’t heard from them since. The next morning we were all feeling a little hung over, Trish was feeling a bit “sea sick”, so Chris, Joey and I all went into Amsterdam city centre, to have a few early morning beers. When Trish met up with us later we all had a snack of Manneken Pis before going to a famous museum close by. We spend the rest of the day shopping, drinking and treating ourself to a really nice meal.
The second day we went to the Amestedam Taussauds waxworks museum, it was really busy but really fun to see such lifelike models. We spent the rest of the day shopping exploring and drinking.
Another Cat
We got another cat! We decided to call this one Mikey.