Table of Contents

Build the Linux Kernel

This procedure was develped under Ubuntu Dapper, but it is believed to work on most Linux distributions.

To build a new kernel, source for the kernel and build tools needs to be obtained. These sources are available from a number of places. The sources for the individual packages are available from ftp://ftp.dlink.com/GPL/DSM-G600_reB/ . The sources are also available at http://tsd.dlink.com.tw/GPL.asp as a single file containing all the released sources, though you need do a little navigation to get them.

If getting the individual sources, you need ppclinux.tar.gz, u-boot.tar.gz and uclibc-toolchain-src-20040609.tar.gz.

Build Toolchain

The Linux 2.4.21-pre4 kernel provided by D-Link requires gcc version 2.95 as opposed to the gcc version 3.x used by the rest of the system, so even if you have built the toolchain for building utilities you will need to build gcc2.95.

In the directory containing the source tarfiles:

tar xzvf uclibc-toolchain-src-20040609.tar.gz
cd uclibc-toolchain-src-20040609/gcc-2.95

Apply the patch:

--- gcc-2.95/Makefile.orig	2006-12-03 19:24:12.000000000 -0800
+++ gcc-2.95/Makefile	2006-12-03 19:26:00.000000000 -0800
@@ -28,11 +28,11 @@
 
 
 # What sortof target system shall we compile this for?
-ARCH:=i386
+#ARCH:=i386
 #ARCH:=arm
 #ARCH:=mips
 #ARCH:=mipsel
-#ARCH:=powerpc
+ARCH:=powerpc
 #ARCH:=sh4
 #ARCH:=cris
 #ARCH:=sh64
@@ -44,7 +44,7 @@
 # Enable this to use the uClibc daily snapshot instead of a released
 # version.  Daily snapshots may contain new features and bugfixes. Or
 # they may not even compile at all, depending on what Erik is doing...
-USE_UCLIBC_SNAPSHOT:=true
+USE_UCLIBC_SNAPSHOT:=false
 
 # Enable large file (files > 2 GB) support
 BUILD_WITH_LARGEFILE:=true
--- gcc-2.95/make/gcc-uclibc-2.95.mk.orig	2004-06-05 18:33:39.000000000 -0700
+++ gcc-2.95/make/gcc-uclibc-2.95.mk	2006-12-03 20:22:01.000000000 -0800
@@ -58,6 +58,7 @@
 	$(SOURCE_DIR)/patch-kernel.sh $(GCC_DIR) $(SOURCE_DIR) gcc2.95-mega.patch.bz2
 	$(SOURCE_DIR)/patch-kernel.sh $(GCC_DIR) $(SOURCE_DIR) gcc2.95-uclibc-conf.patch
 	#$(SOURCE_DIR)/patch-kernel.sh $(GCC_DIR) $(SOURCE_DIR) gcc-uclibc2_95*.patch
+	$(SOURCE_DIR)/patch-kernel.sh $(GCC_DIR) $(SOURCE_DIR) gcc2.95-uclibc-unistd.patch
 	#
 	# We do not wish to build the libstdc++ library provided with gcc,
 	# since it doesn't seem to work at all with uClibc plus gcc 2.95...
@@ -82,7 +83,7 @@
 		--target=$(REAL_GNU_TARGET_NAME) \
 		--enable-languages=c \
 		--disable-shared \
-		--includedir=$(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/include \
+		--includedir=$(STAGING_DIR)/$(TOOL_BUILD_DIR)/uClibc_dev/usr/include \
 		--with-headers \
 		--disable-__cxa_atexit \
 		--enable-target-optspace \
--- gcc-2.95/make/kernel-headers.mk.orig	2004-06-05 18:33:39.000000000 -0700
+++ gcc-2.95/make/kernel-headers.mk	2006-12-03 19:27:05.000000000 -0800
@@ -9,7 +9,7 @@
 ifneq ($(filter $(TARGETS),kernel-headers),)
 
-LINUX_SITE:=http://www.uclibc.org/downloads/toolchain
+LINUX_SITE:=http://www.uclibc.org/downloads/old-releases/toolchain/
-LINUX_SOURCE:=kernel-headers-2.4.21.tar.bz2
+LINUX_SOURCE:=kernel-headers-2.4.25.tar.bz2
 LINUX_DIR:=$(TOOL_BUILD_DIR)/linux

# Used by pcmcia-cs and others

Cut and past the following patch and place it into the file sources/gcc2.95-uclibc-unistd.patch

--- gcc-20011006/gcc/libgcc2.c.orig	1999-06-10 20:11:43.000000000 -0700
+++ gcc-20011006/gcc/libgcc2.c	2006-12-03 17:30:13.000000000 -0800
@@ -36,6 +36,14 @@
    needing header files first.  */
 /* ??? This is not a good solution, since prototypes may be required in
    some cases for correct code.  See also frame.c.  */
+
+/* In a cross-compilation situation, default to inhibiting compilation
+   of routines that use libc.  */
+
+#if defined(CROSS_COMPILE) && !defined(inhibit_libc)
+#define inhibit_libc
+#endif
+
 #ifndef inhibit_libc
 /* fixproto guarantees these system headers exist. */
 #include <stdlib.h>
@@ -57,13 +65,6 @@
 #define WEAK_ALIAS
 #endif
 
-/* In a cross-compilation situation, default to inhibiting compilation
-   of routines that use libc.  */
-
-#if defined(CROSS_COMPILE) && !defined(inhibit_libc)
-#define inhibit_libc
-#endif
-
 /* Permit the tm.h file to select the endianness to use just for this
    file.  This is used when the endianness is determined when the
    compiler is run.  */
--- gcc-20011006/gcc/frame.c.orig	2001-01-25 11:39:43.000000000 -0800
+++ gcc-20011006/gcc/frame.c	2006-12-03 17:33:06.000000000 -0800
@@ -37,6 +37,11 @@
    needing header files first.  */
 /* ??? This is not a good solution, since prototypes may be required in
    some cases for correct code.  See also libgcc2.c.  */
+
+#if defined(CROSS_COMPILE) && !defined(inhibit_libc)
+#define inhibit_libc
+#endif
+
 #ifndef inhibit_libc
 /* fixproto guarantees these system headers exist. */
 #include <stdlib.h>

run

make

if successful

mkdir -p /opt/uclibc-powerpc/; cp -r toolchain_powerpc /opt/uclibc-powerpc/gcc-2.95

Build mkimage

Add the correct compiler to your path, if you are not sure whether you have already done so execute the following command:

powerpc-linux-uclibc-gcc --version

this should print “2.95.4” if the correct compiler is in your path. If it prints some number that does not begin with 2.95 you will need to figure out how to remove the extra dircetory from your path, if it prints “command not found” run:

export PATH=$PATH:/opt/uclibc-powerpc/gcc-2.95/bin

Next in the directory containing the source tarfiles:

tar xzvf u-boot.tar.gz
cd u-boot;make distclean;rm -f include/bmp_logo.h

Apply the following patch:

--- tools/Makefile.orig 2005-04-10 19:52:11.000000000 -0700
+++ tools/Makefile      2006-12-05 20:01:06.000000000 -0800
@@ -79,7 +79,6 @@
 # Everyone else
 #
 else
-TOOLSUBDIRS+= gdb
 HOST_CFLAGS = -Wall -pedantic
 HOST_LDFLAGS =
 HOST_ENVIRO_CFLAGS =

Then:

make Sandpoint8245_config;make all
cp tools/mkimage /opt/uclibc-powerpc/gcc-2.95/bin/

Kernel Build

Verify your path, execute the following command:

powerpc-linux-uclibc-gcc --version

this should print “2.95.4” if the correct compiler is in your path. If it prints some number that does not begin with 2.95 you will need to figure out how to remove the extra directory from your path, if it prints “command not found” run:

export PATH=$PATH:/opt/uclibc-powerpc/gcc-2.95/bin

Make sure that the directory /tftpboot exists and is writeable, then in the directory containing the source tarfiles:

tar zxvf ppclinux.tar.gz;cd ppclinux

Run the D-Link provided script

./cv.sh

And Build the kernel

make oldconfig;make clean;make dep;make pImage

At this point, there should be a file named pImage in the directory /tftpboot, this is a u-boot-able kernel image.

For a loader.o loadable kernel, the build procedure is slightly different. First, check How to install a root file system to a Hard Disk for some additional kernel patches. Then,

make oldconfig;make clean;make dep;make
powerpc-linux-objcopy -O binary vmlinux

The file 'vmlinux' in the kernel build directory is your loader.o-able kernel.

You could also build the modules, because the default .config specifies modular USB support among other items:

make modules
make modules_install INSTALL_MOD_PATH=/tftpboot

The installation command will “fail” because it will attempt to use your buildhost's 'depmod' utility to construct a modules.dep file. However, the modules themselves will be installed into /tftpboot/lib/modules/2.4.21-pre4/. Also, do not be surprised that the default .config builds several inappropriate wireless drivers (orinoco, hermes): these can't be used by the dsmg600 (unless you happen to have a miniPCI card supported by those drivers, and swap out the shipped Ralink RT2560).


Related Forum Threads

http://dns323.kood.org/forum/t46-linux-kernel.html