From 7b8235ae1b3e304486f7f2cc4fc0681049bf50ad Mon Sep 17 00:00:00 2001 From: "Eric W. Biederman" Date: Wed, 28 Aug 2002 20:07:10 +0000 Subject: [PATCH] Update to mkelfImage-1.15 --- util/mkelfImage/Makefile | 119 ++++++++++++++------ util/mkelfImage/News | 73 +++++++++++- util/mkelfImage/elf32-i386/convert_params.c | 2 +- util/mkelfImage/elf32-i386/head.S | 15 ++- util/mkelfImage/mkelfImage.pl | 30 +++-- 5 files changed, 185 insertions(+), 54 deletions(-) diff --git a/util/mkelfImage/Makefile b/util/mkelfImage/Makefile index cf00f91f9c..67c3a90f93 100644 --- a/util/mkelfImage/Makefile +++ b/util/mkelfImage/Makefile @@ -1,53 +1,100 @@ -# To run this: -# Put the name of a directory in PREFIX where you want to run this stuff. -# make sure that this name is OUTSIDE THE LINUXBIOS TREE -# that way it survives across cvs updates. -# Then do a 'make install' -# the result will be a directory tree that you can run mkelfImage in -#PREFIX=/usr/local/ -#PREFIX= /users/rminnich/src/bios/mkelf2 -PERLPATH=/usr/bin/perl -VERSION="1.14" -DATE="28 June 2002" +include Makefile.conf +VERSION:=1.15 +RELEASE_DATE:=23 August 2002 +PACKAGE:=mkelfImage -SHAREDIR=$(PREFIX)/share/mkelfImage -BINDIR=$(PREFIX)/bin -MANDIR=$(PREFIX)/man/man1 +# You can specify DESTDIR on the command line to do a add +# a prefix to the install so it doesn't really happen +# Useful for building binary packages +DESTDIR = -DIRS=$(SHAREDIR) $(BINDIR) $(MANDIR) +pkgdatadir = $(datadir)/$(PACKAGE) +pkglibdir = $(libdir)/$(PACKAGE) +pkgincludedir = $(includedir)/$(PACKAGE) MANS=mkelfImage.1 +SPEC=mkelfImage-$(VERSION).spec +TARBALL=mkelfImage-$(VERSION).tar.gz +SRCS:=$(shell find ./AUTHORS ./COPYING ./Makefile ./Makefile.conf.in ./News \ + ./mkelfImage.pl ./elf32-i386 ./kunzip_src \ + ./configure.in ./configure ./config \ + ! -path '*CVS*' ! -name '*~' ! -name '.*' -type f -print ) +SRCS+=$(SPEC) +PSRCS:=$(patsubst ./%,mkelfImage-$(VERSION)/%,$(SRCS)) -FILES=mkelfImage $(MANS) +SBIN_TARGETS=mkelfImage +MAN1_TARGETS=mkelfImage.1 +PKGDATADIR_TARGETS=\ + elf32-i386/convert_params.c \ + elf32-i386/elf_boot.h \ + elf32-i386/linuxbios_tables.h \ + elf32-i386/elfImage.lds \ + elf32-i386/head.S \ + elf32-i386/uniform_boot.h -all: $(FILES) +TARGETS:=$(SBIN_TARGETS) $(MAN1_TARGETS) $(PKGDATADIR_TARGETS) + +all: $(TARGETS) clean: - rm -f $(FILES) + @rm -rf dist + @rm -f config.log config.status config.cache + @rm -f $(SBIN_TARGETS) $(MAN1_TARGETS) + @rm -f mkelfImage-$(VERSION) $(TARBALL) -distclean: clean - find . -type f -name '*~' | xargs rm -f +dist-clean: clean + @find . -type f -name '*~' | xargs rm -f + @rm Makefile.conf + +maintainer-clean: dist-clean + @rm -f $(SPEC) configure -install: $(DIRS) $(FILES) - mkdir -p $(SHAREDIR) $(BINDIR) $(MANDIR) - cp -fr elf32-i386/ $(SHAREDIR) - find $(SHAREDIR) -type d | xargs chmod a+x - find $(SHAREDIR) -type f | xargs chmod 444 - cp -f mkelfImage $(BINDIR) - cp -f $(MANS) $(MANDIR) +install: $(TARGETS) + mkdir -p $(DESTDIR)/$(pkgdatadir) $(DESTDIR)/$(sbindir) $(DESTDIR)/$(mandir)/man1 + cp -a $(SBIN_TARGETS) $(DESTDIR)/$(sbindir)/ + cp -a $(MAN1_TARGETS) $(DESTDIR)/$(mandir)/man1/ + cp -a $(PKGDATADIR_TARGETS) $(DESTDIR)/$(pkgdatadir)/ -$(DIRS): - mkdir -p $@ %.1 : %.pl Makefile - pod2man --date=$(DATE) --release=$(VERSION) $*.pl > $@ + mkdir -p $(@D) + pod2man --date="$(RELEASE_DATE)" --release="$(VERSION)" $*.pl > $@ -mkelfImage: mkelfImage.pl Makefile - echo 's|^$$params{MYDATA}=".";$$|$$params{MYDATA}="$(SHAREDIR)";|' > sedfile - echo 's|^#!/usr/bin/perl|#!$(PERLPATH)|' >> sedfile - echo 's|^my $$VERSION="";$$|my $$VERSION=$(VERSION);|' >> sedfile - sed -f sedfile mkelfImage.pl > $@ +mkelfImage: mkelfImage.pl Makefile Makefile.conf + mkdir -p $(@D) + sed \ + -e 's,^#!/usr/bin/perl,#!$(PERL),' \ + -e 's,^my $$VERSION="";$$,my $$VERSION="$(VERSION)";,' \ + -e 's,^$$params{MYDATA}=".";$$,$$params{MYDATA}="$(pkgdatadir)";,' \ + -e 's,^$$params{OBJCOPY}="objcopy";$$,$$params{OBJCOPY}="$(OBJCOPY)";,' \ + -e 's,^$$params{LD}="ld";$$,$$params{LD}="$(LD)";,' \ + -e 's,^$$params{CC}="cc";$$,$$params{CC}="$(CC)";,' \ + mkelfImage.pl > $@ chmod a+x $@ - rm -f sedfile + +tarball: $(TARBALL) + + +$(TARBALL): $(SRCS) + rm -f ./mkelfImage-$(VERSION) + ln -s . ./mkelfImage-$(VERSION) + tar -cf - $(PSRCS) | gzip -9 > $@ + +Makefile.conf: Makefile.conf.in configure + ./configure + + +configure: configure.in + autoconf + +$(SPEC): mkelfImage.spec.in Makefile + sed \ + -e 's,^Version: $$,Version: $(VERSION),' \ + mkelfImage.spec.in > $@ + + + +.PHONY: echo install realinstall + diff --git a/util/mkelfImage/News b/util/mkelfImage/News index 3f7b7f7f50..3dc24fb03a 100644 --- a/util/mkelfImage/News +++ b/util/mkelfImage/News @@ -1,5 +1,72 @@ -1.14 +* 1.15 23 August 2002 + - Rewrote the perl ip checksum code to be reasonably fast + - Fixes to the initial parameter passing in head.S thanks to Jake Page + - Initial cross compiling support thanks to Jake Page + - Official specfile thanks to Andrew Ip + - Autoconf support Josh Aune -- Use much less complex ld magic -- Fix a small bug in the LinuxBIOS checksum verification code +* 1.14 28 June 2002 + - Use much less complex ld magic (removed the use of PHDRS directive) + - Fix a small bug in the LinuxBIOS checksum verification code (only affected odd length tables) +* 1.13 10 May 2002 + Include the version number in mkelfImage. + +* 1.12 26 January 2002 + Better firmware detection, and stripping excess symbols from the + generated object. + +* 1.11 24 January 2002 + Bug fix to command line processing. + +* 1.10 21 January 2002 + Starting using the PHDRS directive which many versions of ld cannot + handle correctly. The symptom is generally a file that is 9MB in + size. + + Start computing a checksum on the Image. + + Include an ELF note section in the image for out of band + information (checksum, program name, etc). + +* 1.9 7 January 2002 + I changed LinuxBIOS (in LinuxBIOS) from passing it's information + locally, to passing it in a global table that is always present. + So that whoever needs that information can get it unfiltered. And + because it isn't being passed around it has less chance of + becomming corrupt. Globals for global information are good :) + Version 1.9 goes out and finds that table. + +* 1.8 10 December 2001 + Move the ramdisk up even higher in memory. + Better debugging of multiboot parameters + Pass the correct values for a vga screen instead of telling the + kernel we have EGA... + +* 1.7 18 May 2001 + Warn when I don't have information about the bootloader. + Include a ELF compreressor that works on alpha && x86 + There is no good way to apply it though. + +* 1.6 1 Febuary 2001 + Code cleanup in bzImage support. + +* 1.5 1 Febuary 2001 + Add support for bzImage + +* 1.4 ??? + ??? + +* 1.3 27 December 2000 + Minor bug fixes for working with the e820 memory map. + +* 1.2 18 December 2000 + Work around for some versions of ld not treating /dev/null and an + empty file the same + +* 1.1 30 November 2000 + Fix for ramdisks and large amounts of memory with 2.2 series + kernels. + +* 1.0 7 November 2000 + Initial release (supports vmlinux && bvmlinux) diff --git a/util/mkelfImage/elf32-i386/convert_params.c b/util/mkelfImage/elf32-i386/convert_params.c index f05c6a9cf9..7527451503 100644 --- a/util/mkelfImage/elf32-i386/convert_params.c +++ b/util/mkelfImage/elf32-i386/convert_params.c @@ -5,7 +5,7 @@ #include "elf_boot.h" #define STACK_SIZE (4096) -long user_stack [STACK_SIZE]; +long user_stack [STACK_SIZE] = { 0 }; unsigned long * stack_start = & user_stack[STACK_SIZE]; diff --git a/util/mkelfImage/elf32-i386/head.S b/util/mkelfImage/elf32-i386/head.S index bac5d9d2e5..2c015a150f 100644 --- a/util/mkelfImage/elf32-i386/head.S +++ b/util/mkelfImage/elf32-i386/head.S @@ -249,12 +249,11 @@ startup_32: cli # Save the arguments safely out of the way - movl %eax, %ebp - movl %ebx, %esi + movl %eax, boot_type + movl %ebx, boot_data movl stack_start, %esp - # Clear eflags pushl $0 popfl @@ -288,9 +287,9 @@ startup_32: movl %eax, %fs movl %eax, %gs movl %eax, %ss - - pushl %esi # boot data pointer as second arg - pushl %ebp # boot data type as first argument + + pushl boot_data # boot data pointer as second arg + pushl boot_type # boot data type as first argument call convert_params movl %eax, %esi # put the real mode pointer in a safe place @@ -560,6 +559,9 @@ _prot_to_real: data32 ret /* There is a 32 bit return address on the stack */ .code32 +boot_type: .long 0 +boot_data: .long 0 + idt_real: .word 0x400 # idt limit = 256 .word 0, 0 @@ -597,3 +599,4 @@ gdt: .word 0xffff,(RELOC&0xffff) .byte (RELOC>>16),0x93,0x00,(RELOC>>24) gdt_end: + diff --git a/util/mkelfImage/mkelfImage.pl b/util/mkelfImage/mkelfImage.pl index 38e7fa84a6..27395914b4 100644 --- a/util/mkelfImage/mkelfImage.pl +++ b/util/mkelfImage/mkelfImage.pl @@ -12,7 +12,7 @@ my $VERSION=""; # Hardcoded parameters for now... $params{OBJCOPY}="objcopy"; $params{LD}="ld"; -$params{CC}="gcc"; +$params{CC}="cc"; $params{CFLAGS}="-O2"; $params{MYDATA}="."; $params{PREFIX}=undef(); @@ -168,17 +168,30 @@ sub compute_ip_checksum $checksum = 0; $size = length($str); $shorts = $size >> 1; - for($i = 0; $i < $shorts; $i++) { - $checksum += unpack('S', substr($str, $i <<1, 2)); - $checksum -= 0xFFFF unless ($checksum <= 0xFFFF); + # Perl has a fairly large loop overhead so a straight forward + # implementation of the ip checksum is intolerably slow. + # Instead we use the unpack checksum computation function, + # and sum 16bit little endian words into a 32bit number, on at + # most 64K of data at a time. This ensures we do not overflow + # the 32bit sum allowing carry wrap around to be implemented by + # hand. + for($i = 0; $i < $shorts; $i += 32768) { + $checksum += unpack("%32v32768", substr($str, $i <<1, 65536)); + while($checksum > 0xffff) { + $checksum = ($checksum & 0xffff) + ($checksum >> 16); + } } if ($size & 1) { - $checksum -= 0xFFFF unless ($checksum <= 0xFFFF); $checksum += unpack('C', substr($str, -1, 1)); + while($checksum > 0xffff) { + $checksum = ($checksum & 0xffff) + ($checksum >> 16); + } } - return (~$checksum) & 0xFFFF; + $checksum = (~$checksum) & 0xFFFF; + return $checksum; } + sub add_ip_checksums { my ($offset, $sum, $new) = @_; @@ -353,8 +366,9 @@ B is a program that makes a elf boot image for linux kernel images. The image should work with any i386 multiboot compliant boot loader, an ELF bootloader that passes no options, a loader compliant with the linuxBIOS elf booting spec or with the linux kexec kernel patch. A key feature -here is that nothing relies upon BIOS, but they are made when -necessary useful for systems running linuxbios. +here is that nothing relies upon BIOS calls, but they are made when +necessary. This is useful for systems running linuxbios. + =head1 BUGS