MIPS: arch/mips/boot/compressed/Makefile: Unify the suffix of compressed vmlinux.bin
PATCH 1/1 MIPS: arch/mips/boot/compressed/Makefile: Unify the suffix of compressed vmlinux.bin
The compressed vmlinux.{gz,bz2,lzo,lzma} are only temp files, we can use the same suffix for them to remove several lines and simpify the maintaining.
--- arch/mips/boot/compressed/Makefile | 12 ++++-------- 1 files changed, 4 insertions(+), 8 deletions(-)
arch/mips/boot/compressed/Makefile +4 -8
@@ -48,23 +48,19 @@ OBJCOPYFLAGS_vmlinux.bin := $(OBJCOPYFLAGS) -O binary -R .comment -S $(obj)/vmlinux.bin: $(KBUILD_IMAGE) FORCE $(call if_changed,objcopy) -suffix_$(CONFIG_KERNEL_GZIP) = gz -suffix_$(CONFIG_KERNEL_BZIP2) = bz2 -suffix_$(CONFIG_KERNEL_LZMA) = lzma -suffix_$(CONFIG_KERNEL_LZO) = lzo tool_$(CONFIG_KERNEL_GZIP) = gzip tool_$(CONFIG_KERNEL_BZIP2) = bzip2 tool_$(CONFIG_KERNEL_LZMA) = lzma tool_$(CONFIG_KERNEL_LZO) = lzo -targets += vmlinux.gz vmlinux.bz2 vmlinux.lzma vmlinux.lzo -$(obj)/vmlinux.$(suffix_y): $(obj)/vmlinux.bin FORCE +targets += vmlinux.z +$(obj)/vmlinux.z: $(obj)/vmlinux.bin FORCE $(call if_changed,$(tool_y)) targets += piggy.o -OBJCOPYFLAGS_piggy.o := --add-section=.image=$(obj)/vmlinux.$(suffix_y) \ +OBJCOPYFLAGS_piggy.o := --add-section=.image=$(obj)/vmlinux.z \ --set-section-flags=.image=contents,alloc,load,readonly,data -$(obj)/piggy.o: $(obj)/dummy.o $(obj)/vmlinux.$(suffix_y) FORCE +$(obj)/piggy.o: $(obj)/dummy.o $(obj)/vmlinux.z FORCE $(call if_changed,objcopy) LDFLAGS_vmlinuz := $(LDFLAGS) -Ttext $(VMLINUZ_LOAD_ADDRESS) -T
Signature · 1 line
1.6.5
PATCH 1/1 MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS
We have calculated VMLINUZ_LOAD_ADDRESS in shell, which is awful. This patch rewrites it in C.
--- arch/mips/boot/.gitignore | 1 + arch/mips/boot/compressed/Makefile | 22 ++++----- arch/mips/boot/compressed/calc_vmlinuz_load_addr.c | 52 ++++++++++++++++++++ 3 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 arch/mips/boot/compressed/calc_vmlinuz_load_addr.c
arch/mips/boot/.gitignore +1 -0
@@ -3,3 +3,4 @@ elf2ecoff vmlinux.* zImage zImage.tmp +calc_vmlinuz_load_addr
arch/mips/boot/compressed/Makefile +10 -12
@@ -12,14 +12,6 @@ # Author: Wu Zhangjin <[email protected]> # -# compressed kernel load addr: 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 [ -n "$(VMLINUX_SIZE)" ] && echo -n $$(($(VMLINUX_SIZE) + (65536 - $(VMLINUX_SIZE) % 65536)))) -# VMLINUZ_LOAD_ADDRESS = concat "high32 of VMLINUX_LOAD_ADDRESS" and "(low32 of VMLINUX_LOAD_ADDRESS) + VMLINUX_SIZE" -HIGH32 := $(shell A=$(VMLINUX_LOAD_ADDRESS); [ $${\#A} -gt 10 ] && expr substr "$(VMLINUX_LOAD_ADDRESS)" 3 $$(($${\#A} - 10))) -LOW32 := $(shell [ -n "$(HIGH32)" ] && A=11 || A=3; expr substr "$(VMLINUX_LOAD_ADDRESS)" $${A} 8) -VMLINUZ_LOAD_ADDRESS := 0x$(shell [ -n "$(VMLINUX_SIZE)" -a -n "$(LOW32)" ] && printf "$(HIGH32)%08x" $$(($(VMLINUX_SIZE) + 0x$(LOW32)))) - # set the default size of the mallocing area for decompressing BOOT_HEAP_SIZE := 0x400000
@@ -63,9 +55,15 @@ OBJCOPYFLAGS_piggy.o := --add-section=.image=$(obj)/vmlinux.z \ $(obj)/piggy.o: $(obj)/dummy.o $(obj)/vmlinux.z FORCE $(call if_changed,objcopy) -LDFLAGS_vmlinuz := $(LDFLAGS) -Ttext $(VMLINUZ_LOAD_ADDRESS) -T -vmlinuz: $(src)/ld.script $(vmlinuzobjs-y) $(obj)/piggy.o - $(call cmd,ld) +# Calculate the load address of the compressed kernel +hostprogs-y := calc_vmlinuz_load_addr + +vmlinuzobjs-y += $(obj)/piggy.o + +quiet_cmd_zld = LD $@ + cmd_zld = $(LD) $(LDFLAGS) -Ttext $(shell $(obj)/calc_vmlinuz_load_addr $(objtree)/$(KBUILD_IMAGE) $(VMLINUX_LOAD_ADDRESS)) -T $< $(vmlinuzobjs-y) -o $@ +vmlinuz: $(src)/ld.script $(vmlinuzobjs-y) $(obj)/calc_vmlinuz_load_addr + $(call cmd,zld) $(Q)$(OBJCOPY) $(OBJCOPYFLAGS) $@ #
@@ -76,7 +74,7 @@ ifdef CONFIG_MACH_DECSTATION endif # elf2ecoff can only handle 32bit image -hostprogs-y := ../elf2ecoff +hostprogs-y += ../elf2ecoff ifdef CONFIG_32BIT VMLINUZ = vmlinuz
arch/mips/boot/compressed/calc_vmlinuz_load_addr.c new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
1.6.5
Re: [PATCH] MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS
Hi,
Quoted 4 lines · Wu Zhangjin
We have calculated
VMLINUZ_LOAD_ADDRESSin shell, which is awful. This patch rewrites it in C.
I really feel that going down the C route is even worse....what's more this implementation is broken as it always returns with zero, even when sscanf() fails....and 'return -1' is just plain wrong too (look at sysexits.h for wisdom[1]).
What is so 'awful' about the shell code version?
The shell lump is shorter in implementation size and I am personally not convinced any reasons hinting towards 'clarity' even apply as the shell code is well documented plus it is trivial to step through on any POSIX shell implementation; which cannot be said for the C code. I am also not too confident 'unsigned long long' is a great idea...maybe 'u64' or 'uint64_t' if you are relying on C99[1]?
Wise man says, do not use cannonball to kill mosquito :)
Cheers
[1] http://www.gnu.org/software/libc/manual/html_node/Exit-Status.html
[2] http://gcc.gnu.org/onlinedocs/gcc/Long-Long.html
Quoted 125 lines
Signed-off-by Wu Zhangjin <[email protected]>--- arch/mips/boot/.gitignore | 1 + arch/mips/boot/compressed/Makefile | 22 ++++----- arch/mips/boot/compressed/calc_vmlinuz_load_addr.c | 52 ++++++++++++++++++++ 3 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 arch/mips/boot/compressed/calc_vmlinuz_load_addr.carch/mips/boot/.gitignore +1
-0@@ -3,3 +3,4 @@ elf2ecoff vmlinux.* zImage zImage.tmp +calc_vmlinuz_load_addrarch/mips/boot/compressed/Makefile +10
-12@@ -12,14 +12,6 @@ # Author: Wu Zhangjin <[email protected]> # -# compressed kernel load addr: 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 [ -n "$(VMLINUX_SIZE)" ] && echo -n $$(($(VMLINUX_SIZE) + (65536 - $(VMLINUX_SIZE) % 65536)))) -# VMLINUZ_LOAD_ADDRESS = concat "high32 of VMLINUX_LOAD_ADDRESS" and "(low32 of VMLINUX_LOAD_ADDRESS) + VMLINUX_SIZE" -HIGH32 := $(shell A=$(VMLINUX_LOAD_ADDRESS); [ $${\#A} -gt 10 ] && expr substr "$(VMLINUX_LOAD_ADDRESS)" 3 $$(($${\#A} - 10))) -LOW32 := $(shell [ -n "$(HIGH32)" ] && A=11 || A=3; expr substr "$(VMLINUX_LOAD_ADDRESS)" $${A} 8) -VMLINUZ_LOAD_ADDRESS := 0x$(shell [ -n "$(VMLINUX_SIZE)" -a -n "$(LOW32)" ] && printf "$(HIGH32)%08x" $$(($(VMLINUX_SIZE) + 0x$(LOW32)))) - # set the default size of the mallocing area for decompressing BOOT_HEAP_SIZE := 0x400000@@ -63,9 +55,15 @@ OBJCOPYFLAGS_piggy.o := --add-section=.image=$(obj)/vmlinux.z \ $(obj)/piggy.o: $(obj)/dummy.o $(obj)/vmlinux.z FORCE $(call if_changed,objcopy) -LDFLAGS_vmlinuz := $(LDFLAGS) -Ttext $(VMLINUZ_LOAD_ADDRESS) -T -vmlinuz: $(src)/ld.script $(vmlinuzobjs-y) $(obj)/piggy.o - $(call cmd,ld) +# Calculate the load address of the compressed kernel +hostprogs-y := calc_vmlinuz_load_addr + +vmlinuzobjs-y += $(obj)/piggy.o + +quiet_cmd_zld = LD $@ + cmd_zld = $(LD) $(LDFLAGS) -Ttext $(shell $(obj)/calc_vmlinuz_load_addr $(objtree)/$(KBUILD_IMAGE) $(VMLINUX_LOAD_ADDRESS)) -T $< $(vmlinuzobjs-y) -o $@ +vmlinuz: $(src)/ld.script $(vmlinuzobjs-y) $(obj)/calc_vmlinuz_load_addr + $(call cmd,zld) $(Q)$(OBJCOPY) $(OBJCOPYFLAGS) $@ #@@ -76,7 +74,7 @@ ifdef CONFIG_MACH_DECSTATION endif # elf2ecoff can only handle 32bit image -hostprogs-y := ../elf2ecoff +hostprogs-y += ../elf2ecoff ifdef CONFIG_32BIT VMLINUZ = vmlinuzarch/mips/boot/compressed/calc_vmlinuz_load_addr.c new file +52
-0@@ -0,0 +1,52 @@ +/* +* Copyright (C) 2010 "Wu Zhangjin" <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at your +* option) any later version. +*/ + +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> + +int main (int argc,char *argv[]) +{ +int n; +struct stat sb; +unsigned long long vmlinux_size, vmlinux_load_addr, vmlinuz_load_addr; + +if (argc !=3 ) { +fprintf (stderr,"Usage: %s <pathname> <vmlinux_load_addr>\n" , + argv[0 ]); +return -1 ; + } + +if (stat (argv[1 ], &sb) ==-1 ) { +perror ("stat" ); +return -1 ; + } + +/* Convert hex characters to dec number */ + errno =0 ; + n =sscanf (argv[2 ],"%llx" , &vmlinux_load_addr); +if (n !=1 ) { +if (errno !=0 ) +perror ("sscanf" ); +else +fprintf (stderr,"No matching characters\n" ); + } + + vmlinux_size = (unsigned long long )sb.st_size; + vmlinuz_load_addr = vmlinux_load_addr + vmlinux_size; + +/* Align with 65536 */ + vmlinuz_load_addr += (65536 - vmlinux_size %65536 ); + +printf ("0x%llx\n" , vmlinuz_load_addr); + +return 0 ; +}Signature · 1 line
1.6.5
Signature · 3 lines
Alexander Clouter
.sigmonster says: To teach is to learn twice.
-- Joseph JoubertA message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH] MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS
Hi,
[...]
Quoted 6 lines
Quoted 3 lines
I am also
not too confident 'unsigned long long' is a great idea...maybe 'u64' or 'uint64_t' if you are relying on C99[1]?good idea, which c header file defines u64 and
uint64_t?
Just found it in <stdint.h>
Regards,
Wu Zhangjin
Re: [PATCH] MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS
In reply to a message not in the archiveHi,
Quoted 8 lines · wu zhangjin
Quoted 6 lines · Alexander Clouter
Quoted 4 lines · Wu Zhangjin
We have calculated
VMLINUZ_LOAD_ADDRESSin shell, which is awful. This patch rewrites it in C.
Quoted 9 lines
Quoted 4 lines
I really feel that going down the C route is even worse....what's more this implementation is broken as it always returns with zero, even when
sscanf()fails....and 'return -1' is just plain wrong too (look atsysexits.hfor wisdom[1]).ooh, Sorry, Just found I have forgotten one "return", and for portability, will use
exit(EXIT_SUCCESS)andexit(EXIT_FAILURE)instead later.
I *think* 'return EXIT_SUCCESS' is just as good if not better, as you have 'int main()' as your entry point...or whatever it is called.
Quoted 5 lines
Quoted 1 line
What is so 'awful' about the shell code version?
From my point of view, it looks not good at least, and also not good for maintaining.
Well, I guess I as you are the maintaining, what ever you says goes...more importantly whatever you are more comfortable with also.
Quoted 10 lines
Quoted 4 lines
The shell lump is shorter in implementation size and I am personally not convinced any reasons hinting towards 'clarity' even apply as the shell code is well documented plus it is trivial to step through on any POSIX shell implementation; which cannot be said for the C code.
I like shell too, herein, it is really shorter but is also hard to understand, and of course, we need to ensure "unsigned long long" is at least 64bit wide, I have tested it on my thinkpad SL400 laptop(X86) and my Yeeloong netbook(MIPS), both of them works well.
Quoted 5 lines
Quoted 2 lines
I am also not too confident 'unsigned long long' is a great idea...maybe 'u64' or '
uint64_t' if you are relying on C99[1]?good idea, which c header file defines u64 and
uint64_t?
Wackipedia claims[1] that for C99 you want stdint.h, a quick grep of my /usr/include directory agrees too. It seems that you want 'uint64_t' too and not 'u64' which is Linux only...or something.
Cheers
[1] http://en.wikipedia.org/wiki/Stdint.h
Signature · 2 lines
Alexander Clouter .sigmonster says: Gibble, Gobble, we ACCEPT YOU ...
PATCH 1/1 MIPS: Move Loongson Makefile parts to their own Platform file
In reply to Wu Zhangjin--- arch/mips/Kbuild.platforms | 1 + arch/mips/Makefile | 29 ----------------------------- arch/mips/loongson/Platform | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 29 deletions(-) create mode 100644 arch/mips/loongson/Platform
arch/mips/Kbuild.platforms +1 -0
@@ -1,6 +1,7 @@ # All platforms listed in alphabetic order platforms += ar7 +platforms += loongson # include the platform specific files include $(patsubst %, $(srctree)/arch/mips/%/Platform, $(platforms))
arch/mips/Makefile +0 -29
@@ -130,26 +130,6 @@ cflags-$(CONFIG_CPU_R4300) += -march=r4300 -Wa,--trap cflags-$(CONFIG_CPU_VR41XX) += -march=r4100 -Wa,--trap cflags-$(CONFIG_CPU_R4X00) += -march=r4600 -Wa,--trap cflags-$(CONFIG_CPU_TX49XX) += -march=r4600 -Wa,--trap -# only gcc >= 4.4 have the loongson-specific support -cflags-$(CONFIG_CPU_LOONGSON2) += -Wa,--trap -cflags-$(CONFIG_CPU_LOONGSON2E) += \ - $(call cc-option,-march=loongson2e,-march=r4600) -cflags-$(CONFIG_CPU_LOONGSON2F) += \ - $(call cc-option,-march=loongson2f,-march=r4600) -# enable the workarounds for loongson2f -ifdef CONFIG_CPU_LOONGSON2F_WORKAROUNDS - ifeq ($(call as-option,-Wa$(comma)-mfix-loongson2f-nop,),) - $(error only binutils >= 2.20.2 have needed option -mfix-loongson2f-nop) - else - cflags-$(CONFIG_CPU_NOP_WORKAROUNDS) += -Wa$(comma)-mfix-loongson2f-nop - endif - ifeq ($(call as-option,-Wa$(comma)-mfix-loongson2f-jump,),) - $(error only binutils >= 2.20.2 have needed option -mfix-loongson2f-jump) - else - cflags-$(CONFIG_CPU_JUMP_WORKAROUNDS) += -Wa$(comma)-mfix-loongson2f-jump - endif -endif - cflags-$(CONFIG_CPU_MIPS32_R1) += $(call cc-option,-march=mips32,-mips32 -U_MIPS_ISA -D_MIPS_ISA=_MIPS_ISA_MIPS32) \ -Wa,-mips32 -Wa,--trap cflags-$(CONFIG_CPU_MIPS32_R2) += $(call cc-option,-march=mips32r2,-mips32r2 -U_MIPS_ISA -D_MIPS_ISA=_MIPS_ISA_MIPS32) \
@@ -346,15 +326,6 @@ cflags-$(CONFIG_WR_PPMC) += -I$(srctree)/arch/mips/include/asm/mach-wrppmc load-$(CONFIG_WR_PPMC) += 0xffffffff80100000 # -# Loongson family -# -core-$(CONFIG_MACH_LOONGSON) += arch/mips/loongson/ -cflags-$(CONFIG_MACH_LOONGSON) += -I$(srctree)/arch/mips/include/asm/mach-loongson \ - -mno-branch-likely -load-$(CONFIG_LEMOTE_FULOONG2E) += 0xffffffff80100000 -load-$(CONFIG_LEMOTE_MACH2F) += 0xffffffff80200000 - -# # MIPS Malta board # core-$(CONFIG_MIPS_MALTA) += arch/mips/mti-malta/
arch/mips/loongson/Platform new file +32 -0
@@ -0,0 +1,32 @@ +# +# Loongson Processors' Support +# + +# Only gcc >= 4.4 have Loongson specific support +cflags-$(CONFIG_CPU_LOONGSON2) += -Wa,--trap +cflags-$(CONFIG_CPU_LOONGSON2E) += \ + $(call cc-option,-march=loongson2e,-march=r4600) +cflags-$(CONFIG_CPU_LOONGSON2F) += \ + $(call cc-option,-march=loongson2f,-march=r4600) +# Enable the workarounds for Loongson2f +ifdef CONFIG_CPU_LOONGSON2F_WORKAROUNDS + ifeq ($(call as-option,-Wa$(comma)-mfix-loongson2f-nop,),) + $(error only binutils >= 2.20.2 have needed option -mfix-loongson2f-nop) + else + cflags-$(CONFIG_CPU_NOP_WORKAROUNDS) += -Wa$(comma)-mfix-loongson2f-nop + endif + ifeq ($(call as-option,-Wa$(comma)-mfix-loongson2f-jump,),) + $(error only binutils >= 2.20.2 have needed option -mfix-loongson2f-jump) + else + cflags-$(CONFIG_CPU_JUMP_WORKAROUNDS) += -Wa$(comma)-mfix-loongson2f-jump + endif +endif + +# +# Loongson Machines' Support +# + +platform-$(CONFIG_MACH_LOONGSON) += loongson/ +cflags-$(CONFIG_MACH_LOONGSON) += -I$(srctree)/arch/mips/include/asm/mach-loongson -mno-branch-likely +load-$(CONFIG_LEMOTE_FULOONG2E) += 0xffffffff80100000 +load-$(CONFIG_LEMOTE_MACH2F) += 0xffffffff80200000
Signature · 1 line
1.6.5
Re: [PATCH] MIPS: Move Loongson Makefile parts to their own Platform file
On Tue, Jun 01, 2010 at 06:29:04PM +0800, Wu Zhangjin wrote:
Thanks Wu, queued for 2.6.36.
Ralf
Hi,
I will use vmlinux.bin.z in the next revision of this patch.
Regards,
Quoted 44 lines · Wu Zhangjin
The compressed vmlinux.{gz,bz2,lzo,lzma} are only temp files, we can use the same suffix for them to remove several lines and simpify the maintaining.
Signed-off-by Wu Zhangjin <[email protected]>---
arch/mips/boot/compressed/Makefile | 12 ++++--------1 files changed, 4 insertions(+), 8 deletions(-)arch/mips/boot/compressed/Makefile +0
-0@@ -48,23 +48,19 @@ OBJCOPYFLAGS_vmlinux.bin := $(OBJCOPYFLAGS) -O binary -R .comment -S$(obj)/vmlinux.bin: $(KBUILD_IMAGE) FORCE
$(call if_changed,objcopy)arch/mips/boot/compressed/Makefile +0
-4-suffix_$(CONFIG_KERNEL_GZIP) = gz -suffix_$(CONFIG_KERNEL_BZIP2) = bz2 -suffix_$(CONFIG_KERNEL_LZMA) = lzma -suffix_$(CONFIG_KERNEL_LZO) = lzotool_$(CONFIG_KERNEL_GZIP) = gzip
tool_$(CONFIG_KERNEL_BZIP2) = bzip2
tool_$(CONFIG_KERNEL_LZMA) = lzma
tool_$(CONFIG_KERNEL_LZO) = lzoarch/mips/boot/compressed/Makefile +2
-2-targets += vmlinux.gz vmlinux.bz2 vmlinux.lzma vmlinux.lzo -$(obj)/vmlinux.$(suffix_y): $(obj)/vmlinux.bin FORCE +targets += vmlinux.z +$(obj)/vmlinux.z: $(obj)/vmlinux.bin FORCE$(call if_changed,$(tool_y))
targets += piggy.o
arch/mips/boot/compressed/Makefile +1
-1-OBJCOPYFLAGS_piggy.o := --add-section=.image=$(obj)/vmlinux.$(suffix_y) \ +OBJCOPYFLAGS_piggy.o := --add-section=.image=$(obj)/vmlinux.z \--set-section-flags=.image=contents,alloc,load,readonly,data -$(obj)/piggy.o: $(obj)/dummy.o $(obj)/vmlinux.$(suffix_y) FORCE +$(obj)/piggy.o: $(obj)/dummy.o $(obj)/vmlinux.z FORCE
$(call if_changed,objcopy)LDFLAGS_vmlinuz := $(LDFLAGS) -Ttext $(VMLINUZ_LOAD_ADDRESS) -T --
1.6.5
Signature · 7 lines
Studying engineer. Wu Zhangjin Lanzhou University http://www.lzu.edu.cn Distributed & Embedded System Lab http://dslab.lzu.edu.cn School of Information Science and Engeneering http://xxxy.lzu.edu.cn [email protected] http://falcon.oss.lzu.edu.cn Address:Tianshui South Road 222,Lanzhou,P.R.China Zip Code:730000 Tel:+86-931-8912025