Plain Gentoo Linux on the XBox

Why?

There is NO GOOD REASON to run GentooX on your XBox. PERIOD. You can and should use plain Gentoo. Just add my XBox ebuilds.

The only catch is that I tested the ebuilds on a Gentoo from late 2006, so some of them (mostly just the kernel) are out of date. but this catch is actually the main virtue of my ebuilds: because of the way one installs Gentoo and the loose way portage glues itself together, compared to other abandonware XBox distros, it's much easier to start with my abandoned ebuilds and make a working, up-to-date system.

What's in these ebuilds?

sys-boot/cromwell
This will make you a Cromwell that actually has some prayer of working on all versions of XBox, unlike almost anything else out there. I've only tested it on revision 1.4 and 1.6a, though. The Cromwell at xbox-linux.org is hopelessly out-of-date and just plain broken. This one adds some patches I wrung out of Thomas ``ShAllAxX!!!'' Pedley, who in turn dredged them out of some mod chip company's leak onto bittorrent or something, plus some patches of mine to debrand all shallax's garbage. You get full source code, and it (probably) works. The tarball itself does not include the xcodes needed to boot on revision 1.6a and 1.6b XBoxes, but the ebuild will automatically download them from my web site. Things my Cromwell does that xbox-linux.org's doesn't:

just use my cromwell distribution, and don't ever look back.

sys-boot/raincoat
needed for read/write of mod chips and revision 1.0 - 1.5 internal FLASH. Cromwell also has (different) support for writing mod chips, but not reading them. To write internal flash, you must open your XBox and add a small wire to the board. On revision 1.6 XBox, you can only read the internal FLASH with this raincoat, not write it.
sys-kernel/xbox-sources
Gentoo already provides an xbox-sources kernel, but theirs is missing the genpatches, so it can't boot Gentoo's on LiveCD's. Mine has genpatches, and has some other fixes:

sys-kernel/genkernel
You need to use my genkernel, with my 'append' options, if you use the default config supplied with my kernel above. This is the only ebuild you can use on non-XBoxes, and which you can avoid using on the XBox if you really want to. This will work fine on non-XBoxes, but you will have to make the udev adjustment below. Advantages of my genkernel:

media-sound/alsa-driver
The provided alsa-driver ebuild needs some tiny patch, and also after using this ebuild, snd_intel8x0 still needs the option xbox=1 at load time. I think the alsa-driver in the kernel above is also patched, but I tested with this one. I think it's better to use the ebuild because of the lousy politics of Linux kernel committers who often NIH over the people doing the bulk of actual work.
media-video/rpcmgr
If you replace your XBox DVD-ROM with a LiteON DVD burner (probably a good idea), this will set it to be region-free and work well with libdvdcss. Also, you can stick a DVD in, and it will tell you the region(s) allowed by that DVD, which are often more than one region and not matching what the box says.
sys-apps/xbox-tools
stuff to make the eject button LED stop flashing, and to lock/unlock the MS password security of the IDE hard disk (which Cromwell can also do).

Now, to install on a fresh XBox, here's what you need.

  1. Buy a mod chip and install it. If you have 1.0 - 1.5 XBox, you can try to install to the built-in FLASH, but I haven't tested that yet.
  2. Build Cromwell, or cheat by using my pre-built Cromwell.
    1. Get another system already running Gentoo.
    2. Download my XBox ebuilds onto your existing Gentoo system
    3. If you want to change the background image, use The Gimp on /usr/local/portage/sys-boot/cromwell/files/backdrop.xcf.bz2, and then ebuild /usr/local/portage/sys-boot/cromwell/cromwell-20050612.ebuild digest.
    4. set CROMWELL_BANNER_HOSTNAME in /etc/make.conf to change the hostname displayed in the upper right corner.
    5. emerge sys-boot/cromwell and find your Cromwells in /usr/mdec/cromwell.
  3. Use the README file to learn which Cromwell belongs in your XBox, and load it into the mod chip. I've used two kinds of mod chips. One can overwrite itself from an image on a CD, and the other accepts images by running an internal web server to which you POST the images.
  4. Make a Gentoo Minimal/Install CD that works on the XBox, or cheat by using mine.
    1. Get another system already running Gentoo. Your other system's kernel must have squashfs in it (part of Genpatches) so you can mount the Gentoo CD.
    2. Download my XBox ebuilds onto your existing Gentoo system, and emerge sys-kernel/xbox-sources sys-kernel/genkernel sys-boot/raincoat sys-apps/xbox-tools. Cromwell, xbox-sources, xbox-tools, and raincoat are no problem, but note that my genkernel will overwrite your existing genkernel, so if you don't like this, you'll have to emerge regular genkernel when you're done.
    3. Build an XBox kernel.

      cd /usr/src/linux-2.6.15.1
      # build /lib/modules//* /var/tmp/genkernel/kernel- and /var/tmp/genkernel/System.map-, and install config in /etc/kernels/kernel-config-
      genkernel --debugfile=/usr/src/linux-2.6.15.1/genkernel.out --no-bootsplash --no-gensplash --no-install --kerneldir=/usr/src/linux-2.6.15.1/ --oldconfig kernel
      
      # rebuild the sound and video modules we use outside the main kernel distribution.
      # skip this for now
      #emerge media-sound/alsa-driver x11-base/x11-drm
      
      # build /var/tmp/genkernel/initramfs-<ver>
      genkernel --debugfile=/usr/src/linux-2.6.15.1/genkernel.out --no-bootsplash --no-gensplash --no-install --kerneldir=/usr/src/linux-2.6.15.1/ --oldconfig initrd
      

    4. Download the Gentoo Minimal/Install CD for x86. Sorry for this, but you have to get an older Minimal/Install CD so that my older kernel will be able to read the squashfs on it. Here's how you mount the CD:

      mkdir /cd; mount -t iso9660 -o ro,loop=/dev/loop0 install-x86-minimal-2006.1.iso /cd
      
      # get a read-write copy of the CD
      cd / && pax -rwpe cd ~
      cd
      umount /cd; rmdir /cd
      

      Now you have the InstallCD in ~/cd. We'll make some changes, then burn our version onto a physical CD-ROM that we can boot in the XBox.

      Mount the squashfs inside, and copy some things into it:

      mkdir /squashcd; mount -t squashfs -o loop=/dev/loop0 image.squashfs /squashcd
      
      # get a read-write copy of the squashfs
      cd / && pax -rwpe squashcd ~
      cd
      umount /squashcd; rmdir /squashcd
      
      #copy xbox-tools and raincoat into the squashfs
      cat /var/db/pkg/sys-boot/raincoat-0.11/CONTENTS /var/db/pkg/sys-apps/xbox-tools-20050725/CONTENTS |
       awk '{ if ( $1 == "obj" ) { print gensub("^/", "", 1, $2) } }' | \
       ( cd / && pax -w ) | ( cd ~/squashcd && pax -rvpe )
      
      #copy kernel modules into the squashfs
      (cd /lib/modules && tar cf - 2.6.15.1-xbox ) | (cd ~/squashcd/lib/modules && tar xpf -)
      
      #make new squashfs
      emerge =sys-fs/squashfs-tools-2.2_p2
      rm cd/image.squashfs; mksquashfs squashcd/ cd/image.squashfs -check_data
      chmod 555 cd/image.squashfs
      

    5. Put the kernel you just built onto the CD, along with a config file for Cromwell:

      mkdir ~/cd/boot
      cp /var/tmp/genkernel/initramfs-2.6.15.1-xbox ~/cd/boot/xboxirfs
      cp /var/tmp/genkernel/kernel-genkernel-x86-2.6.15.1-xbox ~/cd/boot/xboxkern
      ln -s xboxkern ~/cd/boot/kernel-genkernel-x86-2.6.15.1-xbox
      ln -s xboxirfs ~/cd/boot/initramfs-2.6.15.1-xbox
      
      # help yourself out later
      cp /usr/src/linux-2.6.15.1/.config ~/cd/boot/dot.config-2.6.15.1-xbox
      cp /usr/src/linux-2.6.15.1/System.map ~/cd/boot/System.map-genkernel-x86-2.6.15.1-xbox
      
      cat > ~/cd/linuxboo.cfg << EOF
      title Linux
      kernel /boot/xboxkern
      initrd /boot/xboxirfs
      append cdroot looptype=squashfs loop=/image.squashfs doload=squashfs,isofs,loop,nls_iso8859_15
      EOF
      
      

      As you can see from the config file's format, Cromwell is definitely not the same as Grub. Its philosophy is similar because it contains Grub's filesystem-reading code, but the config-file-parsing and device-enumerating code is Cromwell's own. There is no ``Stage 2'' with Cromwell---the Grub filesystem code is burned right into the FLASH.

    6. Burn the CD. Or better yet, burn a DVD, which is more likely to read in an XBox DVD-ROM.
      cd
      
      mkisofs -o install-x86-minimal-2006.0-xbox.iso -J -r -publisher "Ivy Ministries" -V gentoo-xbox -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table cd/
      
      # optional.  only works with LiteON writers.  
      # This made the difference whether my Samsung SDG-605B drive would read the DVD+R or not.
      # sorta.  it still seems to give read errors.  Use a CD-RW, or replace the drive with normal IDE DVD-ROM.
      dvd+rw-booktype -dvd-rom-spec -unit+r /dev/hdb
      
      growisofs -dvd-compat -Z /dev/hdb=install-x86-minimal-2006.0-xbox.iso 
      
  5. Boot the CD/DVD you just made, and install Gentoo normally, except for Grub and setting an ``active'' partition.

    Also, if you turn off ``DOS compatibility'' and ``change display/entry units to sectors'' in fdisk like I did, don't put any filesystems in the fourth sector (LBA 3), because the MS ROM will scribble there if you ever accidentally let it boot.

  6. Configuring the bootloader is a bit different for XBox, and for my kernel/genkernel. Below is a lot of detail, but you need to know it to control what modules are loaded or not loaded by the initramfs early-userspace, and you may decide to load different modules than me for some reason.

    Gentoo initramfs's grab modules from /lib/modules/<version>/kernel/... and put them into the initramfs based on a list in /usr/share/genkernel/x86/modules_load. The modules are split into categories like SCSI, FIREWIRE, ATARAID, DMRAID, LVM2, EVMS2, PCMCIA, USB, SATA, FS, IDE, NFS. Most of the modules assigned to categories by Genkernel's modules_load file are implicitly disabled because they are disabled in my kernel config file and never built---these will be left out of the initramfs and not loaded without causing any error. Some categories are off by default, as controlled by MY_HWOPTS in /usr/share/genkernel/generic/initrd.defaults. You change the defaults by editing the append line in /linuxboot.cfg. You can turn whole categories on or off by adding dosata or nosata to the kernel command line, or you can turn individual modules on or off with noload=usb-storage or doload=ext3,isofs,squashfs,loop. Sometimes the initramfs will load a module you didn't explicitly or implicitly mention because it's needed for a feature, like unionfs or NFS, and you've asked it for that feature. Sometimes it's too dumb to do that.

    For disk booting, I use:

    title Linux
    kernel /boot/kernel-genkernel-x86-2.6.15.1-xbox
    initrd /boot/initramfs-2.6.15.1-xbox
    append real_root=/dev/hda4 nodmraid noload=usb-storage nofs doload=ext3
    

    you can put other title's in there if you want. Cromwell will give you a vertical text menu as a second step after you select the hard disk from the horizontal icon menu. To see the vertical menu, you have to select the hard disk rather than waiting for the timeout.

    For NFS booting, I use:

    append real_root=/dev/nfs nofs noide nodmraid noload=usb-storage doload=forcedeth
    

    The path to the NFS root filesystem is specified in DHCP, for example by options root-path "10.100.100.140:/export/nbnfs/armitage"; in ISC dhcpd.conf.

    If you boot over NFS, you'll need to make a couple other changes. First, remove net.eth0 entirely. Just let the initramfs set up the network card.

    Second, change:

    --- etc/init.d/functions.sh.orig	2007-03-04 22:41:43.000000000 -0800
    +++ etc/init.d/functions.sh	2007-03-04 18:35:57.889644087 -0800
    @@ -607,7 +607,7 @@
     # Network filesystems list for common use in rc-scripts.
     # This variable is used in is_net_fs and other places such as
     # localmount.
    -NET_FS_LIST="afs cifs coda davfs gfs ncpfs nfs nfs4 shfs smbfs"
    +[ "X$NET_FS_LIST" = X ] && NET_FS_LIST="afs cifs coda davfs gfs ncpfs nfs nfs4 shfs smbfs"
     
     # bool is_net_fs(path)
     #
    
    

    and put a line in /etc/conf.d/rc that says: NET_FS_LIST="afs cifs coda davfs gfs ncpfs shfs smbfs"

    This will keep the rc scripts from unmounting the root filesystem too early during shutdown. It'll also make them mount other NFS filesystems earlier during startup, which is no problem since the initramfs has already brought up networking.

    Third, add amd74xx and ide-cd to /etc/modules.autoload.d/kernel-2.6 because the append line I gave you above will not load the IDE drivers from the initramfs, so your CD-ROM won't work.

  7. Once you've got the system basically booting, clean up a few loose ends.
  8. Test the new ALSA, then switch back to OSS, or to OSS-emulating ALSA with an OSS userland. One of my XBoxes can play DVD's smoothly, while the other one is jerkey. The one that works is OSS, and the one that's jerkey is ALSA (I've set make.conf to build the ALSA stack only.). I made the skipping better by reducing the size of one of the ALSA buffers, so I think ALSA just sucks. I think sound is tricky. I think either ALSA is a fundamentally broken architecture, or that the mplayer ALSA output module is not using enough features. but I don't really know the details. I just think it's dumb. I want to fire the whole ALSA project. I want to be able to fire whole projects that cause problems, and stick with old abandoned stuff until the new overhyped stuff is actually demonstrably top-to-bottom working, not just ``showing promise.'' These damn open-source guys break things and never finish fixing them. It's the bane of the community. It limits the overall size of the projects we can make.
  9. Now, figure out how to make Cromwell load kernels over TFTP. Supposedly the old CVS cromwell had Etherboot and could do this, but it never worked for me, and I can't imagine how it'd work because of all the 8086 code and BIOS calls in the NBI and PXE stacks.
  10. Get xmame to work.
  11. Give up and install FLASH. People keep wanting to watch Youtube crap. Even when it works a little, fullscreen never seems to work right on Linux. Most importantly, Youtube is DRM. You can't archive the videos yourself, and can't change their encoding/format, which is the whole point of what we're doing here. Please, stop using Youtube and just put AVI's on web pages!
  12. Fix the overscan of the Xcalibur decoder chip so you can watch movies with subtitles. (get to work! good luck!)
  13. Toss out all this Linux crap and replace it with FreeBSD or NetBSD which can swap over NFS. That way you can NFS-boot without giving up paged memory, which is needed on this 64MB machine. NFS-booting is a good idea because it will (maybe) stop a scratched DVD from crashing the whole system. I think that's happening now because the disk and DVD-ROM are on the same IDE bus.

Closing thoughts

This was an incredible pain in the ass, and not how I wish to spend my time. I started this because I want to watch movies, but want to get out of the blue-collar Linux PeeCee-ricer business. The whole point of using the XBox was that I hoped it would not require much attention from one year to the next. Not so!

To start with, of course there are the different revisions of XBox, a complete disaster. Then there is the problem of nonstandard DVD-ROM drives: the replacement XBox drives must be bought from shady unprofessional vendors and are expensive or unobtainable, and the original drive wears out over time and is not nearly as good at reading scratched movies as a typical drive. With a regular PeeCee I could buy a standard DVD-ROM instead of having to dremmel/hack/patch/solder one in. And we have the churn of Gentoo itself, and Linux itself---it seems neither me nor the xbox-linux.org people want to keep up with that pain in the ass, as both of us have XBox patches for a very old kernel, and Gentoo has churned ``squashfs'' so my old kernel cannot boot modern LiveCD's. Finally there is the churn of the video formats one downloads on the Internet, particularly from hacker groups like the CCC which obnoxiously jump on the latest experimental codec to shave off a few bits, and deliver movie files that not only are unsupported without the latest ebuilds, but that a 700MHz i386 will never be able to play.

The greatest accomplishment of this work was the ability to NFS-boot. This provides an incredible rescue system, because you can back up your entire working system onto NFS and use a Cromwell menu to toggle between Disk/NFS. That way, you can try new ebuilds on one system. If, suddenly, DVD's start playing skippy and jerky for no comprehensible reason, like happened to me, you can toggle back to the known-good system. Without this type of backup to let one roll back changes, I think Gentoo would be impractical. It's doubly inpractical if you end up with a house full of people wanting to watch movies who can't do so for half a year while you get around to hammering through some rototilled Linux mess.

The second greatest accomplishment was actually getting source for everything, and next documenting how you build/use it. In theory we are using a so-called ``open source'' operating system, and the GPL guarantees I should get a packet containing source code along with every binary thing I get. In practice that doesn't happen. Cromwells are by far the worst offender and warranted a separate rant, but in general it seems like everyone who writes a page like this writes the top-level ordered list only, meaning the part where I say ``cheat and use mine,'' then stops. Shame on you guys for that. Second, the documentation is ``post to my web forum,'' or ``join my irc channel,'' rather than web pages and mailing lists like normal Linux. Delving into these ADHD-wridden gamerz rats' nests full of signon hoops, clumsy PHP, incomplete sentences, and rampant unappologetic censorship is not my favorite thing to do.

I'm really sick of the XBox and hope I can finish the DVD-skipping problem and then don't have to look at it for a long time.


carton's page / map / GentooX GPL Compliance Lab / Miles Nordin <carton@Ivy.NET>
Last update (UTC timezone): $Id: xbox.html,v 1.5 2008/07/01 22:42:24 carton Exp $