linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] MIPS: fix vmlinuz build when only 32bit math shell is available
@ 2010-01-19  9:43 Wu Zhangjin
  2010-01-19  9:43 ` Wu Zhangjin
  2010-01-19  9:55 ` Alexander Clouter
  0 siblings, 2 replies; 4+ messages in thread
From: Wu Zhangjin @ 2010-01-19  9:43 UTC (permalink / raw)
  To: Alexander Clouter, Ralf Baechle
  Cc: linux-mips, Wu Zhangjin, Alexander Clouter

Hi, Alexander Clouter

Does this revision work for you?

Regards,
		Wu Zhangjin

-------------------------------

Changes from v0:

	- Revert the '-n "$(VMLINUX_SIZE)"' to avoid the error of "make clean"
	- Consider more situations of the VMLINUX_LOAD_ADDRESS

Counter to the documentation for the dash shell, it seems that on my
x86_64 filth under Debian only does 32bit math.  As I have configured my
lapdog to use 'dash' for non-interactive tasks I run into problems when
compiling a compressed kernel.

I play with the AR7 platform, so VMLINUX_LOAD_ADDRESS is
0xffffffff94100000, and for a (for example) 4MiB kernel
VMLINUZ_LOAD_ADDRESS is made out to be:

----
alex@berk:~$ bash -c 'printf "%x\n" $((0xffffffff94100000 + 0x400000))'
ffffffff94500000
alex@berk:~$ dash -c 'printf "%x\n" $((0xffffffff94100000 + 0x400000))'
80000000003fffff
----

The former is obviously correct whilst the later breaks things royally.

But fortunately, this works for both bash and dash:

----
$ bash -c 'printf "%x\n" $((0x94100000 + 0x400000))'
94500000
$ dash -c 'printf "%x\n" $((0x94100000 + 0x400000))'
94500000
----

So, we can split the original 64bit string to two parts, and only
calculate the low 32bit part, which is big enough(about 4095 M) for a
normal linux kernel image file, now, we calculate the
VMLINUZ_LOAD_ADDRESS like this:

1. Append "the high 32bit of VMLINUX_LOAD_ADDRESS" as the prefix if it
exists.

2. Get the sum of "the low 32bit of VMLINUX_LOAD_ADDRESS + VMLINUX_SIZE"
with printf "%08x" (08 herein is used to prefix the result with 0...)

The corresponding shell script is:

  A=$VMLINUX_LOAD_ADDRESS;
  # Append "the high 32bit of VMLINUX_LOAD_ADDRESS" as the prefix if it exists.
  [ "${A:0:10}" != "${A}" ] && echo -n ${A:2:8};
  # Get the sum of "the low 32bit of VMLINUX_LOAD_ADDRESS + VMLINUX_SIZE"
  printf "%08x" $(($VMLINUX_SIZE + 0x${A:(-8)}))

This patch fixes vmlinuz kernel builds on systems where only a 32bit
math enabled shell is a available.

Signed-off-by: Alexander Clouter <alex@digriz.org.uk>
Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
---
 arch/mips/boot/compressed/Makefile |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile
index 569b6ad..0c4eb01 100644
--- a/arch/mips/boot/compressed/Makefile
+++ b/arch/mips/boot/compressed/Makefile
@@ -15,7 +15,11 @@
 # 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 $$(($(VMLINUX_SIZE) + (65536 - $(VMLINUX_SIZE) % 65536))))
-VMLINUZ_LOAD_ADDRESS := 0x$(shell [ -n "$(VMLINUX_SIZE)" ] && printf %x $$(($(VMLINUX_LOAD_ADDRESS) + $(VMLINUX_SIZE))))
+# VMLINUZ_LOAD_ADDRESS = concat "high32 of VMLINUX_LOAD_ADDRESS" and "(low32 of VMLINUX_LOAD_ADDRESS) + VMLINUX_SIZE"
+VMLINUZ_LOAD_ADDRESS := 0x$(shell [ -n "$(VMLINUX_SIZE)" ] && ( \
+				A=$(VMLINUX_LOAD_ADDRESS); \
+				[ "$${A:0:10}" != "$${A}" ] && echo -n $${A:2:8}; \
+				printf "%08x" $$(($(VMLINUX_SIZE) + 0x$${A:(-8)})) ))
 
 # set the default size of the mallocing area for decompressing
 BOOT_HEAP_SIZE := 0x400000
-- 
1.6.5.6

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

* [PATCH v1] MIPS: fix vmlinuz build when only 32bit math shell is available
  2010-01-19  9:43 [PATCH v1] MIPS: fix vmlinuz build when only 32bit math shell is available Wu Zhangjin
@ 2010-01-19  9:43 ` Wu Zhangjin
  2010-01-19  9:55 ` Alexander Clouter
  1 sibling, 0 replies; 4+ messages in thread
From: Wu Zhangjin @ 2010-01-19  9:43 UTC (permalink / raw)
  To: Alexander Clouter, Ralf Baechle; +Cc: linux-mips, Wu Zhangjin

Hi, Alexander Clouter

Does this revision work for you?

Regards,
		Wu Zhangjin

-------------------------------

Changes from v0:

	- Revert the '-n "$(VMLINUX_SIZE)"' to avoid the error of "make clean"
	- Consider more situations of the VMLINUX_LOAD_ADDRESS

Counter to the documentation for the dash shell, it seems that on my
x86_64 filth under Debian only does 32bit math.  As I have configured my
lapdog to use 'dash' for non-interactive tasks I run into problems when
compiling a compressed kernel.

I play with the AR7 platform, so VMLINUX_LOAD_ADDRESS is
0xffffffff94100000, and for a (for example) 4MiB kernel
VMLINUZ_LOAD_ADDRESS is made out to be:

----
alex@berk:~$ bash -c 'printf "%x\n" $((0xffffffff94100000 + 0x400000))'
ffffffff94500000
alex@berk:~$ dash -c 'printf "%x\n" $((0xffffffff94100000 + 0x400000))'
80000000003fffff
----

The former is obviously correct whilst the later breaks things royally.

But fortunately, this works for both bash and dash:

----
$ bash -c 'printf "%x\n" $((0x94100000 + 0x400000))'
94500000
$ dash -c 'printf "%x\n" $((0x94100000 + 0x400000))'
94500000
----

So, we can split the original 64bit string to two parts, and only
calculate the low 32bit part, which is big enough(about 4095 M) for a
normal linux kernel image file, now, we calculate the
VMLINUZ_LOAD_ADDRESS like this:

1. Append "the high 32bit of VMLINUX_LOAD_ADDRESS" as the prefix if it
exists.

2. Get the sum of "the low 32bit of VMLINUX_LOAD_ADDRESS + VMLINUX_SIZE"
with printf "%08x" (08 herein is used to prefix the result with 0...)

The corresponding shell script is:

  A=$VMLINUX_LOAD_ADDRESS;
  # Append "the high 32bit of VMLINUX_LOAD_ADDRESS" as the prefix if it exists.
  [ "${A:0:10}" != "${A}" ] && echo -n ${A:2:8};
  # Get the sum of "the low 32bit of VMLINUX_LOAD_ADDRESS + VMLINUX_SIZE"
  printf "%08x" $(($VMLINUX_SIZE + 0x${A:(-8)}))

This patch fixes vmlinuz kernel builds on systems where only a 32bit
math enabled shell is a available.

Signed-off-by: Alexander Clouter <alex@digriz.org.uk>
Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
---
 arch/mips/boot/compressed/Makefile |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile
index 569b6ad..0c4eb01 100644
--- a/arch/mips/boot/compressed/Makefile
+++ b/arch/mips/boot/compressed/Makefile
@@ -15,7 +15,11 @@
 # 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 $$(($(VMLINUX_SIZE) + (65536 - $(VMLINUX_SIZE) % 65536))))
-VMLINUZ_LOAD_ADDRESS := 0x$(shell [ -n "$(VMLINUX_SIZE)" ] && printf %x $$(($(VMLINUX_LOAD_ADDRESS) + $(VMLINUX_SIZE))))
+# VMLINUZ_LOAD_ADDRESS = concat "high32 of VMLINUX_LOAD_ADDRESS" and "(low32 of VMLINUX_LOAD_ADDRESS) + VMLINUX_SIZE"
+VMLINUZ_LOAD_ADDRESS := 0x$(shell [ -n "$(VMLINUX_SIZE)" ] && ( \
+				A=$(VMLINUX_LOAD_ADDRESS); \
+				[ "$${A:0:10}" != "$${A}" ] && echo -n $${A:2:8}; \
+				printf "%08x" $$(($(VMLINUX_SIZE) + 0x$${A:(-8)})) ))
 
 # set the default size of the mallocing area for decompressing
 BOOT_HEAP_SIZE := 0x400000
-- 
1.6.5.6

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

* Re: [PATCH v1] MIPS: fix vmlinuz build when only 32bit math shell is available
  2010-01-19  9:43 [PATCH v1] MIPS: fix vmlinuz build when only 32bit math shell is available Wu Zhangjin
  2010-01-19  9:43 ` Wu Zhangjin
@ 2010-01-19  9:55 ` Alexander Clouter
  2010-01-19 10:27   ` Wu Zhangjin
  1 sibling, 1 reply; 4+ messages in thread
From: Alexander Clouter @ 2010-01-19  9:55 UTC (permalink / raw)
  To: Wu Zhangjin; +Cc: Ralf Baechle, linux-mips

Hi,

* Wu Zhangjin <wuzhangjin@gmail.com> [2010-01-19 17:43:09+0800]:
> 
> Does this revision work for you?
>
> Changes from v0:
> 
> 	- Revert the '-n "$(VMLINUX_SIZE)"' to avoid the error of "make clean"
> 	- Consider more situations of the VMLINUX_LOAD_ADDRESS
> 
> [snipped]
>
> So, we can split the original 64bit string to two parts, and only
> calculate the low 32bit part, which is big enough(about 4095 M) for a
> normal linux kernel image file, now, we calculate the
> VMLINUZ_LOAD_ADDRESS like this:
>
As a passing query, why do we have the high 32bit (0xffffffff....) spiel 
if later we can just make VMLINU[XZ]_LOAD_ADDRESS the low half?  I see 
the output of 'nm' shows:
----
alex@berk:/usr/src/wag54g/linux$ nm vmlinux | head -n1
941019e4 t .ex0
alex@berk:/usr/src/wag54g/linux$ nm vmlinuz | head -n1
944abb50 B .heap
----

However I am guessing it's some 64bit CPU requirement as my x86_64 
kernel seems to have 0xffffffff....  Which raises the question, why is 
AR7 not just using VMLINUX_LOAD_ADDRESS=0x94100000?

> 1. Append "the high 32bit of VMLINUX_LOAD_ADDRESS" as the prefix if it
> exists.
> 
> 2. Get the sum of "the low 32bit of VMLINUX_LOAD_ADDRESS + VMLINUX_SIZE"
> with printf "%08x" (08 herein is used to prefix the result with 0...)
> 
> The corresponding shell script is:
> 
>   A=$VMLINUX_LOAD_ADDRESS;
>   # Append "the high 32bit of VMLINUX_LOAD_ADDRESS" as the prefix if it exists.
>   [ "${A:0:10}" != "${A}" ] && echo -n ${A:2:8};
>   # Get the sum of "the low 32bit of VMLINUX_LOAD_ADDRESS + VMLINUX_SIZE"
>   printf "%08x" $(($VMLINUX_SIZE + 0x${A:(-8)}))
> 
Eugh, bash-ism's...
----
alex@berk:/usr/src/wag54g/linux$ bash -c 'A=1234567890; echo ${A:0:5}'
12345
alex@berk:/usr/src/wag54g/linux$ dash -c 'A=1234567890; echo ${A:0:5}'
dash: Bad substitution
----

Your 'punishment', use Plan9 for a period of no less than a week! :)

You have to use the pattern matching approach I used in my original 
patch, that's portable.  Look at 'man 1 dash' and search for 'substr' 
for more details.

Cheers

-- 
Alexander Clouter
.sigmonster says: I'm not prejudiced, I hate everyone equally.

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

* Re: [PATCH v1] MIPS: fix vmlinuz build when only 32bit math shell is available
  2010-01-19  9:55 ` Alexander Clouter
@ 2010-01-19 10:27   ` Wu Zhangjin
  0 siblings, 0 replies; 4+ messages in thread
From: Wu Zhangjin @ 2010-01-19 10:27 UTC (permalink / raw)
  To: Alexander Clouter; +Cc: Ralf Baechle, linux-mips

Hi,

On Tue, 2010-01-19 at 09:55 +0000, Alexander Clouter wrote:
[...]
> >
> As a passing query, why do we have the high 32bit (0xffffffff....) spiel 
> if later we can just make VMLINU[XZ]_LOAD_ADDRESS the low half?  I see 
> the output of 'nm' shows:
> ----
> alex@berk:/usr/src/wag54g/linux$ nm vmlinux | head -n1
> 941019e4 t .ex0
> alex@berk:/usr/src/wag54g/linux$ nm vmlinuz | head -n1
> 944abb50 B .heap
> ----
> 

Mine:

$ mips64el-unknown-linux-gnu-nm vmlinux | head -n1
ffffffff80202304 t .ex0
$ mips64el-unknown-linux-gnu-nm vmlinuz | head -n1
ffffffff80b174e0 B .heap

and exactly, here is why we need to reserve the high 32bit:

$ cat arch/mips/Makefile | grep ^load | grep -v 0xffffffff
load-$(CONFIG_MIPS_SIM)		+= 0x80100000
load-$(CONFIG_SGI_IP27)		+= 0xc00000004001c000
load-$(CONFIG_SGI_IP27)		+= 0xa80000000001c000
load-$(CONFIG_SGI_IP28)		+= 0xa800000020004000

(Hi, Ralf, can we use the low 32bit directly?)

> However I am guessing it's some 64bit CPU requirement as my x86_64 
> kernel seems to have 0xffffffff....  Which raises the question, why is 
> AR7 not just using VMLINUX_LOAD_ADDRESS=0x94100000?
> 
> > 1. Append "the high 32bit of VMLINUX_LOAD_ADDRESS" as the prefix if it
> > exists.
> > 
> > 2. Get the sum of "the low 32bit of VMLINUX_LOAD_ADDRESS + VMLINUX_SIZE"
> > with printf "%08x" (08 herein is used to prefix the result with 0...)
> > 
> > The corresponding shell script is:
> > 
> >   A=$VMLINUX_LOAD_ADDRESS;
> >   # Append "the high 32bit of VMLINUX_LOAD_ADDRESS" as the prefix if it exists.
> >   [ "${A:0:10}" != "${A}" ] && echo -n ${A:2:8};
> >   # Get the sum of "the low 32bit of VMLINUX_LOAD_ADDRESS + VMLINUX_SIZE"
> >   printf "%08x" $(($VMLINUX_SIZE + 0x${A:(-8)}))
> > 
> Eugh, bash-ism's...
> ----
> alex@berk:/usr/src/wag54g/linux$ bash -c 'A=1234567890; echo ${A:0:5}'
> 12345
> alex@berk:/usr/src/wag54g/linux$ dash -c 'A=1234567890; echo ${A:0:5}'
> dash: Bad substitution
> ----

Ooh! really forget to test it with the dash, dash.... So, this revision
is also broken ;(

> 
> Your 'punishment', use Plan9 for a period of no less than a week! :)
>

I have never played with Plan9, but ubuntu, archlinux, gentoo... and
created my user with "useradd -s /bin/bash ....", so, I only work with
bash ;)

> You have to use the pattern matching approach I used in my original 
> patch, that's portable.  Look at 'man 1 dash' and search for 'substr' 
> for more details.

To consider "portable" and "good-looking", Perhaps it's better to use C
language here ;)

Thanks!

Regards,
	Wu Zhangjin

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

end of thread, other threads:[~2010-01-19 10:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-19  9:43 [PATCH v1] MIPS: fix vmlinuz build when only 32bit math shell is available Wu Zhangjin
2010-01-19  9:43 ` Wu Zhangjin
2010-01-19  9:55 ` Alexander Clouter
2010-01-19 10:27   ` Wu Zhangjin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).