ADAM'S WEB PRESENCE

27 February 2008

Cross compile for 68000 in C under Windows

Filed under: Nerd Notes — adam @ 9:03 pm

This article contains my notes for setting up a m68k cross-compiler using Cygwin. It’s all free software and gives me a way to create binary images for a 68000 CPU from C code on Windows. Here’s the step-by-step to set it up:

Step 1. Install Cygwin

Go to http://www.cygwin.com/ and download setup.exe. Run it.

During the setup, you will have the opportunity to select what packages to install. Choose the following:

  • binutils
  • gcc-core
  • bzip2
  • flex
  • make

Step 2. Download the compiler source code

You want binutils and gcc-core from GNU. Go to the GNU download page, choose a mirror and download the following files. Place them in your Cygwin home directory.

  • binutils-2.15.tar.bz2
  • gcc-core-3.4.2.tar.bz2

Yes there are more up-to-date versions but at the time of writing, the latest gcc versions do not support the 68000 platform. Feel free to try different versions but I know the versions just mentioned will work.

Step 3. Compile and install binutils

Launch Cygwin and type the following commands. Typing this kind of stuff is automatic for me these days. Its a pretty standard GNU setup procedure.

mkdir /usr/local/m68k

tar jxvf binutils-2.15.tar.bz2

cd binutils-2.15/

./configure --prefix=/usr/local/m68k --target=m68k-coff

make install

Step 4. Compile and install gcc

Same again for the C compiler.

cd ~

export PATH=$PATH:/usr/local/m68k/bin

tar jxvf gcc-core-3.4.2.tar.bz2

cd gcc-core-3.4.2/

./configure --prefix=/usr/local/m68k --target=m68k-coff --enable-languages=c

make install

Step 5. Set up your path

The 68000 compiler will be located in /usr/local/m68k/bin. To make life easier, you might like to add the following to your ~/.bashrc file:

export PATH=$PATH:/usr/local/m68k/bin

Step 6. Enjoy

Here’s the command to compile some C code:

m68k-coff-gcc -o test.out test.c

And the command to create a binary image from the compiled code:

m68k-coff-objcopy -O binary test.out test.bin

5 February 2008

Setup of RAID5 without losing data

Filed under: Nerd Notes — adam @ 8:46 am

I have here a server (Debian Linux of course) which is storing its data on a 1TB hard drive. I want to upgrade the storage to a RAID5 using 4x 1TB drives. I’d like the existing drive to be a part of the RAID array so I only need to buy 3 new drives, but I don’t want to lose the 600G or so of data on it.

The solution ? Set up a degraded array, copy the data and then add the original disk to the array.

Put simply, a degraded array is a RAID array with one or more drives missing. RAID5 can operate with any one drive down. This is very useful if a drive fails, you can replace the faulty drive without losing any data. So we are going to pretend the drive with the data on it is ‘faulty’ so it won’t be part of the RAID until later when we miraculously ‘fix’ it.

On my machine, the new drives are /dev/sde, /dev/sdf and /dev/sdg. The drive with the data is /dev/sdh1. First we partition the new drives. You’ll need to type these two commands for each new drive:

echo ",,L" | sfdisk /dev/sde

sfdisk --change-id /dev/sd1 1 fd

You don’t have to use sfdisk, as long as you set up the partitions somehow and set them to type 0xFD (Linux RAID).

Now to create the degraded array. This is the magic bit.

mdadm --create /dev/md3 --level=5 --raid-devices=4 --spare-devices=0 /dev/sde1 /dev/sdf1 /dev/sdg1 missing

The magic word missing stands in for the drive with the data on it.

Next format the RAID array, mount the data drive and copy the data

mkfs.xfs /dev/md3

mount /dev/md3 /home/adam

mount /dev/sdh1 /mnt

cp -prv /mnt/* /home/adam/

This will take a while so you might want to do it in a screen session.

Finally, after the data is copied, we can add the data drive to the array. This is the bit where we can lose everything if it goes wrong so check your data is all on the RAID before proceeding.

umount /dev/sdh1

sfdisk --change-id /dev/sdh 1 fd

mdadm --manage /dev/md3 --add /dev/sdh1

I’m really pleased at this neat trick. I’ve now got a shiny RAID array with a total storage of 3TB. It all worked so well, I just had to blog about it!


2 February 2008

UUIDs in the fstab

Filed under: Nerd Notes — adam @ 8:54 am

I have a machine with about 8 SATA hard drives in it some of which are connected to a PCI controller card and some are on the motherboard. I have an issue with Debian that it keeps swapping the device nodes around on reboot. Sometimes the first drive will be /dev/sda, other times it will be /dev/sde. Somehow the system manages to boot up OK but when it comes time to mount the drives, all hell breaks loose!

My solution is to mount the drives by their UUID rather than by their device node. It took me quite a bit of Googling to find an example of how to do this so I thought I’d write it here so I will know for next time.

Normally, I’d put an entry in /etc/fstab like this to mount a drive:

/dev/sdb1  /var/www  ext3  defaults  0  2

But now I change it like so:

UUID=bd412298-d540-4e4e-8f31-33ff45644bc4  /var/www  ext3  defaults  0  2

You’ll notice it is exactly the same except I have used the UUID instead of /dev/sdb1.

But wait! I hear you ask, how do you find out what your drive’s UUID is ?

Well, I have the answer for that too:

ls -l /dev/disk/by-uuid/

1 February 2008

IVTV Device Node Problems – Solved

Filed under: Nerd Notes — adam @ 1:06 pm

I’ve got a Debian machine here which is set up for TV recording. It is fully stacked with 2 x cx88 DTV cards and 3 x PVR150 cards using the IVTV driver. I’m running Debian Etch which comes with version 0.8.2 of the ivtv driver at the time of writing.

The problem is that the PVR150 cards sometimes register themselves as /dev/video0, 1 and 2 but other times, after a reboot they register themselves as /dev/video2, 3 and 4. I needed some way to make them stay on the same device nodes.

Enter this little UDEV rules file I wrote. It creates new device nodes called /dev/ivtvenc0, /dev/ivtvenc1 etc. up to however many cards you have. These will symlink to the correct device nodes every time. Here’s the script. Call it 010_ivtv.rules and put it in /etc/udev/rules.d/

# Rule to sort out those pesky IVTV cards which never
# seem to load in the correct order when DTV cards are
# also installed.
# by Adam Pierce 01-Feb-2008

ATTR{name}=="ivtv0 encoder MPEG",SYMLINK+="ivtvenc0"
ATTR{name}=="ivtv1 encoder MPEG",SYMLINK+="ivtvenc1"
ATTR{name}=="ivtv2 encoder MPEG",SYMLINK+="ivtvenc2"
ATTR{name}=="ivtv3 encoder MPEG",SYMLINK+="ivtvenc3"
ATTR{name}=="ivtv4 encoder MPEG",SYMLINK+="ivtvenc4"
ATTR{name}=="ivtv5 encoder MPEG",SYMLINK+="ivtvenc5"
ATTR{name}=="ivtv6 encoder MPEG",SYMLINK+="ivtvenc6"
ATTR{name}=="ivtv7 encoder MPEG",SYMLINK+="ivtvenc7"

Watch it in action. Here it is after one reboot:

# ls -l /dev/ivtv*
lrwxrwxrwx 1 root root 6 2008-02-01 13:54 /dev/ivtvenc0 -> video0
lrwxrwxrwx 1 root root 6 2008-02-01 13:54 /dev/ivtvenc1 -> video1
lrwxrwxrwx 1 root root 6 2008-02-01 13:54 /dev/ivtvenc2 -> video2

And again after the next reboot

# ls -l /dev/ivtv*
lrwxrwxrwx 1 root root 6 2008-02-01 13:54 /dev/ivtvenc0 -> video2
lrwxrwxrwx 1 root root 6 2008-02-01 13:54 /dev/ivtvenc1 -> video3
lrwxrwxrwx 1 root root 6 2008-02-01 13:54 /dev/ivtvenc2 -> video4

Now I can always rely on the ivtvenc device nodes to point at the right cards.


30 January 2008

Solder Reflow with a Frying Pan – part 2

Filed under: Homemade Creations, Nerd Notes — adam @ 8:08 pm

Now that my pan is ready, it is time to do this. First I needed a board. I got one of my designs prototyped by Batch PCB who are cheap and did a good job but I had to wait about six weeks which is OK for hobbyists but I wouldn’t want to be in a hurry.

rubberglove.pngThis solder paste stuff is pretty toxic. Perhaps I’m going overboard here but I thought some rubber gloves would be a good idea.


What a mess!To apply the paste, I just squirted it on the board. It kinda went everywhere at first until I got the hang of it. Next time I’ll get a smaller tube and perhaps a smaller nozzle. I fixed it up as best I could using a toothpick and cotton tips. It took quite a lot longer and was much more messy than I anticipated.


pickandplace2.pngNext comes the pick-and-place. I got most of my parts from Digi-key who send them out as “Cut tape” which is pretty convenient, you just peel the backing off the tape until you get the quantity of parts you need and the rest are left still attached to the tape so you don’t lose them in the carpet. I positioned the parts with tweezers since most of them are incredibly teeny.

My board includes both surface-mount and through-hole components. I just placed the SMT stuff at this stage because I need the back of the board to be flat for heat transfer.

Now for the fun bit. I put the loaded board onto the pan cold. Then I increased temperature to around 100°C. I left it at that heat for a minute to get everything nice and warm. Then I cranked up the heat to maximum (in my case, 175°) until the solder melted. It was magic to watch. Everything just blobbed into place. Even components which were not exactly positioned right pulled themselves into line.

After a slow cool-down over 5 minutes, I examined the board. Everything looks good to my eye except for some pretty major bridging between the pins of my ARM chip. I’ll leave dealing with these to part 3.

In the end though, I’m pretty pleased with the result. Not bad for my first try!

A few bridges there!


27 January 2008

Solder Reflow with a Frying Pan – part 1

Filed under: Homemade Creations, Nerd Notes — adam @ 4:46 pm

I’ve been dying to have a go at this ever since I read some hobbyist websites on how to do solder reflow at home. I never even thought this was possible to do on a hobbyist budget.

Electric SkilletThe idea is to use a frying pan or toaster oven to perform solder reflow for SMT circuit boards. I decided to use a skillet thinking that a toaster oven would melt components since it heats both top and bottom.

I managed to find the perfect thing. A pre-owned 9″ electric skillet from the Salvation Army shop for $3.

Believe it or not, this device is not a precision instrument. The temperature dial is simply numbered from 1 to 10. The first thing I need to do is get some idea of what actual temperature this thing gets to.


Measuring the temperatureSo I need to do a scientific experiment. Firstly I put some oil in the pan and stuck in a thermometer (the fork is to hold the probe in the oil). Then I turned up the heat slowly making a note of the temperature. Finally I graphed the result. Here are the results in degrees C. That cheap little temperature knob is surprisingly linear.

  1. Element not energized
  2. 30°
  3. 46°
  4. 65°
  5. 90°
  6. 105°
  7. 125°
  8. 140°
  9. >150°
  10. >150°

The last two entries I could not measure since the thermometer only went up to 150°C, but by extrapolation I get 155° and 175°. Yes I did this on paper, it is much quicker than using Excel!

The results


I am now ready to use this thing for solder reflow.


26 January 2008

Warcraft II on Windows XP, A step-by-step guide

Filed under: Nerd Notes — adam @ 9:11 pm

Warcraft II – Tides of Darkness. I used to love this old DOS game way back when. But now I want to run it on Windows XP. Yes, it is possible. Here’s how.

DOSBOXDOS Emulation

First you need the very excellent DOSBOX which is a DOS emulator. You can download it from http://www.dosbox.com/.

Once DOSBOX is installed, we need somewhere to put our DOS games. I created a folder called C:\DOSGAMES for this purpose.


Now it is time to run DOSBOX. Once it is going, type the following two commands:

mount c C:\DOSGAMES\

mount d D:\ -t cdrom

NOTE: If your CD-ROM drive is not D:\, modify this accordingly.

Then you can insert your Warcraft II CD. The game can be installed like so:

D:

SETUP

Just select all the default options except for the soundcard and music device which you should set to Soundblaster 16.

Making an icon

At this point you can run the game by typing WAR2. But I don’t want to stop there. Let’s now make a pretty icon so you can launch the game with a mouse-click.

Open the folder C:\Program Files\DOSBox-0.72 and find the file dosbox.conf. Copy it to your C:\DOSGAMES\WAR2 folder.

Edit the copy of dosbox.conf and add the following line to the bottom under the [autoexec] section:

mount d D:\ -t cdrom

I’ve found it is also a good idea to reduce the speed of CPU emulation otherwise the map can scroll too fast. Modify the cycles entry in dosbox.conf like so:

cycles=20000

Now save the changes you made to dosbox.conf.

Warcraft II IconCopy the DOSBOX icon on your desktop. Rename the copy to “Warcraft II”. Now right-click on the icon and select Properties.



Enter the following text (all on one line) into the Target box:

 "C:\Program Files\DOSBox-0.72\dosbox.exe" "C:\DOSGAMES\WAR2\WAR2.EXE"
-conf "C:\DOSGAMES\WAR2\dosbox.conf" -exit -fullscreen

Then finally click on the Change Icon button.

Click Browse and navigate to the folder C:\DOSGAMES\WAR2. Double-click the file WAR2ICON.DLL.

Choose the WarCraft icon and then click OK. Click OK on the shortcut properties window also.

Now we are done. Click the WarCraft icon and enjoy!

Warcraft II


6 January 2008

TP-Link TL-WN550G PCI Wi-fi card in Ubuntu

Filed under: Nerd Notes — adam @ 9:16 pm

TP-Link TL-WN500G I finally got rid of that unreliable NetGear Wireless card and replaced it with a TP-Link card which uses the Atheros chipset. It was only $27 at UMart.

I’ve only had it for a couple of days but in that time I have transferred more than 10GB through it and it has been 100% reliable.

This one was not too difficult to get going on Ubuntu since it is well supported by the MadWifi drivers which are built in to Ubuntu.


However there is a little catch if you want to use WEP. You need to add the iwpriv command to activate your WEP. Here’s my /etc/network/interfaces file with the tricky bit highlighted in bold:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# TP-Link Wi-fi card
auto ath0
iface ath0 inet dhcp
        wireless-mode Managed
        wireless-essid adamnet
        pre-up iwpriv ath0 authmode 2
        wireless-key 1234567890

NOTES: If you are copying this, make sure to change the essid and key to match those of your own network. And if you think this is my real WEP key, you are in for some disappointment.


20 November 2007

A good VHDL tutorial

Filed under: Nerd Notes — adam @ 9:38 am

I had to brush up on my VHDL recently for a project and I discovered the Low-carb VHDL Tutorial by Bryan Mealy.

I really wish I’d read this one back when I was getting started in VHDL. I wouldn’t have found it so hard. This document describes the basics of VHDL in a very clear and readable way. It’s well worth a look if you are wanting to learn VHDL.


15 November 2007

Moving a DirectShow window while paused

Filed under: Nerd Notes — adam @ 2:26 pm

directshowmoveproblem.jpegI’ve been writing a lot of DirectX / DirectShow stuff lately and I’ve come across a problem if I pause a video replay and then move the containing window. The playback window becomes separated from the containing window even though I am handling the WM_MOVE event.

You’d think that the following code would work:

void CMyWindow::OnMove()
{
    CRect r;
    GetClientRect(r);

// _piWindow is a pointer to my filtergraph's IVideoWindow interface.
    _piWindow->SetWindowPosition(r.left, r.top, r.Width(), r.Height());
}

It works fine if the video is playing but if the replay is paused, the active movie window will ignore the window move commands.

The solution was to trick DirectShow into thinking that you want to resize the window like so:

void CMyWindow::OnMove()
{
    CRect r;
    GetClientRect(r);

    _piWindow->SetWindowPosition(r.left, r.top, r.Width() + 4, r.Height());
    _piWindow->SetWindowPosition(r.left, r.top, r.Width(), r.Height());
}

« Previous PageNext Page »

Powered by WordPress