Porting OpenBSD to the Xbox

Introduction and motivation

This page explains my project: OpenBSD on the MS Xbox. If there is any progress, I will publish it here. Since the old Xbox can run Linux (see http://www.xbox-linux.org), several other operating systems have been ported to the Xbox:

  • Linux
  • FreeBSD
  • ReactOS
  • NetBSD
  • Darwin

My name is Markus Ritzer, I study computer science at the technical university of munich where I have to do a system development project (in german: SEP, Systementwicklungsprojekt). I asked Michael Steil, the founder of the Xbox linux project (I used Xbox Linux a lot - so I wanted to give something back), if there is something that could be done for the project that I could also use for the project at university. His idea was to port NetBSD, and I started with that, but since January 2007, there is already a port for the Xbox, and so I switched to OpenBSD. The official beginning of my SEP is April 18th, 2007, and the end is July 18th, 2007.
xboxbanner.jpg
More pictures here

Summary

The project is finished now (the port is not completely finished), and the most important parts are working. The kernel boots, memory gets initialized, there is output on the TV, network is working, the root fs gets mounted, users can log in and work with the system. But there are still things that could be done (see below). I have to do other things now, and I don't have time anymore to continue and completely finish the port. But the inhibition threshold for others who want OpenBSD at the Xbox should be very low now, the most annoying and time wasting problems are solved. I hope somebody will complete the port (please let me know if you plan to do so).
The Xbox isn't supported as an official platform by the OpenBSD developers, a pity.
A big thanks to the NetBSD and FreeBSD Xbox port, I have taken some code from there, and to all the other people that helped me. I have only tested it on a 1.0 Xbox with 128 MB RAM!

Goals of the project

last update: July 6th, 2007

Primary goals:

goal reached comment
memory managementyessize of the kernel is hardcoded; value should be taken from the linker script
framebuffer driveryesneeds to be integrated in the system console
system consoleyesa lot of work!!
mount root file systemyesfrom HDD, device name must be in kernel config
you can login and work with commandlineyes
PCI enumeration bug fixedyescode taken from the NetBSD port
corrected timer frequency yes
reboot and poweroff worksyescode mostly taken from NetBSD
write installation manual and kernel patchyessee below
write a detailed report in PDF and send it to all the helpersyesthis is the report that I need for university; see below

Secondary goals:

goal reached comment
network driveryesI have a nfe0 device. The driver needed a little bit of patching
eject cd button supportnoOn other OS, Xbox crashes when the open CD drive button is pressed, if not handled correctly
switch to OpenBSD -currentyes

Other goals (just in case I have enough time, but these are not important to me):

goal reached comment
X-Serverno (see below)
write an installerno (not planned)
read hardware monitoring sensorsno (not planned)
FATX file system implementationno (not planned)
Audio driver supportyesdriver was already in OpenBSD, I just activated it in the kernel configuration; I tested it, it was working out of the box

Known errors / Things that still need to be done

dmesg problem

When you type dmesg, the message

sysctl: KERN_MFGBUFSIZE: Device not configured

appears. A reason for this could be that kernel and userland are out of sync. The problem is the magic number of the buffer. 0xffffffff is passed, but 0x63061 is expected. So there is no dmesg output.

framebuffer driver lacks ioctl() and mmap()

These two functions are not implemented. They are needed in order to run the X-Server (which suppots framebuffer devices with the wsfb driver).

framebuffer driver lacks scrollback support

You cannot scroll back in the console. The function header scrollback() is in the driver, but, however, it is not implemented.

framebuffer driver lacks screen switching capability

The same is true for Alt+X screen switiching in the console.

reset-on-eject bug handling

Due to the lack of the interrupt handling framework on the SMBus in OpenBSD, there is no possibility to handle this problem (in my opinion).
Details on this problem can be found at:

CD/DVD drive is not found

It seems that the CD/DVD drive is not found or recognized.

Cromwell FFS implementation

Cromwell can't read the kernel from a FFS partition. Add FFS support to Cromwell. There are already the appropriate function headers.
EDIT: There is a patch for Cromwell made my Rink Springer, download it here.
See here on how you use it.

Missing drivers

Write drivers for the eeprom (like NetBSD has one), the gamepad, the temperature sensors and the FATX filesystem of the Xbox.

Write an installer

Write an installer, so it's easier to get OpenBSD on the Xbox. Provide a LiveCD.

Kernel image size

Cromwell should tell the kernel, how big its image is. In other words: the kernel needs to know the address of the first free page of the memory, in order to set up memory management.

Installer / LiveCD

For convenience reasons, there should be an installer to make it easier to get OpenBSD on the Xbox. A LiveCD for quick testing could be provided.

Project Homepage

The content of the project homepage could be transferred into the Xbox-Linux Homepage.

Testing

This port should be tested on all hardware revisions of the Xbox. I tried it only on a 1.0 Xbox with 128 MB RAM. However, the RAM size shouldn't matter.

Video encoder setup

The framebuffer driver should set up the video mode itself and not rely on Cromwell.

userspace tools

A userspace tool to control the LED would be nice.

Chronological log

  1. Idea: July 2006
  2. First time that I touched *BSD,played with NetBSD, compiled kernel, changed kernel
  3. Contacted Michael Steil, he borrowed my one of his Xboxes
  4. Looked at that Xbox, started it, looked for cables
  5. Xbox powered on the first time, it didn't boot
  6. Identified the modchip lying around
  7. Modchip connected
  8. Xbox still didn't boot ⇒ modchip was broken
  9. Michael Steil sent me two modchips and two USB-adapters
  10. New modchip (SmartXX v2) worked, bootet Gentoo-Linux live CD.
  11. Burned cromwell on a DVD; Xbox drive couldn't read CD-ROMs
  12. Flashed Cromwell to one of the modchip banks over the modchip menu
  13. Cromwell booted now
  14. Tried to boot a kernel via TFTP and BOOTP, didn't work
  15. On my other (Linux-)Xbox, I tried to control the front LED from the early linux boot process
  16. Compiled Cromwell; added debug information via printf, analyzed boot process (took me a long time)
  17. Tried to find out where the entry address comes from
  18. Contacted Rink Springer, the porter of FreeBSD
  19. He told me, that since January 4th, 2007, there is already a NetBSD port.
  20. Switched to OpenBSD, installed it on a test computer (i386), compiled own kernel
  21. Made LED blink via a userspace C-program on my Linux-Xbox
  22. Made the LED blink in kernelspace at boot time in boot/compressed/misc.c
  23. Took assembler code from Rink Springer, the porter of FreeBSD, integrated it in head.S, learned assembler
  24. Integrated this LED code into the OpenBSD kernel (locore.S), compiled it, burned it to a DVD, booted it on the test-Xbox, it worked!
  25. Figured out the code trace (what functions calls what) in the OpenBSD kernel, started with locore.S and machdep.c; learned where the kernel panics
  26. This all was done by blinking the LED after each suspicious line; compiling; burning to DVD; booting on the Xbox; watching the LED color
  27. Set up a virtual i386 machine with VMware; no need anymore for my old test PC
  28. Contacted OpenBSD mailinglist
  29. Read something about etherboot, not it works! I can boot kernels via ehternet; I don't need to burn it to DVD anymore; that saves a lot of time
  30. I don't use the first megabytes of RAM at the initialization, now kernel boots until cpu_configure()
  31. Written the foundations of the framebuffer driver
  32. Fixing the PCI enumeration bug; kernel now passes cpu_configure()
  33. Switching to OpenBSD-current because of the new vesafb driver; later switsching back; attach_mainbus crashes and I don't know why
  34. Michael Steil tells me, that I just have to write the top 4 MB of the memory to get output on the TV; video encoder is set up by Cromwell
  35. I have trouble with the memory mapping
  36. I try to change pmap_zero_phys_86() to make something change on the TV; until now, I just have black and white bars. My attempt works, I can display one-colored areas
  37. Tried to cleanly implement the framebuffer driver; BUS_SPACE_MAP_LINEAR and bus_space_vaddr() don't exist on i386!
  38. Found my mistake; XBOX_FB_SIZE had the wrong size, so the pointer to the beginning of the framebuffer memory was wrong; fixed it, now it worked!
  39. With the help of the output_char() of the Darwin port I can now draw characters and strings. This was in April 2007!
  40. Implemented \n handling, standard printf() works; however, the console is not integrated correctly
  41. Created this page about the project, informed everybody I have ever talked to about this project, posted an announcement on Xbox and OpenBSD mailinglists, added a note to www.xbox-linux.org
  42. played around with the nforce ethernet driver, integrated the disabling of the NIC (because Cromwell leaves it running, and so it can't be found by OpenBSD). I have a device icsphy0 now.
  43. tried to mount a root fs via NFS, but it didn't work
  44. tried to change to -current, but there a problems with the pci enumeration bug
  45. Jared McNeill helped me to find the problem; I had overlooked something, now it works! PCI enumeration bug is fixed completely and changing to -current is done
  46. now able to compile in rasops code for the console driver
  47. config_found() and xboxfb_alloc_screen() working
  48. traced the calls of printf()
  49. found the mistake, a wrong setting of the “stride” in the driver, corrected it, got first output of the console (not via my workaround code)
  50. at boot time, the kernel can't find a rootfs. It asks for it. When I enter wd0 it accepts it and mounts the fs. You can login then.
  51. put the name of the HDD in the kernel config, now it gets mounted without asking
  52. nfe driver doesn't seem to work proper, added a flag to the icsphy driver
  53. installed new userland on the HDD, from snapshots
  54. fixed the nfe driver. Taken some lines from the NetBSD driver. Now it works!
  55. integrated PIC16LC support, and poweroff / reboot functions. Non-assembler implementation of the setled()-Function.
  56. tested sound, it works; I was able to play a MP3 file
  57. tried to fix the “reset-on-eject” bug. Don't know how to set up interrupt handlers
  58. Provided a kernel image here, makes it easier to test it
  59. worked on the report; it is now almost complete
  60. report is now complete and downloadable below!
  61. last cleanups in the sourcecode
  62. some more small changes on the homepage
  63. added the end presentation of the project
  64. added Cromwell images and the complete patched OpenBSD source tree
  65. Rink Springer told me that he has a FFS patch for Cromwell; I tried it, it worked. You can boot the kernel from HDD now

last update: July 16th, 2007

How you can try it yourself

There is no one click solution to try OpenBSD yourself. But I can give a detailed step-by-step guide what you have to do in order to make your Xbox boot OpenBSD.

Requirements
  • A MS Xbox (of course connected to a TV)
  • Cromwell/Xromwell 2.41-dev on it; see www.xbox-linux.org for details; I worked with this cromwell image and this one with FFS support.
  • An ethernet link from a pc running a DHCP-Daemon and TFTP or a CD/DVD-Writer
  • If you don't like the the kernel image above and want to compile your own kernel:
    • Knowledge about compiling a kernel under *BSD
    • an OpenBSD installation on a i386 computer to compile the kernel
Step-by-step guide
  1. Test if Cromwell 2.41-dev works on the Xbox
  2. You need a kernel, there are two choices:
    1. download a kernelimage here: openbsd-xbox-kernel-image.gz and gunzip it
    2. build your own from the source:
      1. Get OpenBSD sources from www.openbsd.org, I recommend the -current tree from CVS
      2. compile the kernel
  3. Booting from CD/DVD if you want to burn it to a CD/DVD (careful; Xbox drives have some issues; see www.xbox-linux.org) do so; you can skip the network part below (and continue with 11); you need a file linuxboot.cfg in the root directory of your CD/DVD with the following content:
    kernel isolinux/xbox

    I think that should be enough; isolinux is the directory with the kernel, xbox is the name of the kernel file itself

  4. Booting from the HDD You have to patch Cromwell so that it can read FFS partitions
  5. Booting via ethernet this is the better method; connect your PC with a ethernet cross cable to the Xbox
  6. set up a DHCP server (detailed instructions can be found in this section of the wiki: german.jpg Kernel übers Netzwerk booten)
  7. this my dhcpd.conf DHCP-Server configuration file; 192.168.2.2 is the pc, 192.168.2.1 is the Xbox; also look at the MAC address of your Xbox (I think Cromwell tells you what address your Xbox has)
    allow booting;
    allow bootp;
    
    authoritative;
    ddns-update-style ad-hoc;
    
    subnet 192.168.2.0 netmask 255.255.255.0 {
            range 192.168.2.10 192.168.2.20;
            option subnet-mask 255.255.255.0;
            option broadcast-address 192.168.2.255;
    }
    
    host 192.168.2.1 {
            hardware ethernet 00:50:F2:60:8D:5A;
            fixed-address 192.168.2.1;
            option host-name "xbox-neu";
            option root-path "/xbox";
            next-server 192.168.2.2;
            filename "xbox";
    }

    Be careful with the s. Again, xbox is the filename of the kernel. next-server is the IP address of the TFTP server.

  8. set up the TFTP server, that delivers the kernel. I use xinetd for this; should be installed on every modern linux distribution.
    A part of the file /etx/xinetd.d/tftp:
    service tftp
    {
            socket_type     = dgram
            protocol        = udp
            wait            = yes
            user            = nobody
            group           = nobody
            port            = 69
            server          = /usr/sbin/in.tftpd
            server_args     = /home/markus/xbox-neu/tftpboot
            disable         = no
    }

    server_args is the line with directory holding the kernel file; that means, the kernel file is /home/markus/xbox-neu/tftpboot/xbox
    Note that there are no s in this file.

  9. restart xinetd:
    killall -HUP xinetd
  10. you can test your TFTP server with the commands
    tftp localhost 

    to connect to the server and

    get filename

    to download the file called filename. This should work now.

  11. Start the DHCP server: sudo dhcpd eth0, where eth0 is your network interface
  12. You are ready to boot the kernel on the Xbox
  13. Turn your Xbox on; select Etherboot when booting via network or CD/DVD … well, I think you get it
  14. Your Xbox should boot the brandnew ported OpenBSD kernel now!
  15. To mount the root fs, you must prepare a HDD with an OpenBSD FFS partition on another machine and insert in into the Xbox. The kernel configuration line looks like:
    config bsd root on wd0a swap on wd0b

    I haven't tried using a root fs from NFS, but probably this works also.

  16. If you want to know what already works and what doesn't, have a look above on this page

Pictures

Contact me / participate in the project

  • If you want to contact me, write an email: english.jpg/german.jpg Markus Ritzer, email-markus.jpg

University documents

Here are the documents that I had to write for university.

Links

Thanks to

  • Michael Steil, founder of the Xbox-Linux project; he had the idea for the project and lended me his Xbox.
  • Christian Rehn, Technical University of Munich. He attended the project.
  • David Gwynne, OpenBSD kernel developer; He answers my questions on the OpenBSD kernel.
  • Jared McNeill, he has helped me a lot and did the NetBSD port, from which I have taken some code
  • Rink Springer, the same, he has ported FreeBSD
  • Tobias Schröpf, he owns this server and wiki
  • Rainer Giedat, he has answered me tons of questions
  • Jason Wright, Marco Peereboom, Chris Demetriou, Matthieu Herrb, Miod Vallat: OpenBSD experts
  • Michael “Mickey” Shalayeff - he helped me with console integration
  • Ed Schouten, involved in the FreeBSD port, he had some ideas with the network driver
xbox/porting_openbsd_to_the_xbox.txt · Last modified: 2007/09/12 14:34 by markus
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki