* [PATCH v2] MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS
@ 2010-06-01 13:11 Wu Zhangjin
2010-06-01 13:41 ` Alexander Clouter
0 siblings, 1 reply; 3+ messages in thread
From: Wu Zhangjin @ 2010-06-01 13:11 UTC (permalink / raw)
To: Ralf Baechle, linux-mips
Cc: Alexander Clouter, Manuel Lauss, Sam Ravnborg, Wu Zhangjin
Changes:
v1 -> v2:
o make it more portable (feedback from Alexander Clouter)
use EXIT_SUCCESS and EXIT_FAILURE as the return value, and use uint64_t
instead of "unsigned long long".
o add a missing return value (feedback from Alexander Clouter)
return EXIT_FAILURE if (n != 1).
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 | 55 ++++++++++++++++++++
3 files changed, 66 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..81176b1
--- /dev/null
+++ b/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c
@@ -0,0 +1,55 @@
+/*
+ * 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 <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
+{
+ int n;
+ struct stat sb;
+ uint64_t vmlinux_size, vmlinux_load_addr, vmlinuz_load_addr;
+
+ if (argc != 3) {
+ fprintf(stderr, "Usage: %s <pathname> <vmlinux_load_addr>\n",
+ argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ if (stat(argv[1], &sb) == -1) {
+ perror("stat");
+ return EXIT_FAILURE;
+ }
+
+ /* 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");
+
+ return EXIT_FAILURE;
+ }
+
+ 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 EXIT_SUCCESS;
+}
--
1.6.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS
2010-06-01 13:11 [PATCH v2] MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS Wu Zhangjin
@ 2010-06-01 13:41 ` Alexander Clouter
2010-06-01 13:50 ` wu zhangjin
0 siblings, 1 reply; 3+ messages in thread
From: Alexander Clouter @ 2010-06-01 13:41 UTC (permalink / raw)
To: Wu Zhangjin; +Cc: Ralf Baechle, linux-mips, Manuel Lauss, Sam Ravnborg
Hi,
* Wu Zhangjin <wuzhangjin@gmail.com> [2010-06-01 21:11:56+0800]:
>
> Changes:
>
> v1 -> v2:
> o make it more portable (feedback from Alexander Clouter)
> use EXIT_SUCCESS and EXIT_FAILURE as the return value, and use uint64_t
> instead of "unsigned long long".
> o add a missing return value (feedback from Alexander Clouter)
> return EXIT_FAILURE if (n != 1).
>
> We have calculated VMLINUZ_LOAD_ADDRESS in shell, which is awful. This patch
> rewrites it in C.
>
s/awful/indecipherable/
:)
> 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 | 55 ++++++++++++++++++++
> 3 files changed, 66 insertions(+), 12 deletions(-)
> create mode 100644 arch/mips/boot/compressed/calc_vmlinuz_load_addr.c
>
> 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..81176b1
> --- /dev/null
> +++ b/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c
> @@ -0,0 +1,55 @@
>
> [snipped]
>
> +
> + /* Convert hex characters to dec number */
> + errno = 0;
> + n = sscanf(argv[2], "%llx", &vmlinux_load_addr);
> + if (n != 1) {
>
you can drop the 'n' with:
if (sscanf(argv[2], "%llx", &vmlinux_load_addr) != 1) {
> + if (errno != 0)
> + perror("sscanf");
> + else
> + fprintf(stderr, "No matching characters\n");
> +
> + return EXIT_FAILURE;
> + }
> +
> + vmlinux_size = (unsigned long long)sb.st_size;
>
I'm guessing this should probably be uint64_t also?
Other than that, makes me happy :)
Cheers
--
Alexander Clouter
.sigmonster says: And furthermore, my bowling average is unimpeachable!!!
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS
2010-06-01 13:41 ` Alexander Clouter
@ 2010-06-01 13:50 ` wu zhangjin
0 siblings, 0 replies; 3+ messages in thread
From: wu zhangjin @ 2010-06-01 13:50 UTC (permalink / raw)
To: Alexander Clouter; +Cc: Ralf Baechle, linux-mips, Manuel Lauss, Sam Ravnborg
v3 is ready ;)
On Tue, Jun 1, 2010 at 9:41 PM, Alexander Clouter <alex@digriz.org.uk> wrote:
> Hi,
>
> * Wu Zhangjin <wuzhangjin@gmail.com> [2010-06-01 21:11:56+0800]:
>>
>> Changes:
>>
>> v1 -> v2:
>> o make it more portable (feedback from Alexander Clouter)
>> use EXIT_SUCCESS and EXIT_FAILURE as the return value, and use uint64_t
>> instead of "unsigned long long".
>> o add a missing return value (feedback from Alexander Clouter)
>> return EXIT_FAILURE if (n != 1).
>>
>> We have calculated VMLINUZ_LOAD_ADDRESS in shell, which is awful. This patch
>> rewrites it in C.
>>
> s/awful/indecipherable/
>
> :)
>
>> 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 | 55 ++++++++++++++++++++
>> 3 files changed, 66 insertions(+), 12 deletions(-)
>> create mode 100644 arch/mips/boot/compressed/calc_vmlinuz_load_addr.c
>>
>> 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..81176b1
>> --- /dev/null
>> +++ b/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c
>> @@ -0,0 +1,55 @@
>>
>> [snipped]
>>
>> +
>> + /* Convert hex characters to dec number */
>> + errno = 0;
>> + n = sscanf(argv[2], "%llx", &vmlinux_load_addr);
>> + if (n != 1) {
>>
> you can drop the 'n' with:
>
> if (sscanf(argv[2], "%llx", &vmlinux_load_addr) != 1) {
>
>> + if (errno != 0)
>> + perror("sscanf");
>> + else
>> + fprintf(stderr, "No matching characters\n");
>> +
>> + return EXIT_FAILURE;
>> + }
>> +
>> + vmlinux_size = (unsigned long long)sb.st_size;
>>
> I'm guessing this should probably be uint64_t also?
>
> Other than that, makes me happy :)
>
> Cheers
>
> --
> Alexander Clouter
> .sigmonster says: And furthermore, my bowling average is unimpeachable!!!
>
--
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] 3+ messages in thread
end of thread, other threads:[~2010-06-01 13:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-01 13:11 [PATCH v2] MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS Wu Zhangjin
2010-06-01 13:41 ` Alexander Clouter
2010-06-01 13:50 ` 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.