All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Marek <mmarek@suse.cz>
To: Sam Ravnborg <sam@ravnborg.org>
Cc: Michael Tokarev <mjt@tls.msk.ru>,
	Michael Guntsche <mike@it-loops.com>,
	Oliver Hartkopp <oliver@hartkopp.net>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Andreas Schwab <schwab@linux-m68k.org>
Subject: Re: [PATCH] kbuild: correct size calculation of bzImgae / fix x86 boot
Date: Mon, 21 Dec 2009 15:17:13 +0100	[thread overview]
Message-ID: <4B2F8369.2060708@suse.cz> (raw)
In-Reply-To: <20091220141156.GA3744@merkur.ravnborg.org>

Sam Ravnborg wrote:
> The whole business using shell scripts to append the size seems broken.
> How about moving this functionality to mkpiggy where we are
> less shell script dependent.
> 
> Something like the following.
> I have only tested it lightly (vmlinux.bin did not differ
> before/after the patch.


I think that it's a good idea to move this out of the makefiles. But for
2.6.33, I think I prefer the patch from Andreas, provided he signs it
off and Michael G confirms that it fixes his issue.


> It includes the length also in the gzip case - I dunno if that matters.

I don't know either, but this is trivially fixable by an option to
mkpiggy that is added only if CONFIG_KERNEL_BZIP2=y or CONFIG_KERNEL_LZMA=y.


> Also I dunno if ".long" is the same on 32 and 64 bit.

I think we can work this out until the .34 merge window :).

Michal
> 
> 	Sam
> 
> diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
> index f8ed065..d39fe2e 100644
> --- a/arch/x86/boot/compressed/Makefile
> +++ b/arch/x86/boot/compressed/Makefile
> @@ -54,7 +54,8 @@ suffix-$(CONFIG_KERNEL_BZIP2)	:= bz2
>  suffix-$(CONFIG_KERNEL_LZMA)	:= lzma
>  
>  quiet_cmd_mkpiggy = MKPIGGY $@
> -      cmd_mkpiggy = $(obj)/mkpiggy $< > $@ || ( rm -f $@ ; false )
> +      cmd_mkpiggy = $(obj)/mkpiggy $< $(vmlinux.bin.all-y) > $@ || \
> +                   ( rm -f $@ ; false )
>  
>  targets += piggy.S
>  $(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
> diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c
> index bcbd36c..f4a1a3f 100644
> --- a/arch/x86/boot/compressed/mkpiggy.c
> +++ b/arch/x86/boot/compressed/mkpiggy.c
> @@ -29,6 +29,7 @@
>  #include <stdio.h>
>  #include <string.h>
>  #include <inttypes.h>
> +#include <sys/stat.h>
>  
>  static uint32_t getle32(const void *p)
>  {
> @@ -38,12 +39,27 @@ static uint32_t getle32(const void *p)
>  		((uint32_t)cp[2] << 16) + ((uint32_t)cp[3] << 24);
>  }
>  
> +static file_size(const char *filename)
> +{
> +	struct stat statbuf;
> +	int res;
> +
> +	res = stat(filename, &statbuf);
> +	if (res < 0) {
> +		perror(filename);
> +		exit(1);
> +	}
> +	return (size_t)statbuf.st_size;
> +}
> +
>  int main(int argc, char *argv[])
>  {
>  	uint32_t olen;
>  	long ilen;
>  	unsigned long offs;
> +	size_t size;
>  	FILE *f;
> +	int i;
>  
>  	if (argc < 2) {
>  		fprintf(stderr, "Usage: %s compressed_file\n", argv[0]);
> @@ -67,6 +83,11 @@ int main(int argc, char *argv[])
>  	olen = getle32(&olen);
>  	fclose(f);
>  
> +	i = 2;
> +	size = 0;
> +	while (i < argc)
> +		size += file_size(argv[i++]);
> +
>  	/*
>  	 * Now we have the input (compressed) and output (uncompressed)
>  	 * sizes, compute the necessary decompression offset...
> @@ -91,6 +112,14 @@ int main(int argc, char *argv[])
>  	printf(".globl input_data, input_data_end\n");
>  	printf("input_data:\n");
>  	printf(".incbin \"%s\"\n", argv[1]);
> +
> +        /*
> +         * Bzip2 and LZMA do not include size in file... so we have to fake that;
> +         * append the size as a 32-bit littleendian number as gzip does.
> +         */
> +	if (size > 0)
> +		printf(".long %d\n", size);
> +
>  	printf("input_data_end:\n");
>  
>  	return 0;
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index cd815ac..10bef1c 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -211,27 +211,14 @@ cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -f -9 > $@) || \
>  # Bzip2
>  # ---------------------------------------------------------------------------
>  
> -# Bzip2 and LZMA do not include size in file... so we have to fake that;
> -# append the size as a 32-bit littleendian number as gzip does.
> -size_append = printf $(shell						\
> -dec_size=0;								\
> -for F in $1; do								\
> -	fsize=$$(stat -c "%s" $$F);					\
> -	dec_size=$$(expr $$dec_size + $$fsize);				\
> -done;									\
> -printf "%08x" $$dec_size |						\
> -	sed 's/\(..\)\(..\)\(..\)\(..\)/\\\\x\4\\\\x\3\\\\x\2\\\\x\1/g'	\
> -)
> -
>  quiet_cmd_bzip2 = BZIP2   $@
> -cmd_bzip2 = (cat $(filter-out FORCE,$^) | \
> -	bzip2 -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
> -	(rm -f $@ ; false)
> +cmd_bzip2 = cat $(filter-out FORCE,$^) | \
> +	bzip2 -9 > $@ || (rm -f $@ ; false)
>  
>  # Lzma
>  # ---------------------------------------------------------------------------
>  
>  quiet_cmd_lzma = LZMA    $@
> -cmd_lzma = (cat $(filter-out FORCE,$^) | \
> -	lzma -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
> -	(rm -f $@ ; false)
> +cmd_lzma = cat $(filter-out FORCE,$^) | \
> +	lzma -9 > $@ || (rm -f $@ ; false)
> +


  reply	other threads:[~2009-12-21 14:17 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-19 23:34 2.6.33-rc1 Reboot right after bootloader Michael Guntsche
2009-12-20  8:46 ` Sam Ravnborg
2009-12-20  9:10   ` Johannes Stezenbach
2009-12-20 10:38     ` Michael Tokarev
2009-12-20 11:10       ` Michael Tokarev
2009-12-20 11:38         ` Michael Tokarev
2009-12-20  9:11   ` Michael Guntsche
2009-12-20 10:03     ` [PATCH] kbuild: correct size calculation of bzImgae / fix x86 boot Sam Ravnborg
2009-12-20 10:20       ` Oliver Hartkopp
2009-12-20 10:28       ` Willy Tarreau
2009-12-20 10:47         ` Michael Tokarev
2009-12-20 13:09           ` Willy Tarreau
2009-12-20 11:19       ` Michael Tokarev
2009-12-20 12:02         ` Andreas Schwab
2009-12-20 12:18           ` Sam Ravnborg
2009-12-21 12:23           ` Michal Marek
2009-12-21 13:50             ` Andreas Schwab
2009-12-20 14:11         ` Sam Ravnborg
2009-12-21 14:17           ` Michal Marek [this message]
2009-12-21 16:28             ` Michael Guntsche
2009-12-21 19:53               ` Michael Tokarev
2009-12-21 20:48                 ` Michael Guntsche
2009-12-21 18:28           ` H. Peter Anvin
2009-12-21 19:09             ` H. Peter Anvin
2009-12-20 13:50       ` Arkadiusz Miskiewicz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B2F8369.2060708@suse.cz \
    --to=mmarek@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mike@it-loops.com \
    --cc=mjt@tls.msk.ru \
    --cc=oliver@hartkopp.net \
    --cc=sam@ravnborg.org \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.