[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: PReP support for mkvmlinuz & kernel-image 2.6



Damn,

forgot to attach the files, here they are.

Friendly,

Sven Luther
#!/bin/sh

# usage information
usage() {
    echo 'usage:'
    echo ' -o <output>  - path to output file for compressed kernel image'
    echo ' -a <arch>    - PowerPC sub-architecture'
    echo ' -k <kernel>  - path to kernel image file in ELF format'
    echo ' -s <sysmap>  - path to System.map file'
    echo ' -i <initrd>  - path to initrd image file in uncompressed format'
    echo ' -d <objdir>  - path to directory with additional object files'
    echo ' -r <release> - kernel release number'
    echo ' -z           - assume the initrd image file is already compressed'
    echo ' -q           - quiet operation (do not indicate progress)'
    echo ' -v           - verbose operation (print commands)'

    exit 0
}

# echo a shell command if desired, and execute it
do_cmd() {
    test -z "$verbose" || echo $@; eval $@
    return
}

# parse command line
while getopts o:k:s:i:d:r:a:zqv option; do
    case "$option" in
	o) output=$OPTARG ;;
	k) kernel=$OPTARG ;;
	s) sysmap=$OPTARG ;;
	i) initrd=$OPTARG ;;
	d) objdir=$OPTARG ;;
	r) release=$OPTARG ;;
	a) arch=$OPTARG ;;
	z) compressed="Yes" ;;
	q) quiet="Yes" ;;
	v) verbose="Yes" ;;
	*) usage; exit 0 ;;
    esac
done

# use non-option arguments as release version and kernel image file if needed
shift $((OPTIND-1))
if test -z "$release" -a -n "$1"; then
    release=$1
fi
if test -z "$kernel" -a -n "$2"; then
    kernel=$2
fi

# if no sub-architecture was specified, read it from /proc
if test -z "$arch"; then
    case $(grep ^machine /proc/cpuinfo) in
	*PReP*) arch=prep ;;
	*CHRP*) arch=chrp ;;
	*Amiga) arch=amiga ;;
	*iSeries) arch=iseries ;;
	*)
	    case $(grep ^pmac-generation /proc/cpuinfo) in
		*NewWorld) arch=newworld ;;
		*OldWorld) arch=coff ;;
	    esac
	    ;;
    esac
fi

test -n "$quiet" || echo === Building for sub-architecture $arch.

# if no kernel was specified, try to find one
if test -z "$kernel"; then

    # guess the location of a kernel
    if kernel=/boot/vmlinux-$release; test -n "$release" -a -r $kernel; then
	:
    elif kernel=/vmlinux; test -r $kernel; then
	:
    elif kernel=/boot/vmlinux; test -r $kernel; then
	:
    elif kernel=/boot/vmlinux-$(uname -r); test -r $kernel; then
	:
    else
	kernel=""
    fi

    # we couldn't find a kernel, and therefore give up
    if test -z "$kernel"; then
	echo Could not find a kernel image file, please specify one.
	exit 1
    fi

    # sanitize the location of the kernel
    kernel=$(readlink -f $kernel)

fi

test -n "$quiet" || echo === Using kernel image file $kernel.

# if no initrd was specified, try to find one that goes with the kernel
if test -z "$initrd"; then

    # guess the location of an initrd, but don't try too hard
    if initrd=${kernel/vmlinux/initrd.img}; test -r $initrd; then
	:
    else
	initrd=""
    fi

    # sanitize the location of the initrd
    if test -n "$initrd"; then
	initrd=$(readlink -f $initrd)
    fi

fi

test -n "$quiet" -a -n "$initrd" || echo === Using initrd image file $initrd.

# if no release was specified, extract it from the kernel image name
if test -z "$release"; then
    release=$(echo $kernel | sed s/.*vmlinux-//)
    if echo $release | grep -q '2\.[46]\.[0-9]*'; then
	:
    else
	release=""
    fi
fi

test -n "$quiet" || echo === Release version seems to be $release.

# if no object file directory was specified, try to find one
if test -z "$objdir"; then

    # try a default location first, then use the current directory
    if objdir=/usr/lib/kernel-image-$release; test -d $objdir; then
	:
    else
	objdir=$PWD
    fi
fi

test -n "$quiet" || echo === Using object files from $objdir.

# if no output file was specified, source the configuration file
if test -z "$output" -a -r /etc/mkvmlinuz/output; then
    . /etc/mkvmlinuz/output
fi

# we absolutely need an output file, and won't attempt guesses
if test -z "$output"; then
    echo Please specify an output file.
    exit 1
fi

test -n "$quiet" || echo === Building a bootable compressed kernel image in $output.

# create a work directory
work=$(mktemp -d)

test -n "$quiet" || echo === Doing build in $work.

# utilities
ADDNOTE=$objdir/utils/addnote
HACKOFF=$objdir/utils/hack-coff
MKNOTE=$objdir/utils/mknote
MKPREP=$objdir/utils/mkprep
MKBUGBOOT=$objdir/utils/mkbugboot
LD=ld
OBJCOPY=objcopy

GZIP="--force --best"

# libraries and common object files
libs=$objdir/lib
of_objs=$objdir/obj/openfirmware
simple_objs=$objdir/obj/simple
OBJS="$of_objs/start.o $of_objs/misc.o $of_objs/common.o $of_objs/${arch}main.o"
SIMPLE_OBJS="$simple_objs/head.o $simple_objs/relocate.o $simple_objs/legacy.o $simple_objs/misc.o $simple_objs/misc-prep.o $simple_objs/mpc10x_memory.o"
case $arch in
    prep)
    	dummy=$objdir/obj/simple/dummy.o
	OBJCOPY_ARGS="-O elf32-powerpc"
	LIBS="$libs/common.a $libs/ppc.a $libs/of.a"
    ;;
    coff|inewworld|chrp)
    	dummy=$objdir/obj/openfirmware/dummy.o
	LIBS="$libs/lib.a $libs/ppc.a $libs/of.a $libs/common.a"
    ;;
esac

# off we go...

# create the compressed kernel image file
test -n "$quiet" || echo === Creating compressed kernel image vmlinux.gz...
do_cmd $OBJCOPY -O binary $kernel $work/vmlinux
do_cmd gzip $work/vmlinux

# create the compressed initrd image file
if test -n "$initrd"; then
    test -n "$quiet" || echo === Creating compressed initrd image initrd.gz...
    if test -n "$compressed"; then
	do_cmd cp -p $initrd $work/initrd.gz
    else
	do_cmd cp -p $initrd $work/initrd
	do_cmd gzip $work/initrd
    fi
fi

# create the raw ELF image file
test -n "$quiet" || echo === Putting everything into ELF image file image.o...
do_cmd $OBJCOPY $OBJCOPY_ARGS -R .comment $dummy $work/image.o
do_cmd $OBJCOPY $OBJCOPY_ARGS $work/image.o $work/image.o \
    --add-section=.image=$work/vmlinux.gz \
    --set-section-flags=.image=contents,alloc,load,readonly,data
if test -n "$sysmap"; then
    do_cmd $OBJCOPY $OBJCOPY_ARGS $work/image.o $work/image.o \
	--add-section=.sysmap=$sysmap \
	--set-section-flags=.sysmap=contents,alloc,load,readonly,data
fi
if test -n "$initrd"; then
    do_cmd $OBJCOPY $OBJCOPY_ARGS $work/image.o $work/image.o \
	--add-section=.ramdisk=$work/initrd.gz \
	--set-section-flags=.ramdisk=contents,alloc,load,readonly,data
fi

# link everything into the final image file and make it bootable
vmlinuz=$work/vmlinuz.$arch
LD_ARGS="-T $objdir/boot/ld.script"
OF_LD_ARGS="$LD_ARGS -e _start"
OBJCOPY_ARGS="$OBJCOPY_ARGS -R .comment"
test -n "$quiet" || echo === Creating bootable kernel image file vmlinuz.$arch...
case $arch in
    chrp)
	LD_ARGS="$OF_LD_ARGS -Ttext 0x00800000"
	do_cmd $LD -o $vmlinuz $LD_ARGS $of_objs/crt0.o $OBJS $work/image.o $LIBS
	do_cmd $OBJCOPY $OBJCOPY_ARGS $vmlinuz $vmlinuz
	do_cmd cp -p $objdir/boot/note $work
	do_cmd $ADDNOTE $vmlinuz
	;;
    coff)
	LD_ARGS="$OF_LD_ARGS -Ttext 0x00500000 -Bstatic"
	OBJCOPY_ARGS="-O aixcoff-rs6000 -R .stab -R .stabstr $OBJCOPY_ARGS"
	do_cmd $LD -o $vmlinuz $LD_ARGS $of_objs/coffcrt0.o $OBJS $work/image.o $LIBS
	do_cmd $OBJCOPY $OBJCOPY_ARGS $vmlinuz $vmlinuz
	do_cmd $HACKOFF $vmlinuz
	;;
    newworld)
	LD_ARGS="$OF_LD_ARGS -Ttext 0x01000000"
	OBJCOPY_ARGS="--add-section=.note=$work/note $OBJCOPY_ARGS"
	do_cmd $LD -o $vmlinuz $LD_ARGS $of_objs/crt0.o $OBJS $LIBS $work/image.o
	do_cmd $MKNOTE > $work/note
	do_cmd $OBJCOPY $OBJCOPY_ARGS $vmlinuz $vmlinuz
	;;
    prep)
	# TODO: 0x00800000 should be configurable (set by CONFIG_BOOT_LOADER)
	LD_ARGS="$LD_ARGS -Ttext 0x00800000 -Bstatic"
	OBJCOPY_ARGS="$OBJCOPY_ARGS -R .stab -R .stabstr -R .sysmap"
	do_cmd $LD -o $vmlinuz $LD_ARGS $SIMPLE_OBJS $work/image.o $LIBS
	do_cmd $OBJCOPY $OBJCOPY_ARGS $vmlinuz $vmlinuz
	# TODO: Do we really need MKBUGBOOT ?
	do_cmd $MKBUGBOOT $vmlinuz $vmlinuz.bugboot
	do_cmd $MKPREP -pbp $vmlinuz $vmlinuz
	;;
    *)
	echo Sorry, I do not know how to handle PowerPC sub-architecture $arch.
esac

# move bootable kernel image to its final location
if test -e $vmlinuz; then
    test -n "$quiet" || echo === Moving bootable kernel image file to $output...
    if test -e $output; then
	echo Output file $output exists, attempting to back it up...
	mv $output $output.old 2> /dev/null
    fi
    cat $vmlinuz > $output
fi

# clean up
test -n "$quiet" || echo === Cleaning up...
rm -rf $work
--- mkvmlinuz-6	2004-07-07 11:25:08.000000000 +0200
+++ mkvmlinuz	2004-07-08 13:56:34.898137576 +0200
@@ -162,6 +162,8 @@
 ADDNOTE=$objdir/utils/addnote
 HACKOFF=$objdir/utils/hack-coff
 MKNOTE=$objdir/utils/mknote
+MKPREP=$objdir/utils/mkprep
+MKBUGBOOT=$objdir/utils/mkbugboot
 LD=ld
 OBJCOPY=objcopy
 
@@ -169,9 +171,21 @@
 
 # libraries and common object files
 libs=$objdir/lib
-LIBS="$libs/lib.a $libs/ppc.a $libs/of.a $libs/common.a"
-objs=$objdir/obj
-OBJS="$objs/start.o $objs/misc.o $objs/common.o $objs/${arch}main.o"
+of_objs=$objdir/obj/openfirmware
+simple_objs=$objdir/obj/simple
+OBJS="$of_objs/start.o $of_objs/misc.o $of_objs/common.o $of_objs/${arch}main.o"
+SIMPLE_OBJS="$simple_objs/head.o $simple_objs/relocate.o $simple_objs/legacy.o $simple_objs/misc.o $simple_objs/misc-prep.o $simple_objs/mpc10x_memory.o"
+case $arch in
+    prep)
+    	dummy=$objdir/obj/simple/dummy.o
+	OBJCOPY_ARGS="-O elf32-powerpc"
+	LIBS="$libs/common.a $libs/ppc.a $libs/of.a"
+    ;;
+    coff|inewworld|chrp)
+    	dummy=$objdir/obj/openfirmware/dummy.o
+	LIBS="$libs/lib.a $libs/ppc.a $libs/of.a $libs/common.a"
+    ;;
+esac
 
 # off we go...
 
@@ -193,49 +207,59 @@
 
 # create the raw ELF image file
 test -n "$quiet" || echo === Putting everything into ELF image file image.o...
-do_cmd $OBJCOPY -R .comment $objdir/obj/dummy.o $work/image.o
-do_cmd $OBJCOPY $work/image.o $work/image.o \
+do_cmd $OBJCOPY $OBJCOPY_ARGS -R .comment $dummy $work/image.o
+do_cmd $OBJCOPY $OBJCOPY_ARGS $work/image.o $work/image.o \
     --add-section=.image=$work/vmlinux.gz \
     --set-section-flags=.image=contents,alloc,load,readonly,data
 if test -n "$sysmap"; then
-    do_cmd $OBJCOPY $work/image.o $work/image.o \
+    do_cmd $OBJCOPY $OBJCOPY_ARGS $work/image.o $work/image.o \
 	--add-section=.sysmap=$sysmap \
 	--set-section-flags=.sysmap=contents,alloc,load,readonly,data
 fi
 if test -n "$initrd"; then
-    do_cmd $OBJCOPY $work/image.o $work/image.o \
+    do_cmd $OBJCOPY $OBJCOPY_ARGS $work/image.o $work/image.o \
 	--add-section=.ramdisk=$work/initrd.gz \
 	--set-section-flags=.ramdisk=contents,alloc,load,readonly,data
 fi
 
 # link everything into the final image file and make it bootable
 vmlinuz=$work/vmlinuz.$arch
-LD_ARGS="-T $objdir/boot/ld.script -e _start"
-OBJCOPY_ARGS="-R .comment"
+LD_ARGS="-T $objdir/boot/ld.script"
+OF_LD_ARGS="$LD_ARGS -e _start"
+OBJCOPY_ARGS="$OBJCOPY_ARGS -R .comment"
 test -n "$quiet" || echo === Creating bootable kernel image file vmlinuz.$arch...
 case $arch in
     chrp)
-	LD_ARGS="$LD_ARGS -Ttext 0x00800000"
-	do_cmd $LD -o $vmlinuz $LD_ARGS $objs/crt0.o $OBJS $work/image.o $LIBS
+	LD_ARGS="$OF_LD_ARGS -Ttext 0x00800000"
+	do_cmd $LD -o $vmlinuz $LD_ARGS $of_objs/crt0.o $OBJS $work/image.o $LIBS
 	do_cmd $OBJCOPY $OBJCOPY_ARGS $vmlinuz $vmlinuz
 	do_cmd cp -p $objdir/boot/note $work
 	do_cmd $ADDNOTE $vmlinuz
 	;;
     coff)
-	LD_ARGS="$LD_ARGS -Ttext 0x00500000 -Bstatic"
+	LD_ARGS="$OF_LD_ARGS -Ttext 0x00500000 -Bstatic"
 	OBJCOPY_ARGS="-O aixcoff-rs6000 -R .stab -R .stabstr $OBJCOPY_ARGS"
-	do_cmd $LD -o $vmlinuz $LD_ARGS $objs/coffcrt0.o $OBJS $work/image.o $LIBS
+	do_cmd $LD -o $vmlinuz $LD_ARGS $of_objs/coffcrt0.o $OBJS $work/image.o $LIBS
 	do_cmd $OBJCOPY $OBJCOPY_ARGS $vmlinuz $vmlinuz
 	do_cmd $HACKOFF $vmlinuz
 	;;
     newworld)
-	LD_ARGS="$LD_ARGS -Ttext 0x01000000"
+	LD_ARGS="$OF_LD_ARGS -Ttext 0x01000000"
 	OBJCOPY_ARGS="--add-section=.note=$work/note $OBJCOPY_ARGS"
-	do_cmd $LD -o $vmlinuz $LD_ARGS $objs/crt0.o $OBJS $LIBS $work/image.o
+	do_cmd $LD -o $vmlinuz $LD_ARGS $of_objs/crt0.o $OBJS $LIBS $work/image.o
 	do_cmd $MKNOTE > $work/note
 	do_cmd $OBJCOPY $OBJCOPY_ARGS $vmlinuz $vmlinuz
 	;;
-    #prep)
+    prep)
+	# TODO: 0x00800000 should be configurable (set by CONFIG_BOOT_LOADER)
+	LD_ARGS="$LD_ARGS -Ttext 0x00800000 -Bstatic"
+	OBJCOPY_ARGS="$OBJCOPY_ARGS -R .stab -R .stabstr -R .sysmap"
+	do_cmd $LD -o $vmlinuz $LD_ARGS $SIMPLE_OBJS $work/image.o $LIBS
+	do_cmd $OBJCOPY $OBJCOPY_ARGS $vmlinuz $vmlinuz
+	# TODO: Do we really need MKBUGBOOT ?
+	do_cmd $MKBUGBOOT $vmlinuz $vmlinuz.bugboot
+	do_cmd $MKPREP -pbp $vmlinuz $vmlinuz
+	;;
     *)
 	echo Sorry, I do not know how to handle PowerPC sub-architecture $arch.
 esac

Reply to: