All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] MIPS: arch/mips/boot/compressed/Makefile: Unify the suffix of compressed vmlinux.bin
@ 2010-06-01 10:29 Wu Zhangjin
  2010-06-01 10:29 ` [PATCH] MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS Wu Zhangjin
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Wu Zhangjin @ 2010-06-01 10:29 UTC (permalink / raw)
  To: Ralf Baechle, linux-mips
  Cc: Alexander Clouter, Manuel Lauss, Sam Ravnborg, 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 <wuzhangjin@gmail.com>
---
 arch/mips/boot/compressed/Makefile |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile
index 74a52d7..7204dfc 100644
--- a/arch/mips/boot/compressed/Makefile
+++ b/arch/mips/boot/compressed/Makefile
@@ -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
-- 
1.6.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH] MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS
  2010-06-01 10:29 [PATCH] MIPS: arch/mips/boot/compressed/Makefile: Unify the suffix of compressed vmlinux.bin Wu Zhangjin
@ 2010-06-01 10:29 ` Wu Zhangjin
  2010-06-01 10:56   ` Alexander Clouter
  2010-06-01 10:29 ` [PATCH] MIPS: Move Loongson Makefile parts to their own Platform file Wu Zhangjin
  2010-06-02  2:31   ` wu zhangjin
  2 siblings, 1 reply; 9+ messages in thread
From: Wu Zhangjin @ 2010-06-01 10:29 UTC (permalink / raw)
  To: Ralf Baechle, linux-mips
  Cc: Alexander Clouter, Manuel Lauss, Sam Ravnborg, Wu Zhangjin

We have calculated VMLINUZ_LOAD_ADDRESS in shell, which is awful. This patch
rewrites it in C.

Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
---
 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

diff --git a/arch/mips/boot/.gitignore b/arch/mips/boot/.gitignore
index 4667a5f..f210b09 100644
--- a/arch/mips/boot/.gitignore
+++ b/arch/mips/boot/.gitignore
@@ -3,3 +3,4 @@ elf2ecoff
 vmlinux.*
 zImage
 zImage.tmp
+calc_vmlinuz_load_addr
diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile
index 7204dfc..cd9ee04 100644
--- a/arch/mips/boot/compressed/Makefile
+++ b/arch/mips/boot/compressed/Makefile
@@ -12,14 +12,6 @@
 # Author: Wu Zhangjin <wuzhangjin@gmail.com>
 #
 
-# 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
diff --git a/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c b/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c
new file mode 100644
index 0000000..1787dce
--- /dev/null
+++ b/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 "Wu Zhangjin" <wuzhangjin@gmail.com>
+ *
+ * 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;
+}
-- 
1.6.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH] MIPS: Move Loongson Makefile parts to their own Platform file
  2010-06-01 10:29 [PATCH] MIPS: arch/mips/boot/compressed/Makefile: Unify the suffix of compressed vmlinux.bin Wu Zhangjin
  2010-06-01 10:29 ` [PATCH] MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS Wu Zhangjin
@ 2010-06-01 10:29 ` Wu Zhangjin
  2010-06-01 13:13   ` Ralf Baechle
  2010-06-02  2:31   ` wu zhangjin
  2 siblings, 1 reply; 9+ messages in thread
From: Wu Zhangjin @ 2010-06-01 10:29 UTC (permalink / raw)
  To: Ralf Baechle, linux-mips
  Cc: Alexander Clouter, Manuel Lauss, Sam Ravnborg, Wu Zhangjin

Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
---
 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

diff --git a/arch/mips/Kbuild.platforms b/arch/mips/Kbuild.platforms
index 681b2d4..9784c49 100644
--- a/arch/mips/Kbuild.platforms
+++ b/arch/mips/Kbuild.platforms
@@ -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))
diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index ff71a54..14b755d 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -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/
diff --git a/arch/mips/loongson/Platform b/arch/mips/loongson/Platform
new file mode 100644
index 0000000..29692e5
--- /dev/null
+++ b/arch/mips/loongson/Platform
@@ -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
-- 
1.6.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS
  2010-06-01 10:29 ` [PATCH] MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS Wu Zhangjin
@ 2010-06-01 10:56   ` Alexander Clouter
       [not found]     ` <AANLkTikxHLWSoUFQItXnULP-pF1-us7FgAP_GkkoCMeO@mail.gmail.com>
  0 siblings, 1 reply; 9+ messages in thread
From: Alexander Clouter @ 2010-06-01 10:56 UTC (permalink / raw)
  To: Wu Zhangjin; +Cc: Ralf Baechle, linux-mips, Manuel Lauss, Sam Ravnborg

Hi,

* Wu Zhangjin <wuzhangjin@gmail.com> [2010-06-01 18:29:03+0800]:
>
> We have calculated VMLINUZ_LOAD_ADDRESS in 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

> Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
> ---
>  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
> 
> diff --git a/arch/mips/boot/.gitignore b/arch/mips/boot/.gitignore
> index 4667a5f..f210b09 100644
> --- a/arch/mips/boot/.gitignore
> +++ b/arch/mips/boot/.gitignore
> @@ -3,3 +3,4 @@ elf2ecoff
>  vmlinux.*
>  zImage
>  zImage.tmp
> +calc_vmlinuz_load_addr
> diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile
> index 7204dfc..cd9ee04 100644
> --- a/arch/mips/boot/compressed/Makefile
> +++ b/arch/mips/boot/compressed/Makefile
> @@ -12,14 +12,6 @@
>  # Author: Wu Zhangjin <wuzhangjin@gmail.com>
>  #
>  
> -# 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
> diff --git a/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c b/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c
> new file mode 100644
> index 0000000..1787dce
> --- /dev/null
> +++ b/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c
> @@ -0,0 +1,52 @@
> +/*
> + * Copyright (C) 2010 "Wu Zhangjin" <wuzhangjin@gmail.com>
> + *
> + * 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;
> +}
> -- 
> 1.6.5
> 

-- 
Alexander Clouter
.sigmonster says: To teach is to learn twice.
                  		-- Joseph Joubert

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS
       [not found]     ` <AANLkTikxHLWSoUFQItXnULP-pF1-us7FgAP_GkkoCMeO@mail.gmail.com>
@ 2010-06-01 12:41       ` wu zhangjin
  2010-06-01 12:42       ` Alexander Clouter
  1 sibling, 0 replies; 9+ messages in thread
From: wu zhangjin @ 2010-06-01 12:41 UTC (permalink / raw)
  To: Alexander Clouter; +Cc: Ralf Baechle, linux-mips, Manuel Lauss, Sam Ravnborg

Hi,

[...]
>> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS
       [not found]     ` <AANLkTikxHLWSoUFQItXnULP-pF1-us7FgAP_GkkoCMeO@mail.gmail.com>
  2010-06-01 12:41       ` wu zhangjin
@ 2010-06-01 12:42       ` Alexander Clouter
  1 sibling, 0 replies; 9+ messages in thread
From: Alexander Clouter @ 2010-06-01 12:42 UTC (permalink / raw)
  To: wu zhangjin; +Cc: Ralf Baechle, linux-mips, Manuel Lauss, Sam Ravnborg

Hi,

* wu zhangjin <wuzhangjin@gmail.com> [2010-06-01 20:26:23+0800]:
>
> On Tue, Jun 1, 2010 at 6:56 PM, Alexander Clouter <alex@digriz.org.uk> wrote:
> >
> > * Wu Zhangjin <wuzhangjin@gmail.com> [2010-06-01 18:29:03+0800]:
> >>
> >> We have calculated VMLINUZ_LOAD_ADDRESS in 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]).
> 
> ooh, Sorry, Just found I have forgotten one "return", and for
> portability, will use exit(EXIT_SUCCESS) and exit(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.
 
> > 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.
 
> > 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.
> 
> > 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

-- 
Alexander Clouter
.sigmonster says: Gibble, Gobble, we ACCEPT YOU ...

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] MIPS: Move Loongson Makefile parts to their own Platform file
  2010-06-01 10:29 ` [PATCH] MIPS: Move Loongson Makefile parts to their own Platform file Wu Zhangjin
@ 2010-06-01 13:13   ` Ralf Baechle
  0 siblings, 0 replies; 9+ messages in thread
From: Ralf Baechle @ 2010-06-01 13:13 UTC (permalink / raw)
  To: Wu Zhangjin; +Cc: linux-mips, Alexander Clouter, Manuel Lauss, Sam Ravnborg

On Tue, Jun 01, 2010 at 06:29:04PM +0800, Wu Zhangjin wrote:

Thanks Wu, queued for 2.6.36.

 Ralf

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] MIPS: arch/mips/boot/compressed/Makefile: Unify the  suffix of compressed vmlinux.bin
@ 2010-06-02  2:31   ` wu zhangjin
  0 siblings, 0 replies; 9+ messages in thread
From: wu zhangjin @ 2010-06-02  2:31 UTC (permalink / raw)
  To: Ralf Baechle, linux-mips
  Cc: Alexander Clouter, Manuel Lauss, Sam Ravnborg, Wu Zhangjin

Hi,

I will use vmlinux.bin.z in the next revision of this patch.

Regards,


On Tue, Jun 1, 2010 at 6:29 PM, Wu Zhangjin <wuzhangjin@gmail.com> wrote:
> 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 <wuzhangjin@gmail.com>
> ---
>  arch/mips/boot/compressed/Makefile |   12 ++++--------
>  1 files changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile
> index 74a52d7..7204dfc 100644
> --- a/arch/mips/boot/compressed/Makefile
> +++ b/arch/mips/boot/compressed/Makefile
> @@ -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
> --
> 1.6.5
>
>



-- 
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
wuzhangjin@gmail.com         http://falcon.oss.lzu.edu.cn
Address:Tianshui South Road 222,Lanzhou,P.R.China    Zip Code:730000
Tel:+86-931-8912025

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] MIPS: arch/mips/boot/compressed/Makefile: Unify the suffix of compressed vmlinux.bin
@ 2010-06-02  2:31   ` wu zhangjin
  0 siblings, 0 replies; 9+ messages in thread
From: wu zhangjin @ 2010-06-02  2:31 UTC (permalink / raw)
  To: Ralf Baechle, linux-mips
  Cc: Alexander Clouter, Manuel Lauss, Sam Ravnborg, Wu Zhangjin

Hi,

I will use vmlinux.bin.z in the next revision of this patch.

Regards,


On Tue, Jun 1, 2010 at 6:29 PM, Wu Zhangjin <wuzhangjin@gmail.com> wrote:
> 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 <wuzhangjin@gmail.com>
> ---
>  arch/mips/boot/compressed/Makefile |   12 ++++--------
>  1 files changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile
> index 74a52d7..7204dfc 100644
> --- a/arch/mips/boot/compressed/Makefile
> +++ b/arch/mips/boot/compressed/Makefile
> @@ -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
> --
> 1.6.5
>
>



-- 
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
wuzhangjin@gmail.com         http://falcon.oss.lzu.edu.cn
Address:Tianshui South Road 222,Lanzhou,P.R.China    Zip Code:730000
Tel:+86-931-8912025

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-06-02  2:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-01 10:29 [PATCH] MIPS: arch/mips/boot/compressed/Makefile: Unify the suffix of compressed vmlinux.bin Wu Zhangjin
2010-06-01 10:29 ` [PATCH] MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS Wu Zhangjin
2010-06-01 10:56   ` Alexander Clouter
     [not found]     ` <AANLkTikxHLWSoUFQItXnULP-pF1-us7FgAP_GkkoCMeO@mail.gmail.com>
2010-06-01 12:41       ` wu zhangjin
2010-06-01 12:42       ` Alexander Clouter
2010-06-01 10:29 ` [PATCH] MIPS: Move Loongson Makefile parts to their own Platform file Wu Zhangjin
2010-06-01 13:13   ` Ralf Baechle
2010-06-02  2:31 ` [PATCH] MIPS: arch/mips/boot/compressed/Makefile: Unify the suffix of compressed vmlinux.bin wu zhangjin
2010-06-02  2:31   ` wu zhangjin

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.