Click here to learn
about this Sponsor:
Home  |  News  |  Articles  |  Forum

  Home arrow Linux For Devices Articles arrow Running Linux on the Sega Dreamcast (Part 3)

Running Linux on the Sega Dreamcast (Part 3)
By Rick Lehrbaum

Rate This Article: Add This Article To:

Building the toolsThe first step in the process of getting Linux running on the Dreamcast is to construct the tools we need, including a cross assembler, linker, compiler, and a C runtime library. In the next section we will use these tools to build the operating system, and a basic shell application that Linux will run at the end of its boot process.

Finally, we'll organize everything into a ramdisk image and burn a CD.

The process is long and involved, but highly instructive.

Building a cross assembler, linker, and bootstrap compiler

We'll start by building a cross assembler and linker, and then a bootstrap compiler: a minimal compiler that can be used to build runtime libraries and operating system kernels, but not generic applications. We can't build a complete compilation environment all at once, because many of the header files needed to do so come from the C runtime library, and don't exist until the runtime library itself is built.

Log in as the root user, and follow the script shown in Figure 2. The first steps in the figure set up some environment variables to save typing later, and to make sure that /usr/local/bin is in the PATH. The source code for the binutils package is decompressed, and then patched with minor changes that make it more specific to the Dreamcast's microprocessor. The binutils package is then configured, compiled and installed; the resulting executables end up in /usr/local/bin, with names like sh4-linux-as and sh4-linux-ld.

The same process is then repeated for the bootstrap compiler, only with slightly different arguments that reflect the fact that we are not building a complete compiler setup yet. The bootstrap compiler's executable is called sh4-linux-gcc, and like the binutils package, is installed in /usr/local/bin.



    # export TARGET=sh4-linux
    # export PREFIX=/usr/local
    # export PATH=${PATH}:${PREFIX}/bin

    # tar xzf binutils-2.11.2.tar.gz
    # patch -p0 < binutils-2.11.2-sh-linux.diff
    # mkdir -p build-binutils && cd build-binutils
    # ../binutils-2.11.2/configure --target=$TARGET \
    --prefix=$PREFIX
    # make all install
    # cd ..

    # tar xzf gcc-3.0.1.tar.gz
    # patch -p0 < gcc-3.0.1-sh-linux.diff
    # mkdir -p build-gcc && cd build-gcc
    # ../gcc-3.0.1/configure \
    --target=$TARGET --prefix=$PREFIX \
    --without-headers --with-newlib \
    --disable-shared --enable-languages=c
    # make all-gcc install-gcc
    # cd ..
Figure 2: Commands to build binutils and a bootstrap gcc


Configure the kernel sources

The next step in the toolchain construction process is to configure Linux kernel header files so that the runtime library's build process can extract important bits of information from them during its build process. The idea is to run the equivalent of the configure command on the kernel source code, which you accomplish by using the procedure is shown in Figure 3. Run these commands as they appear in the figure, but don't change any of the settings in the menu that appears: the kernel is already properly configured. Simply exit menuconfig by selecting Exit with the right arrow key on your keyboard, then press ENTER.



    # tar xzf kernel-sh-linux-dreamcast.tar.gz
    # patch -p0 < kernel-sh-linux-dreamcast.diff
    # cd kernel
    # make ARCH=sh CROSS_COMPILE=sh4-linux- menuconfig
    # cd ..
Figure 3: Configuring the kernel sources.


In the instructions, the trailing dash at the end of CROSS_COMPILE is not a mistake: the CROSS_COMPILE macro is used as a prefix for the tools invoked by make; without the dash at the end, the macro won't work.

Building a runtime library

Now that we have a bootstrap compiler and properly-configured kernel, we can build a runtime library environment and header files. The runtime library we will use is GNU's glibc; this library includes familiar functions like printf(), but it also includes the dynamic linker (Linux's equivalent of Win32's DLLs) and several other programs. We can get by without these programs, however, so the steps needed to set them up will be the subject of a future article.

The procedure for building glibc is shown in Figure 4. The first commands uncompress and patch the library, then copy the Linux kernel header files into their proper locations. In contrast to the previous procedures, we actually invoke make twice when building glibc: the first invocation builds the library, but does not install it; the second step installs the library, specifying in detail the installation locations of the library's various components.

In the interest of saving some time, the touch command used between the two make invocations tricks glibc into thinking it has properly built several programs that we don't need. And finally, the echo command writes a linker command file called libc.so without path information, which (perhaps nonintuitively) enables the compiler to properly locate the installed libraries.

If you rebooted your computer or logged out since you built binutils and the bootstrap gcc, you will need to restore the values of PATH, TARGET and PREFIX to the values used in previous steps before building glibc.

Glibc is a substantial, complicated body of code, and you will notice that it takes a long time to build even on fairly powerful hardware. After you get the process going, this would be a good time to take a break.



    # tar xzf glibc-2.2.4.tar.gz
    # patch -p0 < glibc-2.2.4-sh-linux.diff
    # mkdir -p build-glibc && cd build-glibc

    # mkdir -p ${PREFIX}/${TARGET}/include
    # cp -r ../kernel/include/linux \
    ${PREFIX}/${TARGET}/include
    # cp -r ../kernel/include/asm-sh \
    ${PREFIX}/${TARGET}/include/asm

    # CC=sh4-linux-gcc ../glibc-2.2.4/configure \
    --host=$TARGET --prefix=$PREFIX \
    --disable-debug --disable-profile \
    --disable-sanity-checks \
    --with-headers=${PREFIX}/${TARGET}/include

    # make
    # touch iconv/iconv_prog login/pt_chown
    # make install_root=${PREFIX}/${TARGET} \
    prefix="" install
    # echo "GROUP ( libc.so.6 libc_nonshared.a )" \
    > ${PREFIX}/${TARGET}/lib/libc.so
    # cd ..
Figure 4: Instructions to build glibc


Rebuild the cross compiler

With properly installed header files and a runtime library, we can now build a complete c/c++ cross compiler. The commands to do so are in Figure 5. We are reusing the source tree from the bootstrap compiler, so we skip the familiar untar-plus-patch steps.



    # mkdir -p build-gcc2 && cd build-gcc2
    # ../gcc-3.0.1/configure --target=$TARGET \
    --prefix=$PREFIX --enable-languages=c,c++
    # make all install
    # cd ..
Figure 5: Instructions to build the complete cross compiler


--- Continued ---



Story navigation . . .



Discuss Running Linux on the Sega Dreamcast (Part 3)
 
>>> Be the FIRST to comment on this article!
 
 
 
>>> More Linux For Devices Articles Articles          >>> More By Rick Lehrbaum
 



FUEL Database on MontaVista Linux
Whether building a mobile handset, a car navigation system, a package tracking device, or a home entertainment console, developers need capable software systems, including an operating system, development tools, and supporting libraries, to gain maximum benefit from their hardware platform and to meet aggressive time-to-market goals.

Breaking New Ground: The Evolution of Linux Clustering
With a platform comprising a complete Linux distribution, enhanced for clustering, and tailored for HPC, Penguin Computing¿s Scyld Software provides the building blocks for organizations from enterprises to workgroups to deploy, manage, and maintain Linux clusters, regardless of their size.

Data Monitoring with NightStar LX
Unlike ordinary debuggers, NightStar LX doesn¿t leave you stranded in the dark. It¿s more than just a debugger, it¿s a whole suite of integrated diagnostic tools designed for time-critical Linux applications to reduce test time, increase productivity and lower costs. You can debug, monitor, analyze and tune with minimal intrusion, so you see real execution behavior. And that¿s positively illuminating.

Virtualizing Service Provider Networks with Vyatta
This paper highlights Vyatta's unique ability to virtualize networking functions using Vyatta's secure routing software in service provider environments.

High Availability Messaging Solution Using AXIGEN, Heartbeat and DRBD
This white paper discusses a high-availability messaging solution relying on the AXIGEN Mail Server, Heartbeat and DRBD. Solution architecture and implementation, as well as benefits of using AXIGEN for this setup are all presented in detail.

Understanding the Financial Benefits of Open Source
Will open source pay off? Open source is becoming standard within enterprises, often because of cost savings. Find out how much of a financial impact it can have on your organization. Get this methodology and calculator now, compliments of JBoss.

Embedded Hardware and OS Technology Empower PC-Based Platforms
The modern embedded computer is the jack of all trades appearing in many forms.

Data Management for Real-Time Distributed Systems
This paper provides an overview of the network-centric computing model, data distribution services, and distributed data management. It then describes how the SkyBoard integration and synchronization service, coupled with an implementation of the OMG¿s Data Distribution Service (DDS) standard, can be used to create an efficient data distribution, storage, and retrieval system.

7 Advantages of D2D Backup
For decades, tape has been the backup medium of choice. But, now, disk-to-disk (D2D) backup is gaining in favor. Learn why you should make the move in this whitepaper.

Got a HOT tip?   please tell us!
Free weekly newsletter
Enter your email...
PLATINUM SPONSORS

 


ADVERTISEMENT


Check out the latest Linux powered...

Mobile phones!

MIDs, UMPCs
& tablets

Mobile devices

Other cool
gadgets

Resource Library

• Unix, Linux Uptime and Reliability Increase: Patch Management Woes Plague Windows Yankee Group survey finds IBM AIX Unix is highest in ...
• Scalable, Fault-Tolerant NAS for Oracle - The Next Generation For several years NAS has been evolving as a storage ...
• Managing Software Intellectual Property in an Open Source World This whitepaper draws on the experiences of the Black Duck ...
• Open Source Security Myths Dispelled Is it risky to trust mission-critical infrastructure to open source ...
• Bringing IT Operations Management to Open Source & Beyond Download this IDC analyst report to learn how open source ...




Most popular stories -- past 90 days:
· Linux boots in 2.97 seconds
· Tiniest Linux system, yet?
· Linux powers "cloud" gaming console
· Report: T-Mobile sells out first 1.5 million G1s
· Open set-top box ships
· E17 adapted to Linux devices, demo'd on Treo650
· Android debuts
· First ALP Linux smartphone?
· Cortex-A8 gaming handheld runs Linux
· Ubuntu announces ARM port


DesktopLinux headlines:
· Simulator runs Android apps on Ubuntu
· Hypervisor rev'd for higher reliability
· Pluggable NAS now supports Linux desktops
· Moblin v2 beta targets netbooks
· Linux-ready netbook touted as "Student rugged"
· USB display technology heading for Linux
· Ubuntu One takes baby step to the cloud
· Game over for Linux netbooks?
· Linux Foundation relaunches Linux web site
· Dell spins lower-cost netbook


Also visit our sister site:


Sign up for LinuxForDevices.com's...

news feed


Or, follow us on Twitter...