Skip to contentSkip to conversation

MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS

PATCH Superseded Wu Zhangjin 2 participants 3 messages Jun 1, 2010 MIPS

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 MIPS: Clean up the calculation of VMLINUZ_LOAD_ADDRESS

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.

---
 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
arch/mips/boot/.gitignore +1 -0
index 4667a5f..f210b09 100644
@@ -3,3 +3,4 @@ elf2ecoff
 vmlinux.*
 zImage
 zImage.tmp
+calc_vmlinuz_load_addr
arch/mips/boot/compressed/Makefile +10 -12
index 7204dfc..cd9ee04 100644
@@ -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 +55 -0

55 lines not on this page · raw message

Signature · 1 line
1.6.5
#1 lore raw

Hi,

Quoted 8 lines · 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)

Quoted 5 lines
    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/

:)

Quoted 15 lines
---
 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
arch/mips/boot/compressed/calc_vmlinuz_load_addr.c new file +0 -0
new file mode 100644
index 0000000..81176b1

arch/mips/boot/compressed/calc_vmlinuz_load_addr.c line 37

Quoted 8 lines
arch/mips/boot/compressed/calc_vmlinuz_load_addr.c new file +5 -0
@@ -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) {

arch/mips/boot/compressed/calc_vmlinuz_load_addr.c line 46

Quoted 10 lines
arch/mips/boot/compressed/calc_vmlinuz_load_addr.c new file +9 -0
+		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

Signature · 2 lines
Alexander Clouter
.sigmonster says: And furthermore, my bowling average is unimpeachable!!!
#2 lore raw

v3 is ready ;)

Quoted 67 lines · Alexander Clouter

Hi,

Quoted 10 lines · 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).

Quoted 3 lines

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

s/awful/indecipherable/

:)

Quoted 15 lines

---
 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

arch/mips/boot/compressed/calc_vmlinuz_load_addr.c new file +0 -0
new file mode 100644
index 0000000..81176b1

arch/mips/boot/compressed/calc_vmlinuz_load_addr.c line 37

Quoted 8 lines
arch/mips/boot/compressed/calc_vmlinuz_load_addr.c new file +5 -0
@@ -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) {

arch/mips/boot/compressed/calc_vmlinuz_load_addr.c line 46

Quoted 10 lines

+             if (errno != 0)
+                     perror("sscanf");
+             else
+                     fprintf(stderr, "No matching characters\n");

arch/mips/boot/compressed/calc_vmlinuz_load_addr.c new file +5 -0
+
+             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!!!

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