MIPS: add support for gzip/bzip2/lzma compressed kernel images
PATCH 1/1 MIPS: add support for gzip/bzip2/lzma compressed kernel images
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 protected]>, 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.
--- arch/mips/Kconfig | 3 + arch/mips/Makefile | 11 ++- arch/mips/boot/compressed/Makefile | 72 +++++++++++++++ arch/mips/boot/compressed/dbg.c | 64 ++++++++++++++ arch/mips/boot/compressed/dbg.h | 19 ++++ arch/mips/boot/compressed/decompress.c | 149 +++++++++++++++++++++++++++++++ arch/mips/boot/compressed/dummy.c | 4 + arch/mips/boot/compressed/head.S | 86 ++++++++++++++++++ arch/mips/boot/compressed/ld.script | 150 ++++++++++++++++++++++++++++++++ 9 files changed, 556 insertions(+), 2 deletions(-) create mode 100644 arch/mips/boot/compressed/Makefile create mode 100644 arch/mips/boot/compressed/dbg.c create mode 100644 arch/mips/boot/compressed/dbg.h create mode 100644 arch/mips/boot/compressed/decompress.c create mode 100644 arch/mips/boot/compressed/dummy.c create mode 100644 arch/mips/boot/compressed/head.S create mode 100644 arch/mips/boot/compressed/ld.script
arch/mips/Kconfig +3 -0
@@ -4,6 +4,9 @@ config MIPS select HAVE_IDE select HAVE_OPROFILE select HAVE_ARCH_KGDB + select HAVE_KERNEL_GZIP + select HAVE_KERNEL_BZIP2 + select HAVE_KERNEL_LZMA # Horrible source of confusion. Die, die, die ... select EMBEDDED select RTC_LIB
arch/mips/Makefile +9 -2
@@ -709,7 +709,10 @@ vmlinux.64: vmlinux makeboot =$(Q)$(MAKE) $(build)=arch/mips/boot VMLINUX=$(vmlinux-32) $(1) -all: $(all-y) +all: $(all-y) zImage + +zImage: vmlinux + $(Q)$(MAKE) $(build)=arch/mips/boot/compressed $@ LOADADDR=$(load-y) vmlinux.bin: $(vmlinux-32) +@$(call makeboot,$@)
@@ -735,11 +738,13 @@ endif install: $(Q)install -D -m 755 vmlinux $(INSTALL_PATH)/vmlinux-$(KERNELRELEASE) + $(Q)install -D -m 755 vmlinuz $(INSTALL_PATH)/vmlinuz-$(KERNELRELEASE) $(Q)install -D -m 644 .config $(INSTALL_PATH)/config-$(KERNELRELEASE) $(Q)install -D -m 644 System.map $(INSTALL_PATH)/System.map-$(KERNELRELEASE) archclean: @$(MAKE) $(clean)=arch/mips/boot + @$(MAKE) $(clean)=arch/mips/boot/compressed @$(MAKE) $(clean)=arch/mips/lasat define archhelp
@@ -747,10 +752,12 @@ define archhelp echo ' vmlinux.ecoff - ECOFF boot image' echo ' vmlinux.bin - Raw binary boot image' echo ' vmlinux.srec - SREC boot image' + echo ' vmlinuz - Compressed boot image' echo echo ' These will be default as apropriate for a configured platform.' endef CLEAN_FILES += vmlinux.32 \ vmlinux.64 \ - vmlinux.ecoff + vmlinux.ecoff \ + vmlinuz
arch/mips/boot/compressed/Makefile new file +72 -0
72 lines not on this page · raw message
arch/mips/boot/compressed/dbg.c new file +64 -0
64 lines not on this page · raw message
arch/mips/boot/compressed/dbg.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* board-specific serial port +*/ + +#include <asm/addrspace.h> + +#ifdef CONFIG_LEMOTE_FULONG +#define UART_BASE 0x1fd003f8 +#define PORT (offset) (CKSEG1ADDR(UART_BASE) + (offset)) +#endif + +#ifdef CONFIG_AR7 +#include <ar7.h> +#define PORT (offset) (CKSEG1ADDR(AR7_REGS_UART0) + (4 * offset)) +#endif + +#ifndef PORT +#error please define the serial port address for your own machine +#endif
arch/mips/boot/compressed/decompress.c new file +149 -0
149 lines not on this page · raw message
arch/mips/boot/compressed/dummy.c new file +4 -0
@@ -0,0 +1,4 @@ +int main (void ) +{ +return 0 ; +}
arch/mips/boot/compressed/head.S new file +86 -0
86 lines not on this page · raw message
arch/mips/boot/compressed/ld.script new file +150 -0
150 lines not on this page · raw message
Signature · 1 line
1.6.2.1
Re: AR7 runtime identification [was:- Re: [PATCH -v1] MIPS: add support for gzip/bzip2/lzma compressed kernel images]
In reply to a message not in the archiveLe Monday 10 August 2009 23:42:27 Florian Fainelli, vous avez écrit :
Quoted 42 lines
Hi Alexander,
Le Monday 10 August 2009 12:12:05 Alexander Clouter, vous avez écrit :
Quoted 33 lines · Florian Fainelli
Quoted 10 lines
Hi Alexander,
Le Monday 10 August 2009 11:03:15 Alexander Clouter, vous avez écrit :
Quoted 6 lines
I notice in
arch/mips/ar7/prom.cthe while loop hangs on "(serial_in(UART_LSR)&UART_LSR_TEMT)" instead, is this because of the buggy UART's seen in some revisions of the AR7? As it stands Wu'sputc()implementation works fine for me but I'm guessing it is because the UART has not much opportunity for over/underruns as not much is being sent.Quoted 3 lines
Even with the silicon bug, this should not be a problem as long as you keep polling the
LSR_TEMTbit in the LSR register. The problem appears when running the UART with interrupts.Ahhhh, that makes sense. I'll leave Wu's code alone :)
Quoted 11 lines
Quoted 5 lines
The UART on my board is buggy (missing/repeated characters like many others seem to get) to, but I remember seeing somewhere (in a chat you had years ago with Alan Cox if I remember correctly) the UART is not buggy on *all* AR7 based boards? Is is possible to detect a buggy UART at runtime (maybe via a AR7 revision match test)?
Alan Cox suggested to perform some tests which I did not carry out yet. By using two different hardware revisions in two different routers I noticed that the silicon bug is present in TNETD7300GDU revision 4, while revision 5 does not have it.
Quoted 4 lines
The revision id can certainly help differentiating between the silicon version, later tonight when I have access to the hardware I will compare between a WAG54G and a C54APRx. I remember being them different for theTNETD7300GDU rev 4 and the rev 5.
Quoted 5 lines
Well, I was offering that I could add an extra datapoint if need be. There must be a way to fix up the UART without adding a 'new' UART type, in a clean way. I'll have a look into it tonight, but I imagine you have looked at this in far more detail than I could...but hey, it gives me something to do tonight[1]. :)
Quoted 8 lines
For your information, the TNETD7300GDU is detected like this:
TI AR7 (TNETD7300), ID:0x0005, Revision:0x02and the TNETD7300EZDW (ADSL 2+) is detected like this:
TI AR7 (TNETD7200), ID:0x002b, Revision:0x10which also has the UART bug and is wrongly detected as a TNETD7200.I have left the WAG54G at work and will get my hands back on it tomorow.
The bad news is that my WAG54G v2 which is also a TNEDT7300GDU has this HW bug too rendering the runtime detection of the bug more difficult.
Signature · 5 lines
Best regards, Florian Fainelli Email: [email protected] Web: http://openwrt.org IRC: [florian] on irc.freenode.net -------------------------------
Re: AR7 runtime identification [was:- Re: [PATCH -v1] MIPS: add support for gzip/bzip2/lzma compressed kernel images]
Quoted 6 lines · Florian Fainelli
Quoted 6 lines
Le Monday 10 August 2009 12:12:05 Alexander Clouter, vous avez écrit :
For your information, the TNETD7300GDU is detected like this:
TI AR7 (TNETD7300), ID:0x0005, Revision:0x02
Quoted 9 lines
Quoted 5 lines
and the TNETD7300EZDW (ADSL 2+) is detected like this:
TI AR7 (TNETD7200), ID:0x002b, Revision:0x10which also has the UART bug and is wrongly detected as a TNETD7200.I have left the WAG54G at work and will get my hands back on it tomorow.
The bad news is that my WAG54G v2 which is also a TNEDT7300GDU has this HW bug too rendering the runtime detection of the bug more difficult.
Well, two options I guess. Another Kconfig or pass something on the command line to the kernel. I would opt for the latter as the bug does not make the machine completely unusable and if you make sure the workaround is disabled by default hopefully that will have the effect of getting people to contact you to add an extra data point.
Annoyingly I'm guess we are more interested in people who do *not* have the bug and we would not hear from them as a result. Maybe if we proactively crippled their serial port.... :)
Cheers
Signature · 2 lines
Alexander Clouter .sigmonster says: Be braver -- you can't cross a chasm in two small jumps.
Re: AR7 runtime identification [was:- Re: [PATCH -v1] MIPS: add support for gzip/bzip2/lzma compressed kernel images]
Le Wednesday 12 August 2009 10:37:04 Alexander Clouter, vous avez écrit :
Quoted 12 lines
Quoted 11 lines · Florian Fainelli
Quoted 10 lines
Le Monday 10 August 2009 12:12:05 Alexander Clouter, vous avez écrit :
For your information, the TNETD7300GDU is detected like this:
TI AR7 (TNETD7300), ID:0x0005, Revision:0x02and the TNETD7300EZDW (ADSL 2+) is detected like this:
TI AR7 (TNETD7200), ID:0x002b, Revision:0x10which also has the UART bug and is wrongly detected as a TNETD7200.I have left the WAG54G at work and will get my hands back on it tomorow.
Quoted 8 lines
Quoted 2 lines
The bad news is that my WAG54G v2 which is also a TNEDT7300GDU has this HW bug too rendering the runtime detection of the bug more difficult.
Well, two options I guess. Another
Kconfigor pass something on the command line to the kernel. I would opt for the latter as the bug does not make the machine completely unusable and if you make sure the workaround is disabled by default hopefully that will have the effect of getting people to contact you to add an extra data point.
Or simply enable the workaround even for sane hardware like it is done here:
https://dev.openwrt.org/browser/trunk/target/linux/ar7/patches-2.6.30/500-serial_kludge.patch
as this patch has no side effect on working hardware.
Quoted 7 lines
Annoyingly I'm guess we are more interested in people who do *not* have the bug and we would not hear from them as a result. Maybe if we proactively crippled their serial port.... :)
Cheers
Cordialement, Florian Fainelli
------------------------------
Signature · 5 lines
Best regards, Florian Fainelli Email: [email protected] Web: http://openwrt.org IRC: [florian] on irc.freenode.net -------------------------------
Hi,
Quoted 17 lines · Wu Zhangjin
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/vmlinuzHave 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 protected]>, he helped to test it on AR7[1] based Linksys WAG54Gv2 and gave good suggestion on board-independence.
Quoted 6 lines
NOTE: this should work for the other MIPS-based machines, but I have used the command bc in the
Makefileto 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 :)
Quoted 2 lines
Signed-off-by Wu Zhangjin <[email protected]>
Cheers
Signature · 3 lines
Alexander Clouter
.sigmonster says: My computer can beat up your computer.
-- Karl LehenbauerHi Wu!
Quoted 1 line · Wu Zhangjin
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
Hi,
Quoted 11 lines · Wu Zhangjin
This patch will help to generate smaller kernel images for linux-MIPS,
[snipped]
NOTE: this should work for the other MIPS-based machines, but I have used the command bc in the
Makefileto 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.
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 :)
Review
Quoted 10 lines
+ [snipped]
(quoted diff) +8
-0+# 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
arch/mips/boot/compressed/Makefile +5 -5
@@ -12,11 +12,11 @@ # Author: Wu Zhangjin <[email protected]> # -# 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)
Quoted 11 lines · Wu Zhangjin
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/vmlinuzHave tested the 32bit kernel on Qemu/Malta and 64bit kernel on FuLoong Mini PC. both of them work well.
ip27_defconfig:
CHK include/linux/compile.h
(standard_in) 1: parse error
(standard_in) 1: parse error
AS arch/mips/boot/compressed/head.oarch/mips/boot/compressed/head.S: Assembler messages:arch/mips/boot/compressed/head.S:78: Error: Number (0xa800000000021bf0) larger than 32 bits make[1]: *** [arch/mips/boot/compressed/head.o] Error 1
rm200_defconfig:
$ make [...] IHEX2FW firmware/whiteheat.fw IHEX2FW firmware/keyspan_pda/keyspan_pda.fw IHEX2FW firmware/keyspan_pda/xircom_pgs.fw [ralf@h5 linux-queue]$ ll vmlinuz lrwxrwxrwx 1 ralf ralf 33 2009-10-12 03:30 vmlinuz -> arch/mips/boot/compressed/vmlinuz* [ralf@h5 linux-queue]$ ll arch/mips/boot/compressed/vmlinuz -rwxrwxr-x 1 ralf ralf 1675346 2009-10-12 03:30 arch/mips/boot/compressed/vmlinuz* [ralf@h5 linux-queue]$ make distclean CLEAN arch/mips/boot (standard_in) 1: parse error [...]
For rm200 we need an ECOFF zimage.
malta_defconfig:
$ mkdir ../build-malta $ make O=../build-malta malta_defconfig [...] $ cd ../build-malta $ make [...] $ make distclean make -C /home/ralf/src/linux/linux-queue O=/home/ralf/src/linux/build-malta/. distclean CLEAN arch/mips/boot (standard_in) 1: parse error $
By default we generate a binary that is not ELF file for malta, so a compressed kernel should be in that format also.
$ make help [...] Architecture specific targets (mips): install - install kernel into /boot vmlinux.ecoff - ECOFF boot image vmlinux.bin - Raw binary boot image vmlinux.srec - SREC boot image vmlinuz - Compressed boot image [...] $ make vmlinuz make: *** No rule to make target `vmlinuz'. Stop. $
arch/mips/Makefile vmlinux.64: vmlinux · line 715
Quoted 13 lines
arch/mips/Makefile +4
-1@@ -709,7 +709,10 @@ vmlinux.64: vmlinux makeboot =$(Q)$(MAKE) $(build)=arch/mips/boot VMLINUX=$(vmlinux-32) $(1) -all: $(all-y) +all: $(all-y) zImage + +zImage: vmlinux + $(Q)$(MAKE) $(build)=arch/mips/boot/compressed $@ LOADADDR=$(load-y)
Several systems rely on the firmware for memory usage information. With a compressed kernel this information will be inaccurate. This is a somewhat hard problem to solve so I suggest to only enable compressed kernels on systems where they're known to work.
Ralf
Hi,
Quoted 16 lines · Ralf Baechle
Quoted 11 lines · Wu Zhangjin
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/vmlinuzHave tested the 32bit kernel on Qemu/Malta and 64bit kernel on FuLoong Mini PC. both of them work well.
ip27_defconfig:
Quoted 8 lines
CHK
include/linux/compile.h
(standard_in) 1: parse error
(standard_in) 1: parse error
ASarch/mips/boot/compressed/head.oarch/mips/boot/compressed/head.S: Assembler messages:arch/mips/boot/compressed/head.S:78: Error: Number (0xa800000000021bf0) larger than 32 bits make[1]: *** [arch/mips/boot/compressed/head.o] Error 1
Seems something wrong in the Makefile, will fix it later, here it is:
[...]/bin/sh: 0x0xa80000000001c000: value too great for base (error token is "0x0xa80000000001c000")
Building modules, stage 2.
AS arch/mips/boot/compressed/head.o CC arch/mips/boot/compressed/decompress.o GZIP arch/mips/boot/compressed/vmlinux.gz CC arch/mips/boot/compressed/dbg.o
MODPOST 137 modules
CC arch/mips/boot/compressed/dummy.oarch/mips/boot/compressed/head.S: Assembler messages:arch/mips/boot/compressed/head.S:47: Error: Number (0xa800000000021bf0) larger than 32 bits
[...]
Quoted 16 lines
rm200_defconfig:$ make [...] IHEX2FW firmware/whiteheat.fw IHEX2FW firmware/keyspan_pda/keyspan_pda.fw IHEX2FW firmware/keyspan_pda/xircom_pgs.fw [ralf@h5 linux-queue]$ ll vmlinuz lrwxrwxrwx 1 ralf ralf 33 2009-10-12 03:30 vmlinuz -> arch/mips/boot/compressed/vmlinuz* [ralf@h5 linux-queue]$ ll arch/mips/boot/compressed/vmlinuz -rwxrwxr-x 1 ralf ralf 1675346 2009-10-12 03:30 arch/mips/boot/compressed/vmlinuz* [ralf@h5 linux-queue]$ make distclean CLEAN arch/mips/boot (standard_in) 1: parse error [...]
Quoted 2 lines
For rm200 we need an ECOFF zimage.
Okay, will fix it later.
Quoted 12 lines
malta_defconfig:$ mkdir ../build-malta $ make O=../build-malta malta_defconfig [...] $ cd ../build-malta $ make [...] $ make distclean make -C /home/ralf/src/linux/linux-queue O=/home/ralf/src/linux/build-malta/. distclean CLEAN arch/mips/boot (standard_in) 1: parse error
This "parse error" will be fixed by tuning the Makefile via adding something like " blabla 2>/dev/null".
Quoted 5 lines
$
By default we generate a binary that is not ELF file for malta, so a compressed kernel should be in that format also.
Quoted 13 lines
$ make help [...] Architecture specific targets (mips): install - install kernel into /boot vmlinux.ecoff - ECOFF boot image vmlinux.bin - Raw binary boot image vmlinux.srec - SREC boot image vmlinuz - Compressed boot image [...] $ make vmlinuz make: *** No rule to make target `vmlinuz'. Stop. $
it should be
$ make zImage
will replace "vmlinuz - Compressed boot image" to "zImage - Compressed boot image", or, fix "make vmlinuz" itself.
Quoted 8 lines
Quoted 8 lines
arch/mips/Makefile +0
-0@@ -709,7 +709,10 @@ vmlinux.64: vmlinux makeboot =$(Q)$(MAKE) $(build)=arch/mips/boot VMLINUX=$(vmlinux-32) $(1)
Quoted 10 lines
arch/mips/Makefile vmlinux.64: vmlinux · line 715
Quoted 5 lines
arch/mips/Makefile +4
-1-all: $(all-y) +all: $(all-y) zImage + +zImage: vmlinux + $(Q)$(MAKE) $(build)=arch/mips/boot/compressed $@ LOADADDR=$(load-y)Several systems rely on the firmware for memory usage information. With a compressed kernel this information will be inaccurate. This is a somewhat hard problem to solve so I suggest to only enable compressed kernels on systems where they're known to work.
Okay, I will add a new kernel option for this, and also, the DEBUG(dbg.[hc]) part will be selectable with a new kernel option too.
Thanks & Regards,
Wu Zhangjin