ppcrcd/trunk: Makefile fill_conf.pl mkvmlinuz
sparky
cvs at pld-linux.org
Mon Jan 9 21:54:18 CET 2006
Author: sparky
Date: Mon Jan 9 21:54:13 2006
New Revision: 6783
Added:
ppcrcd/trunk/fill_conf.pl (contents, props changed)
ppcrcd/trunk/mkvmlinuz (contents, props changed)
Modified:
ppcrcd/trunk/Makefile
Log:
- mkvmlinuz: stripped and a little changed script for preparing bootable
ppc kernel image
- fill_conf.pl: script filling yaboot configuration
- Makefile: prepare vmlinuz - chrp-bootable image with initrd;
ppcrcd will work on pegasos 2 soon !!!
Modified: ppcrcd/trunk/Makefile
==============================================================================
--- ppcrcd/trunk/Makefile (original)
+++ ppcrcd/trunk/Makefile Mon Jan 9 21:54:13 2006
@@ -25,6 +25,8 @@
root_stripped = out/root/stripped
touch = out/touch
initrd_sqf = out/images/initrd.sqf
+vmlinuz = out/images/vmlinuz
+vmlinux = out/images/vmlinux
root_initrd = out/root/initrd
root_installed = out/root/installed
root_inst = out/root/inst
@@ -72,6 +74,8 @@
$(SU) /usr/sbin/mksquashfs_lzma \
$(root_initrd) \
$@
+ $(SU) chown $$USER $@
+ touch $@
$(root_initrd): out/touch/root_installed initrd.dir
rm -rf $@{,.work}
@@ -106,23 +110,39 @@
$(@:out/touch/stop/%=%) off
sleep 1 && touch $@
-$(boot): out/touch/root_installed $(initrd_sqf) yaboot/yaboot boot.dir
+$(boot): out/touch/root_installed $(vmlinuz) yaboot/yaboot \
+ yaboot/yaboot boot.dir
rm -rf $@{,.work}
mkdir -p $@.work
- cp boot.dir/{hfs.map,boot.msg{,.net},yaboot.conf{,.net},*.help} $@.work
+ cp boot.dir/{hfs.map,boot.msg{,.net},*.help} $@.work
+ $(PWD)/fill_conf.pl $(vmlinuz) out/images/vmlinux.bin{.gz,} $(initrd_sqf) \
+ boot.dir/yaboot.conf.in > $@.work/yaboot.conf
+ $(PWD)/fill_conf.pl $(vmlinuz) out/images/vmlinux.bin{.gz,} $(initrd_sqf) \
+ boot.dir/yaboot.conf.net.in > $@.work/yaboot.conf.net
rm -f $@.work/*~
sed -e 's/"@_VERSION_@"/$(VER13)/g' \
-i $@.work/boot.msg \
-i $@.work/boot.msg.net
- cp out/root/inst/boot/vmlinux-* $@.work/vmlinux
- strip $@.work/vmlinux
- strip -R.comment $@.work/vmlinux
- gzip -9 $@.work/vmlinux
+ cp $(vmlinuz) $@.work
cp yaboot/yaboot $@.work
cp -a bootinfo.txt $@.work/ofboot.b
- $(SU) cp $(initrd_sqf) $@.work
mv $@{.work,}
+$(vmlinuz): $(vmlinux) $(initrd_sqf) \
+ out/rpm/rpms/kernel-grsecurity-libs
+ -$(SU) rpm --erase kernel-grsecurity-libs --nodeps
+ -$(SU) rpm -Uhv `cat out/rpm/rpms/kernel-grsecurity-libs` --nodeps
+ $(PWD)/mkvmlinuz $@ \
+ -v $(vmlinux) \
+ -i $(initrd_sqf) \
+ -l /boot/libs-* -V
+
+$(vmlinux): out/touch/root_installed
+ $(SU) cp out/root/inst/boot/vmlinux-* $@
+ $(SU) chown $$USER $@
+ strip $@
+ strip -R.comment $@
+
$(root_stripped): out/touch/root_installed conf.dir doc
$(SU) rm -rf $@{,.work}
#
@@ -252,7 +272,7 @@
$(SU) rm -rf $(root_stripped) $(boot) $(root_initrd)
clean-img:
- rm -rf $(ppcrcd_iso) $(ppcrcd_sqf) $(initrd_sqf) $(cdroot)
+ rm -rf $(ppcrcd_iso) $(ppcrcd_sqf) $(initrd_sqf) $(cdroot) out/images/*
clean-yaboot:
make -C yaboot clean
@@ -260,5 +280,6 @@
# don't delete anything
.SECONDARY:
-.DELETE_ON_ERROR: $(ppcrcd_iso) $(ppcrcd_sqf) $(initrd_sqf)
+.DELETE_ON_ERROR: $(ppcrcd_iso) $(ppcrcd_sqf) $(initrd_sqf) \
+ $(vmlinuz) $(vmlinux)
Added: ppcrcd/trunk/fill_conf.pl
==============================================================================
--- (empty file)
+++ ppcrcd/trunk/fill_conf.pl Mon Jan 9 21:54:13 2006
@@ -0,0 +1,43 @@
+#!/usr/bin/perl -w
+#
+# fill configuration info
+#
+# usage: fill_conf.pl <zImage> <vmlinux.bin.gz> <vmlinux> <initrd>
+#
+use strict;
+use warnings;
+
+my $image = shift @ARGV or die;
+my $vmlinux_gz = shift @ARGV or die;
+my $vmlinux = shift @ARGV or die;
+my $initrd = shift @ARGV or die;
+
+
+open F_IN, $image or die;
+binmode F_IN;
+local $/ = undef;
+my $file = <F_IN>;
+close F_IN;
+
+sub sect_start {
+ open F_IN, $_[0] or die;
+ binmode F_IN;
+ local $/ = undef;
+ my $string = <F_IN>;
+ close F_IN;
+ return index $file, $string;
+}
+
+my $vm_beg = sect_start($vmlinux_gz);
+my $rd_beg = sect_start($initrd);
+
+my $vm_len = (stat($vmlinux))[7];
+my $rd_len = (stat($initrd))[7];
+
+while (<>) {
+ s/#KERNEL_BEGIN#/$vm_beg/go;
+ s/#KERNEL_SIZE#/$vm_len/go;
+ s/#INITRD_BEGIN#/$rd_beg/go;
+ s/#INITRD_SIZE#/$rd_len/go;
+ print $_;
+}
Added: ppcrcd/trunk/mkvmlinuz
==============================================================================
--- (empty file)
+++ ppcrcd/trunk/mkvmlinuz Mon Jan 9 21:54:13 2006
@@ -0,0 +1,214 @@
+#!/bin/sh
+
+# $Id: mkvmlinuz,v 1.2 2005/10/21 15:11:49 sparky Exp $
+# mkvmlinuz for pld linux
+#
+# based on mkvmlinuz from Debian and Linux kernel Makefiles
+
+
+# usage information
+usage() {
+ cat << EOF
+usage: $(basename $0) [options] <output-image> <kernel-version>
+(ex: $(basename $0) /boot/zImage-2.6.13.3-1.pmac 2.6.13.3-1)
+
+<output-image> - path to output file for compressed kernel image
+<kernel-version> - kernel version-release
+
+options:
+ -v <kernel> - path to vmlinux kernel
+ default: /boot/vmlinux-<kernel-version>
+ -i <initrd> - path to initrd image file
+ default: /boot/initrd-<kernel-version>[.gz]
+ geninitrd will be executed if no initrd file and not specified
+ -l <libdir> - path to directory with kernel libraries
+ default: /boot/libs-<kernel-version>/
+ -kb - specify if using kernel build directory as <libdir>
+ -n - do not use an initrd
+ -f - force
+ -V - verbose operation
+ -D - debug (set -x)
+
+EOF
+
+exit
+}
+
+error() {
+ MSG="$*"
+ echo "$(basename $0): ERROR: ${MSG#$1 }" >&2
+ exit $1
+}
+
+err() {
+ cd /
+ rm -rf $workdir
+ echo "ERROR: Some error has ocurred"
+ exit $(($1+30))
+}
+
+. /etc/rc.d/init.d/functions
+if [ -r /etc/sysconfig/mkvmlinuz ] ; then
+ . /etc/sysconfig/mkvmlinuz
+fi
+
+is_yes "$DEBUG" && set -x
+
+output=
+version=
+
+# parse command line
+while [ -n "$1" ]; do
+ case "$1" in
+ -v|--vmlinux)
+ shift
+ vmlinux=$1
+ ;;
+ -i|--initrd)
+ shift
+ initrd=$1
+ ;;
+ -l|--libdir)
+ shift
+ libdir=$1
+ ;;
+ -kb|--kb)
+ libdirsuf="/arch/ppc/boot"
+ kernellib="../../../lib/lib.a"
+ ;;
+ -n|--noinitrd)
+ initrd="no"
+ ;;
+ -f|--force)
+ force="yes"
+ ;;
+ -V|--verbose)
+ verbose="yes"
+ ;;
+ -D|--debug)
+ DEBUG="yes"
+ ;;
+ -*)
+ usage
+ ;;
+ *)
+ if [ -z "$output" ]; then
+ output=$1
+ else
+ usage
+ fi
+ ;;
+ esac
+ shift
+done
+[ -n "$libdir" ] && libdir="$libdir$libdirsuf"
+
+is_yes "$DEBUG" && set -x
+
+# check everything
+if [ -e "$output" ]; then
+ is_yes "$force" || error 1 "$output exists"
+fi
+
+is_yes "$verbose" && echo "=== Preparing kernel version $version."
+
+is_yes "$verbose" && echo "=== Building for sub-architecture chrp."
+
+# if no kernel was specified, try to find one
+[ -z "$vmlinux" ] && vmlinux=/boot/vmlinux-$version
+[ -r "$vmlinux" ] || error 3 "vmlinux \`$vmlinux' is not readable"
+is_yes "$verbose" && echo "=== Using kernel image file $vmlinux."
+
+[ -r "$initrd" ] || error 4 "initrd \`$initrd\' is not readable"
+is_yes "$verbose" && echo "=== Using initrd image file $initrd."
+
+# if no object file directory was specified, try to find one
+[ -z "$libdir" ] && libdir=/boot/libs-$version
+[ -r "$libdir" ] || error 5 "libdir \`$libdir' is not readable"
+is_yes "$verbose" && echo "=== Using object files from $libdir."
+
+is_yes "$verbose" && \
+ echo "=== Building a bootable compressed kernel image in $output."
+
+CROSSPPC=
+[ "$(uname -m)" = "ppc" ] || CROSSPPC="ppc-pld-linux-"
+
+# utilities
+[ -z "$ADDNOTE" ] && ADDNOTE=$libdir/utils/addnote
+[ -z "$HACKCOFF" ] && HACKCOFF=$libdir/utils/hack-coff
+[ -z "$MKNOTE" ] && MKNOTE=$libdir/utils/mknote
+[ -z "$MKPREP" ] && MKPREP=$libdir/utils/mkprep
+[ -z "$MKBUGBOOT" ] && MKBUGBOOT=$libdir/utils/mkbugboot
+
+[ -z "$LD" ] && LD=${CROSSPPC}ld
+[ -z "$OBJCOPY" ] && OBJCOPY=${CROSSPPC}objcopy
+
+# libraries and common object files
+OFCOMMONOBJS="start.o,misc.o,common.o"
+[ -z "$kernellib" ] && kernellib=kernel/lib.a
+LIBS=$(echo $libdir/{$kernellib,lib/lib.a,of1275/lib.a,common/lib.a})
+
+OBJS=$(echo $libdir/openfirmware/{crt0.o,$OFCOMMONOBJS,chrpmain.o})
+dummy=$libdir/openfirmware/dummy.o
+
+# create a work directory
+workdir="$(mktemp -d "/tmp/$(basename $0)-XXXXXX")"
+[ -z "$workdir" ] && error 7 "work directory not created"
+
+# off we go...
+GZIP_FLAGS="--force --best"
+
+# create the compressed kernel image file
+is_yes "$verbose" && echo "=== Creating compressed kernel image vmlinux.bin.gz..."
+$OBJCOPY -O binary $vmlinux $workdir/vmlinux.bin
+cp $workdir/vmlinux.bin out/images/vmlinux.bin
+gzip $GZIP_FLAGS $workdir/vmlinux.bin
+cp $workdir/vmlinux.bin.gz out/images/vmlinux.bin.gz
+
+cat "$initrd" > $workdir/initrd
+
+
+RMSECT=
+
+is_yes "$verbose" && echo "=== Putting everything into ELF image file image.o..."
+$OBJCOPY -O elf32-powerpc -R .comment $dummy $workdir/image.o
+$OBJCOPY -O elf32-powerpc $workdir/image.o $workdir/image.o \
+ --add-section=.image=$workdir/vmlinux.bin.gz \
+ --set-section-flags=.image=contents,alloc,load,readonly,data
+
+$OBJCOPY -O elf32-powerpc $workdir/image.o $workdir/image.o \
+ --add-section=.ramdisk=$workdir/initrd \
+ --set-section-flags=.ramdisk=contents,alloc,load,readonly,data
+
+# link everything into the final image file and make it bootable
+zImage=$workdir/zImage.chrp
+LD_ARGS="-T $libdir/ld.script"
+OBJCOPY_ARGS="-R .comment"
+is_yes "$verbose" && echo "=== Creating bootable kernel image file zImage.chrp..."
+
+LD_ARGS="$LD_ARGS -e _start -Ttext 0x00800000"
+
+$LD $LD_ARGS -o $zImage $OBJS $workdir/image.o $LIBS || err $?
+$OBJCOPY $OBJCOPY_ARGS $zImage $zImage || err $?
+# shouldn't be done only for rs6k ?
+# workaround: ADDNOTE=echo mkvmlinux [args]
+$ADDNOTE $zImage
+
+# move bootable kernel image to its final location
+if [ -r "$zImage" ]; then
+ is_yes "$verbose" && echo "=== Moving bootable kernel image file to $output..."
+ cat $zImage > $output && \
+ echo "*** kernel saved in $output succesfully ***" || \
+ err 21
+ ERROR=0
+else
+ err 30
+fi
+
+# clean up
+is_yes "$verbose" && echo "=== Cleaning up..."
+rm -rf $workdir
+
+exit $ERROR
+
+# vi:syntax=sh:ts=4:sw=4
More information about the pld-cvs-commit
mailing list