Subject: Re: [PATCH -v1] MIPS: add support for gzip/bzip2/lzma compressed kernel images

From: Alexander Clouter <[email-masked]>
Date: Sat, 26 Sep 2009 13:33:20 +0100

Hi,

* Wu Zhangjin <[email-masked]> [2009-08-10 16:49:14+0800]:
>
> This patch will help to generate smaller kernel images for linux-MIPS,
> 
> Here is the effect when using lzma:
> 
> $ ls -sh vmlinux
> 7.1M vmlinux
> $ ls -sh arch/mips/boot/compressed/vmlinuz
> 1.5M arch/mips/boot/compressed/vmlinuz
> 
> Have tested the 32bit kernel on Qemu/Malta and 64bit kernel on FuLoong
> Mini PC. both of them work well.
> 
> and this revision incorporates the feedback from Alexander Clouter
> <[email-masked]>, he helped to test it on AR7[1] based Linksys
> WAG54Gv2 and gave good suggestion on board-independence.
> 
> NOTE: this should work for the other MIPS-based machines, but I have
> used the command bc in the Makefile to calculate the load address of the
> compressed kernel. I'm not sure this is suitable.  perhaps I need to
> rewrite this part in C program or somebody help to simplify the current
> implementation.
> 
Finally Fleabay'ed a replacement WAG54Gv2 to replace the one I 
bricked to try this new patch.

Works perfectly....I finally can cooked more or less vanilla kernels on 
my board now :)

> Signed-off-by: Wu Zhangjin <[email-masked]>
>
Tested-by: Alexander Clouter <[email-masked]>

Cheers

-- 
Alexander Clouter
.sigmonster says: My computer can beat up your computer.
                  		-- Karl Lehenbauer

---

From: Manuel Lauss <[email-masked]>
Date: Mon, 28 Sep 2009 16:08:52 +0200

Hi Wu!

> This patch will help to generate smaller kernel images for linux-MIPS,

I just gave it quick spin on my Alchemy boards, works quite well!

For the debug code (dbg.[ch]) I suggest you leave the actual uart-banging
to board code (either in the form of cpp macros or inlined functions)
because most chips either don't have a 16550 compatible uart or (in the
alchemy case) have a 16550 with non-standard register layout.

Thanks you for your work!
        Manuel Lauss

---

From: Alexander Clouter <[email-masked]>
Date: Mon, 28 Sep 2009 21:17:03 +0100

Hi,

* Wu Zhangjin <[email-masked]> [2009-08-10 16:49:14+0800]:
> [snipped]
Remembered you wanted a nicer way to work out the load address so this 
is my best attempt so far....I think it's fine to leave it as shell code 
personally; but I'm not a maintainer :)

> + [snipped]
>
> +# The load address of the compressed kernel, VMLINUZ_LOAD_ADDRESS > VMLINUX_LOAD_ADDRESS + VMLINUX_SIZE
> +VMLINUX_SIZE := $(shell wc -c $(objtree)/$(KBUILD_IMAGE) 2>/dev/null | cut -d' ' -f1)
> +VMLINUX_SIZE := $(shell echo "obase=16;ibase=10;(($(VMLINUX_SIZE)/65536 + 1) * 65536)" | bc | cut -d'.' -f1)
> +VMLINUX_LOAD_ADDRESS = $(shell echo $(LOADADDR) | sed -e "s/0xffffffff//g")
> +VMLINUZ_LOAD_ADDRESS := $(shell echo "obase=16; ibase=16; ($(VMLINUX_LOAD_ADDRESS) + $(VMLINUX_SIZE))" | bc)
> +VMLINUZ_LOAD_ADDRESS := 0x$(if $(CONFIG_64BIT),ffffffff,)$(VMLINUZ_LOAD_ADDRESS)
> +LOADADDR := 0x$(if $(CONFIG_64BIT),ffffffff,)$(VMLINUX_LOAD_ADDRESS)
> +
Slightly prettier is to get rid of the 'bc' dependency, a divide and a 
'cut' here and there.

Cheers

--
Alexander Clouter
.sigmonster says: Nice guys finish last.
                                -- Leo Durocher

diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile
index f9ccd97..e531b28 100644
--- a/arch/mips/boot/compressed/Makefile
+++ b/arch/mips/boot/compressed/Makefile
@@ -12,11 +12,11 @@
 # Author: Wu Zhangjin <[email-masked]>
 #
 
-# The load address of the compressed kernel, VMLINUZ_LOAD_ADDRESS > VMLINUX_LOAD_ADDRESS + VMLINUX_SIZE
-VMLINUX_SIZE := $(shell wc -c $(objtree)/$(KBUILD_IMAGE) 2>/dev/null | cut -d' ' -f1)
-VMLINUX_SIZE := $(shell echo "obase=16;ibase=10;(($(VMLINUX_SIZE)/65536 + 1) * 65536)" | bc | cut -d'.' -f1)
-VMLINUX_LOAD_ADDRESS = $(shell echo $(LOADADDR) | sed -e "s/0xffffffff//g")
-VMLINUZ_LOAD_ADDRESS := $(shell echo "obase=16; ibase=16; ($(VMLINUX_LOAD_ADDRESS) + $(VMLINUX_SIZE))" | bc)
+# compressed kernel load addr: VMLINUZ_LOAD_ADDRESS > VMLINUX_LOAD_ADDRESS + VMLINUX_SIZE
+VMLINUX_SIZE := $(shell wc -c $(objtree)/$(KBUILD_IMAGE) | cut -d' ' -f1)
+VMLINUX_SIZE := $(shell echo $$(($(VMLINUX_SIZE) + (65536 - $(VMLINUX_SIZE) % 65536))))
+VMLINUX_LOAD_ADDRESS = $(shell echo $(LOADADDR) | sed -e 's/0xffffffff//')
+VMLINUZ_LOAD_ADDRESS := $(shell printf %x $$((0x$(VMLINUX_LOAD_ADDRESS) + $(VMLINUX_SIZE))))
 VMLINUZ_LOAD_ADDRESS := 0x$(if $(CONFIG_64BIT),ffffffff,)$(VMLINUZ_LOAD_ADDRESS)
 LOADADDR := 0x$(if $(CONFIG_64BIT),ffffffff,)$(VMLINUX_LOAD_ADDRESS)