Thursday, 3 July 2008

A perfect Linux MAME cab installation

Debian


First, the Debian installation. Wherever possible I've taken the simplest options, such as using ftpd and telnetd rather than more elaborate remote administration tools. Any hacks have been done in the correct Debian fashion and are on show for anyone to see and adapt.


Installation


This example uses Debian Linux 4.0 (etch). Whatever method you choose to install with, choose defaults throughout except with the below:



  • Hostname can be whatever you like, I choose mame

  • Domain should normally be set to example, test, or invalid. If you want to know why, read RFC 2606. You'll know if it needs to be set to anything else!

  • When partitioning, change the mount options to noatime,sync.

  • Create a new user account called mame.

  • When asked about "Software selection" unselect everything.


Customisation


After the forced reboot, we run through the steps needed to tweak the OS for our needs.



  1. Get our system bang up to date: aptitude update && aptitude dist-upgrade

  2. Install tools we'll need: aptitude install telnetd ftpd fbset mingetty

  3. Move the installed /etc/fb.modes somewhere safe: mv /etc/fb.modes /etc/fb.modes.sample

  4. Enable the framebuffer. This can be done in three ways: compiling one or more drivers into the kernel and loading the appropriate one at boot (hardest), by adding one or more as modules to the initial RAM disk and loading at boot (easier), or by loading them in the startup scripts (easiest). I add them all to the startup scripts, it's the quickest and easiest to fix.

    • You'll need to identify what modules are available: ls -R /lib/modules/`uname -r`/kernel/drivers/video/ | grep .ko | sed s/.ko// | sort. Currently, the list I use is: arcfb aty128fb atyfb cirrusfb cyber2000fb cyblafb gx1fb gxfb hgafb i810fb intelfb kyrofb matroxfb neofb nvidiafb pm2fb radeonfb s1d13xxxfb savagefb sisfb sstfb tdfxfb tridentfb. Not all of these have been tested on an arcade monitor, but all should be suitable for PC use.

    • This will help you identify what hardware is in the machine: lspci | grep VGA

    • To load modules via the initial RAM disk (initrd):

      1. nano -w /etc/initramfs-tools/modules

      2. update-initramfs -u



    • To load modules from the startup scripts: nano -w /etc/modules.



  5. Logging in automatically as the mame user is accomplished by editing /etc/inittab (we're replacing getty with mingetty for tty1 - the first console - and setting the mame user to automatically login): sed -ie 's,getty 38400 tty1,mingetty --autologin=mame tty1,g' /etc/inittab

  6. Giving root telnet and ftp access is bad security practice - but it makes our lives a bit easier when setting up the system. You could always skip this and use su, or reverse the changes once you're happy with everything.

    • nano -w/etc/securetty and add the following:

      # Telnet
      pts/0
      pts/1
      pts/2
      pts/3
      pts/4
      pts/5
      pts/6
      pts/7
      pts/8
      pts/9

    • Allow root ftp access: sed -i 's/\#root/root/g' /etc/ftpusers



  7. To stop DHCP taking an age when not connected to a network, edit /etc/network/interfaces and replace the keyword "auto" with "allow-hotplug" except on the loopback interface (lo)

  8. We want to add some fake kernel parameters to our grub menu. This tells update-grub to add extra boot options other than the standard and single user. /proc/cmdline contains the boot parameters and we can run scripts based on this to configure the system automatically.

    1. Edit /boot/grub/menu.lst. add extra #altoptions = lines as follows:

      # altoptions=(15.75kHz Horizontal) hclock=15.75 fbcon=rotate_all:0
      # altoptions=(15.75kHz Vertical) hclock=15.75 fbcon=rotate_all:1
      # altoptions=(16.5kHz Horizontal) hclock=16.5 fbcon=rotate_all:0
      # altoptions=(16.5kHz Vertical) hclock=16.5 fbcon=rotate_all:1
      # altoptions=(25kHz Horizontal) hclock=25 fbcon=rotate_all:0
      # altoptions=(25kHz Vertical) hclock=25 fbcon=rotate_all:1
      # altoptions=(31.5kHz Horizontal) hclock=31.5 fbcon=rotate_all:0
      # altoptions=(31.5kHz Vertical) hclock=31.5 fbcon=rotate_all:1
      # altoptions=(15.75+25+31.5kHz Horizontal) hclock=15.75+25+31.5 fbcon=rotate_all:0
      # altoptions=(15.75+25+31.5kHz Vertical) hclock=15.75+25.31.5 fbcon=rotate_all:1

    2. Change the "default" line to read "saved" instead of "0". This will remember our previous selection and use this for the next boot.

    3. Add a line right at the top of the file that reads: setkey enter control This maps the Enter key to the standard MAME entry for P1B1 - the Left Control key. Enter is still found at it's default position. We can now change the boot option using a keyboard or a MAME mapped joystick!

    4. Save the file, then run update-grub to commit the changes.



  9. Create arcade script:

    1. nano -w /etc/init.d/arcade



    2. #! /bin/bash

      case "$1" in
      start)
      # Modelines
      if grep hclock=15.75+25+31.5 /proc/cmdline > /dev/null ; then
      echo "Using 15.75+25+31.5kHz modelines..."
      ln -sf /etc/fb.modes.15.75+25+31.5 /etc/fb.modes
      elif grep hclock=15.75 /proc/cmdline > /dev/null ; then
      echo "Using 15.75kHz modelines..."
      ln -sf /etc/fb.modes.15.75 /etc/fb.modes
      elif grep hclock=16.5 /proc/cmdline > /dev/null ; then
      echo "Using 16.5kHz modelines..."
      ln -sf /etc/fb.modes.16.5 /etc/fb.modes
      elif grep hclock=25 /proc/cmdline > /dev/null ; then
      echo "Using 25kHz modelines..."
      ln -sf /etc/fb.modes.25 /etc/fb.modes
      elif grep hclock=31.5 /proc/cmdline > /dev/null ; then
      echo "Using 31.5kHz modelines..."
      ln -sf /etc/fb.modes.31.5 /etc/fb.modes
      else
      echo "No monitor type chosen, using generic PC VGA..."
      fbset --all -match -xres 640 -yres 480
      ln -sf /etc/fb.modes.sample /etc/fb.modes
      fi

      # Rotation
      if grep fbcon=rotate_all:0 /proc/cmdline > /dev/null ; then
      echo "Using horizontal monitor..."
      # Console
      echo 0 > /sys/class/graphics/fbcon/rotate_all
      # MAME
      sed -i 's/^rotate *0/rotate 1/g' /home/mame/.mame/mame.ini
      sed -i 's/^ror *1/ror 0/g' /home/mame/.mame/mame.ini
      # AdvanceMENU
      sed -i 's/vertical include$/vertical exclude$/g' /home/mame/.advance/advmenu.rc
      sed -i 's/vertical exclude_not$/vertical exclude$/g' /home/mame/.advance/advmenu.rc
      elif grep fbcon=rotate_all:1 /proc/cmdline > /dev/null ; then
      echo "Using vertical monitor..."
      # Console
      echo 1 > /sys/class/graphics/fbcon/rotate_all
      # MAME
      sed -i 's/^rotate *0/rotate 1/g' /home/mame/.mame/mame.ini
      sed -i 's/^ror *0/ror 1/g' /home/mame/.mame/mame.ini
      # AdvanceMENU
      sed -i 's/vertical include$/vertical exclude_not$/g' /home/mame/.advance/advmenu.rc
      sed -i 's/vertical exclude$/vertical exclude_not$/g' /home/mame/.advance/advmenu.rc
      else
      echo "Using rotate mode (vertical on horizontal)..."
      # MAME
      sed -i 's/^rotate *0/rotate 1/g' /home/mame/.mame/mame.ini
      sed -i 's/^ror *1/ror 0/g' /home/mame/.mame/mame.ini
      # AdvanceMENU
      sed -i 's/vertical exclude_not$/vertical include$/g' /home/mame/.advance/advmenu.rc
      sed -i 's/vertical exclude$/vertical include$/g' /home/mame/.advance/advmenu.rc
      fi
      ;;
      stop)
      echo "Clearing fb.modes..."
      ln -sf /etc/fb.modes.sample /etc/fb.modes
      echo "Clearing rotation..."
      # MAME
      sed -i 's/^rotate *0/rotate 1/g' /home/mame/.mame/mame.ini
      sed -i 's/^ror *1/ror 0/g' /home/mame/.mame/mame.ini
      # AdvanceMENU
      sed -i 's/vertical exclude_not$/vertical include$/g' /home/mame/.advance/advmenu.rc
      sed -i 's/vertical exclude$/vertical include$/g' /home/mame/.advance/advmenu.rc
      # Console
      echo 0 > /sys/class/graphics/fbcon/rotate_all
      ;;
      *)
      echo "Usage: /etc/init.d/jamma {start|stop}"
      exit 1
      ;;
      esac

      exit 0

    3. Make it executable: chmod +x /etc/init.d/arcade

    4. Run automatically on boot: update-rc.d arcade defaults 50



  10. Edit udev permissions so that any user can write to the framebuffer tty

    1. nano -w /etc/udev/permissions



    2. KERNEL=="tty0", MODE="0666", GROUP="root"
      KERNEL=="tty[1-9]*", GROUP="root"



  11. Edit the mame user login script

    1. nano -w /home/mame/.bash_profile

    2. Add the following lines:

      export SDL_VIDEO_YUV_DIRECT=1
      export SDL_VIDEODRIVER=directfb
      export SDLMAME_DESKTOPDIM=640x480
      export DFBARGS=depth=16,no-debug,no-trace,desktop-buffer-mode=frontonly,no-cursor,no-banner,quiet,dma,sync,no-vt-switch,disable-module=x11,disable-module=joystick,disable-module=linux_input,bg-color=000000
      advmenu




SDLMAME



  1. Install SDL: aptitude install make libsdl-dev libgconf2-dev Sadly the development libraries for SDL in Debian depend on huge amounts of other packages, but these are only needed for compiling! Once compiled, you can happily purge the above packages, and install libsdl by itself.

  2. Grab the source from http://rbelmont.mameworld.info/?page_id=163.

  3. Decompress: 7z x sdlmame*.zip

  4. cd sdlmame*

  5. A small change is needed to the source to get it to compile on Debian:

    1. nano -w src/osd/sdl/sdlsync.h

    2. Change #define THREAD_COOPERATIVE (1) to #define THREAD_COOPERATIVE (0).



  6. Compile:

    1. make clean

    2. make NO_X11=1 NO_OPENGL=1




Notes



  • Enable switchres in mame.ini. Enable window in mame.ini

  • You can optimize disk performance with hdparm. Be careful and read the documentation!

    1. aptitude install hdparm

    2. Check performance with: hdparm -Tt /dev/hda

    3. nano -w /etc/conf.d/hdparm

    4. invoke-rc.d hdparm start

    5. Check performance again



  • Changing the system volume is done with the tool alsamixer. Use the m key to unmute a channel and set a sensible volume. AdvanceMAME normalises game volume so you don't need to touch volume inside it.

  • Trimming down disk usage:

    1. aptitude install localepurge

    2. aptitude purge tasksel tasksel-data cron logrotate info man-db manpages ed vim-common vim-tiny installation-report iptables netcat libsasl2 dictionaries-common ispell usbutils laptop-detect dmidecode eject ibritish myspell-en-gb wbritish util-linux-locales groff-base bsdmainutils



  • If the install was done with a netinst CD, or you simply want to use internet sources only, comment out the CD-ROM entry in /etc/apt/sources.list

  • Compiling a custom kernel

    1. Install tools necessary to recompile the kernel: aptitude install kernel-package linux-source build-essential libncurses5-dev bzip2

    2. Decompress kernel sources:

      1. tar jxf /usr/src/linux-source-*.tar.bz2

      2. cd /usr/src/linux-source*



    3. Edit /etc/kernel-pkg.conf with your personal details if desired

    4. Clean up any old compile data and use the current kernel configuration:

      1. make-kpkg clean

      2. cp /boot/config-`uname -r` ./.config



    5. Make changes to the kernel configuration: make menuconfig

    6. Compile your custom kernel: make-kpkg --initrd kernel_image kernel_headers

    7. Install custom kernel: dpkg -i kernel-image-x.y.z.yy.mm.dd_10.00.Custom_i386.deb



Labels: , , , ,

Friday, 4 April 2008

Handy Debian bits and pieces

Put OpenSSH on so we can configure the device remotely.
aptitude install openssh-client openssh-server

Set up a nice /etc/issue with coloured ASCII debian logo:

 _,met$$$$$gg.
 ,g$$$$$$$$$$$$$$$P.
 ,g$$P"" """Y$$.".
 ,$$P' `$$$.
 ',$$P ,ggs. `$$b:
 `d$$' ,$P"' . $$$
 $$P d$' , $$P
 $$: $$. - ,d$$'
 $$; Y$b._ _,d$P'  _, _, ,'`.
 Y$$. `.`"Y$$$$P"'  `$$' `$$' `. ,'
 `$$b "-.__  $$ $$ `'
 `Y$$b  $$ $$ _, _
 `Y$$.  ,d$$$g$$ ,d$$$b. $$,d$$$b.`$$' g$$$$$b.`$$,d$$b.
 `$$b.  ,$P' `$$ ,$P' `Y$. $$$' `$$ $$ "' `$$ $$$' `$$
 `Y$$b.  $$' $$ $$' `$$ $$' $$ $$ ,ggggg$$ $$' $$
 `"Y$b._  $$ $$ $$ggggg$$ $$ $$ $$ ,$P" $$ $$ $$
 `"""" $$ ,$$ $$. $$ ,$P $$ $$' ,$$ $$ $$
`$g. ,$$$ `$$._ _., $$ _,g$P' $$ `$b. ,$$$ $$ $$
`Y$$P'$$. `Y$$$$P',$$$$P"' ,$$. `Y$$P'$$.$$. ,$$.

Debian GNU/\s lenny/sid \n \l

Labels: ,

Tuesday, 1 April 2008

Debian sid (armel) on SL-C3200

Notes on a "proper" Debian installation. We start with the applied-data armel-root-fs, an up to date kernel, and move to official sources.

The stuff relating to networking is specific to me, everything else is a standard install.

NAND restore to Sharp bootloader
Grab latest yonggun kernel (hda2) and modules, and updater.sh
Grab armel-root-fs
Grab spectrum 24 firmware
Uncompress (but leave as tar files), put all on root of SD
The following armel debs are needed:
console-tools and libconsole http://ftp.uk.debian.org/debian/pool/main/c/console-tools
tzdata http://ftp.uk.debian.org//debian/pool/main/t/tzdata/
libc6 http://ftp.uk.debian.org//debian/pool/main/g/glibc/
wireless-tools and libiw http://ftp.uk.debian.org//debian/pool/main/w/wireless-tools/
Boot into emergency mode (B+D), fdisk and format /dev/hda1 as swap (256MB), /dev/hda2 as ext3. Putting swap as hda1 is faster.
Untar armel-root-fs onto /dev/hda2
Untar modules
Untar firmware into /lib/firmware
Reboot into flash menu (OK). Flash kernel
Reboot twice.

Login as root (no password)

dpkg -i the debs

Set /etc/hostname to zaurus
Set 127.0.0.1 localhost zaurus in /etc/hosts

Setup /etc/network/interfaces
dhclient
route del default gw 192.168.2.1
route add default gw 192.168.2.254

date 030410412008 (MMDDHHMMYYYY)
aptitude update
cd /sbin
mv start-stop-daemon start-stop-daemon.FAKE
mv start-stop-daemon.REAL start-stop-daemon
aptitude install libc6-dev

Run aptitude, disable automatically installing recommended packages

Get spitz keymap
http://inv2004.googlepages.com/keymap-spitz.tar.bz2
Untar keymap
mkdir /usr/share/keymaps/zaurus
mv keymap.map /usr/share/keymaps/zaurus/spitz.kmap
gzip /usr/share/keymaps/zaurus/spitz.kmap
aptitude install console-common - Don't touch keymap
install-keymap /usr/share/keymaps/zaurus/spitz.kmap.gz

aptitude upgrade
aptitude dist-upgrade (asks about libsasl2. Choose n to first solution, y to second. This removes libsasl2, which isn't available in armel.)

Fix exim4 moaning:
rm /var/log/exim4/paniclog
invoke-rc.d exim4 restart

Setup fstab
proc /proc proc defaults 0 0
/dev/hda2 / ext3 defaults,errors=remount-ro 1 1
/dev/hda1 none swap pri=1 0 0
/dev/mmcblk0p1 /media/card auto defaults,sync,noauto,user 0 0
devpts /dev/pts devpts mode=0620,gid=5 0 0

Correct time and timezone:
aptitude install ntpdate
dpkg-reconfigure tzdata
ntpdate uk.pool.ntp.org
hwclock -w

Strip out obselete packages
aptitude purge libdevmapper1.02 libopencdk8 slang1a-utf8

Load some modules we need that don't autoload in /etc/modules:
snd-soc-spitz
ohci-hcd

Xorg:
aptitude install xorg xserver-xorg-input-tslib xserver-xorg-input-void xserver-xorg-input-evtouch x-ttcidfont-conf xfonts-base xfonts-cyrillic xfs libts-bin libts-0.0-0

Get touchscreen working:
tslib is hardcoded to /dev/event0 at the moment, so we need to tell udev to symlink.
Do this manually:
ln -s /dev/input/event1 /dev/event0
Then add the following line to /etc/udev/links.conf to fix it on reboots
L event0 /dev/input/event1
To calibrate touchscreen:
export TSLIB_TSDEVICE="/dev/event0" && ts_calibrate



Working xorg.conf:
Section "InputDevice"
Identifier "Built-in keyboard"
Driver "kbd"
Option "XkbRules" "xorg"
Option "XkbModel" "zaurus"
Option "XkbLayout" "us"
EndSection

Section "InputDevice"
Identifier "Touch Screen"
Driver "tslib"
Option "Device" "/dev/event0"
Option "Protocol" "Auto"
EndSection

Section "Device"
Identifier "Framebuffer"
Driver "fbdev"
Option "Rotate" "CW"
EndSection

Section "Monitor"
Identifier "LCD"
EndSection

Section "Screen"
Identifier "Zaurus Screen"
Monitor "LCD"
Device "Framebuffer"
EndSection

Section "ServerLayout"
Identifier "Sharp Zaurus"
Screen "Zaurus Screen"
InputDevice "Touch Screen" "CorePointer"
InputDevice "Built-in Keyboard" "CoreKeyboard"
EndSection


Still to do - sound!

Labels: , ,

Monday, 31 March 2008

Debian EABI on a Sharp Zaurus SL-C3200

1. Install http://www.trisoft.de/download/SYSTC320.zip

SYSTC320.zip NAND-Backup from 04/11/2006
First version we shipped.


Please note the file size is about 64 MB.

Attention: We're not liable for using these backups. Not for data loss nor misfunctions !

How to: Download the ZIP-file, unzip it. Then copy the file to a card (at least 256 MB). Power down the Zaurus and remove all power sources (no AC adaptor and remove the battery!). Set the battery switch to the "Offen" position and wait for at least 5 seconds. Then connect the AC adaptor and put back the battery. Hold down the [D] and [M] keys and set the battery switch back to "Betrieb" (while keys are pressed!). After a short moment the diagnostics menu should appear. If not, try it again and this time hold down the [D] and [M] keys before you restore the power (AC adaptor / battery).
Insert the CF card in the Zaurus and choose "Backup Menu" and then "Flash RESTORE" on page 3 of the diag menu. The restore will take some time, so please be patient.

2. Boot up. Open terminal. su. umount /hdd1 /hdd2 /hdd3. fdisk. delete all partitions. create 2 new partitions - 256M + rest. change /dev/hda1 to type 82 (swap). mke2fs -j /dev/hda2. mkswap /dev/hda1. mount /dev/hda2 /hdd1

3. Download http://yonggun.tistory.com/68 hda2 kernel, rename to zImage.bin - copy to SD. Download http://yonggun.tistory.com/68 modules, ungzip, copy tar to SD. Download http://www.oesf.org/forum/index.php?act=attach&type=post&id=5291, rename to updater.sh, copy to SD.

4. Download http://matrixmen.free.fr/zaurus/debian/zaurus_eabi_rootfs_071201.tar.bz2. Unbzip, copy tar to SD.

5. Drop SD card into Zaurus. Copy rootfs tar from SD to /hdd1. tar -xpf zaurus_eabi_rootfs_071201.tar

6. Copy modules tar into /hdd1. tar -xpf 2.6.24.3-yonggun.cpufreq.fastfpe.tar

7. Copy symbol_sp24t_prim_fw and symbol_sp24t_sec_fw into /hdd1/lib/firmware

8. Edit /hdd1/etc/network/interfaces. Change eth2 to eth3 and configure accordingly.

8. Reboot the machine into the normal Flash Menu (press [OK] before powering up/rebooting). In the Japanese menu, choose "4", then choose the media, then choose "Y" to confirm.

9. Reboot twice to bring up console.

10. Continue from step 5 here. http://www.oesf.org/forum/index.php?showtopic=25029

11. Bring up networking with ifup eth3

Labels: , ,

Monday, 24 September 2007

vlc transcoding for portable players

Here's the script I use to transcode all the video files in the current directory to 320 pixel wide MP4 format files suitable for playback on devices limited in both CPU and RAM - in my case my mobile phone.

Total bitrate (video and audio) is 128kbps, which works out as roughly 1MB a minute. This works better on cartoons than it does on live action or CG. Audio is downsampled to mono 11025hz to avoid excessive artifacting.

#!/bin/bash
vcodec="mp4v"
acodec="mp4a"
bitrate="96"
w=320
arate="32"
asrate="11025"
achannels="1"
ext="mp4"
mux="mp4"
vlc="vlc"
out="/media/files/video/portable/"

for a in *; do
if ! [ -f "$out$a.$ext" ]
then
$vlc -I dummy -vvv "$a" --sout "#transcode{vcodec=$vcodec,vb=$bitrate,width=$w,autocrop,scale,deinterlace,audio-sync,acodec=$acodec,ab=$arate,samplerate=$asrate,channels=$achannels}:standard{mux=$mux,dst=\"$out$a.$ext\",access=file}" vlc:quit
fi
done

Labels: , , , , ,