Skip to contentSkip to conversation

defining ZRELADDR as PHYS_OFFSET + TEXT_OFFSET

DISCUSSION Uwe Kleine-König 3 participants 7 messages Jan 27, 2010 – Feb 5, 2010 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

Hello,

currently all platforms need to define zreladdr-y in arch/arm/mach-$mach/Makefile.boot and PHYS_OFFSET (in arch/arm/mach-$mach/include/mach/memory.h).

Constraints for these are:

TEXTADDR = PAGE_OFFSET + TEXT_OFFSET
__virt_to_phys(virt) = virt - PAGE_OFFSET + PHYS_OFFSET (at least for
"small" virtual addresses)
ZRELADDR = __virt_to_phys(TEXTADDR)

(The equallity for __virt_to_phys only holds "normaly" according to
http://lists.arm.linux.org.uk/lurker/message/20010723.185051.94ce743c.en.html.
In practice it holds for addresses of the first bank of RAM which is enough for the purposes of this mail.)

So we can deduce ZRELADDR = PHYS_OFFSET + TEXT_OFFSET.

Is there something I missed or is it possible to get rid of zreladdr-y in .../Makefile.boot and define it according to the equation above?

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                              | Uwe Kleine-K?nig            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |
#1 lore raw
Quoted 18 lines · Uwe Kleine-K?nig

Hello,

currently all platforms need to define zreladdr-y in arch/arm/mach-$mach/Makefile.boot and PHYS_OFFSET (in arch/arm/mach-$mach/include/mach/memory.h).

Constraints for these are:

TEXTADDR = PAGE_OFFSET + TEXT_OFFSET
__virt_to_phys(virt) = virt - PAGE_OFFSET + PHYS_OFFSET (at least for
"small" virtual addresses)
ZRELADDR = __virt_to_phys(TEXTADDR)

(The equallity for __virt_to_phys only holds "normaly" according to
http://lists.arm.linux.org.uk/lurker/message/20010723.185051.94ce743c.en.html.
In practice it holds for addresses of the first bank of RAM which is enough for the purposes of this mail.)

Quoted 4 lines

So we can deduce ZRELADDR = PHYS_OFFSET + TEXT_OFFSET.

Is there something I missed or is it possible to get rid of zreladdr-y in .../Makefile.boot and define it according to the equation above?

You'd need to find some way to get PHYS_OFFSET out of the C code into the makefile. With all sorts of stuff going on in various platforms memory.h files, that doesn't look simple.

#2 lore raw

Hi,

Quoted 19 lines · Russell King - ARM Linux
Quoted 18 lines · Uwe Kleine-K?nig

Hello,

currently all platforms need to define zreladdr-y in arch/arm/mach-$mach/Makefile.boot and PHYS_OFFSET (in arch/arm/mach-$mach/include/mach/memory.h).

Constraints for these are:

TEXTADDR = PAGE_OFFSET + TEXT_OFFSET
__virt_to_phys(virt) = virt - PAGE_OFFSET + PHYS_OFFSET (at least for
"small" virtual addresses)
ZRELADDR = __virt_to_phys(TEXTADDR)

(The equallity for __virt_to_phys only holds "normaly" according to
http://lists.arm.linux.org.uk/lurker/message/20010723.185051.94ce743c.en.html.
In practice it holds for addresses of the first bank of RAM which is enough for the purposes of this mail.)

Quoted 8 lines
Quoted 4 lines

So we can deduce ZRELADDR = PHYS_OFFSET + TEXT_OFFSET.

Is there something I missed or is it possible to get rid of zreladdr-y in .../Makefile.boot and define it according to the equation above?

You'd need to find some way to get PHYS_OFFSET out of the C code into the makefile. With all sorts of stuff going on in various platforms memory.h files, that doesn't look simple.

How about this?:

arch/arm/boot/Makefile +1 -1
index 4a590f4..b79050e 100644
@@ -21,7 +21,7 @@ endif
 #   ZRELADDR == virt_to_phys(PAGE_OFFSET + TEXT_OFFSET)
 #   PARAMS_PHYS must be within 4MB of ZRELADDR
 #   INITRD_PHYS must be in RAM
-ZRELADDR    := $(zreladdr-y)
+ZRELADDR    := $(shell printf "0x%08x" $$[`echo PHYS_OFFSET + $(TEXT_OFFSET)  | $(CPP) $(CPP_FLAGS) -D__ASSEMBLY__ -xc -include arch/arm/include/asm/memory.h - | tail -n 1`])
 PARAMS_PHYS := $(params_phys-y)
 INITRD_PHYS := $(initrd_phys-y)
 

Since params_phys-y is (always?) constant relative to zreladdr-y, it can also be calculated in a similar fashion, e.g.

PARAMS_PHYS := $(shell printf "0x%08x" $$[$(ZRELADDR) - 0x7f00])

--
Regards,
George

#3 lore raw

Hallo George,

Quoted 36 lines · George G. Davis
Quoted 19 lines · Russell King - ARM Linux
Quoted 18 lines · Uwe Kleine-K?nig

Hello,

currently all platforms need to define zreladdr-y in arch/arm/mach-$mach/Makefile.boot and PHYS_OFFSET (in arch/arm/mach-$mach/include/mach/memory.h).

Constraints for these are:

TEXTADDR = PAGE_OFFSET + TEXT_OFFSET
__virt_to_phys(virt) = virt - PAGE_OFFSET + PHYS_OFFSET (at least for
"small" virtual addresses)
ZRELADDR = __virt_to_phys(TEXTADDR)

(The equallity for __virt_to_phys only holds "normaly" according to
http://lists.arm.linux.org.uk/lurker/message/20010723.185051.94ce743c.en.html.
In practice it holds for addresses of the first bank of RAM which is enough for the purposes of this mail.)

Quoted 8 lines
Quoted 4 lines

So we can deduce ZRELADDR = PHYS_OFFSET + TEXT_OFFSET.

Is there something I missed or is it possible to get rid of zreladdr-y in .../Makefile.boot and define it according to the equation above?

You'd need to find some way to get PHYS_OFFSET out of the C code into the makefile. With all sorts of stuff going on in various platforms memory.h files, that doesn't look simple.

How about this?:

arch/arm/boot/Makefile +0 -0
index 4a590f4..b79050e 100644

arch/arm/boot/Makefile endif · line 26

Quoted 7 lines
arch/arm/boot/Makefile +1 -1
@@ -21,7 +21,7 @@ endif
 #   ZRELADDR == virt_to_phys(PAGE_OFFSET + TEXT_OFFSET)
 #   PARAMS_PHYS must be within 4MB of ZRELADDR
 #   INITRD_PHYS must be in RAM
-ZRELADDR    := $(zreladdr-y)
+ZRELADDR    := $(shell printf "0x%08x" $$[`echo PHYS_OFFSET + $(TEXT_OFFSET)  | $(CPP) $(CPP_FLAGS) -D__ASSEMBLY__ -xc -include arch/arm/include/asm/memory.h - | tail -n 1`])
 PARAMS_PHYS := $(params_phys-y)
 INITRD_PHYS := $(initrd_phys-y)

hui! Is this really robust?

Quoted 4 lines

Since params_phys-y is (always?) constant relative to zreladdr-y, it can also be calculated in a similar fashion, e.g.

PARAMS_PHYS := $(shell printf "0x%08x" $$[$(ZRELADDR) - 0x7f00])

This isn't necessarily true I think. And I'd prefer getting rid of PARAMS_PHYS. This is only used for bootp and maybe if the bootloader doesn't pass r2 properly.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                              | Uwe Kleine-K?nig            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |
#4 lore raw

Hi,

Quoted 34 lines · Uwe Kleine-K?nig

Hallo George,

Quoted 31 lines · George G. Davis
Quoted 19 lines · Russell King - ARM Linux
Quoted 18 lines · Uwe Kleine-K?nig

Hello,

currently all platforms need to define zreladdr-y in arch/arm/mach-$mach/Makefile.boot and PHYS_OFFSET (in arch/arm/mach-$mach/include/mach/memory.h).

Constraints for these are:

TEXTADDR = PAGE_OFFSET + TEXT_OFFSET
__virt_to_phys(virt) = virt - PAGE_OFFSET + PHYS_OFFSET (at least for
"small" virtual addresses)
ZRELADDR = __virt_to_phys(TEXTADDR)

(The equallity for __virt_to_phys only holds "normaly" according to
http://lists.arm.linux.org.uk/lurker/message/20010723.185051.94ce743c.en.html.
In practice it holds for addresses of the first bank of RAM which is enough for the purposes of this mail.)

Quoted 8 lines
Quoted 4 lines

So we can deduce ZRELADDR = PHYS_OFFSET + TEXT_OFFSET.

Is there something I missed or is it possible to get rid of zreladdr-y in .../Makefile.boot and define it according to the equation above?

You'd need to find some way to get PHYS_OFFSET out of the C code into the makefile. With all sorts of stuff going on in various platforms memory.h files, that doesn't look simple.

How about this?:

Quoted 13 lines

arch/arm/boot/Makefile endif · line 26

Quoted 12 lines
arch/arm/boot/Makefile +1 -1
index 4a590f4..b79050e 100644
@@ -21,7 +21,7 @@ endif
 #   ZRELADDR == virt_to_phys(PAGE_OFFSET + TEXT_OFFSET)
 #   PARAMS_PHYS must be within 4MB of ZRELADDR
 #   INITRD_PHYS must be in RAM
-ZRELADDR    := $(zreladdr-y)
+ZRELADDR    := $(shell printf "0x%08x" $$[`echo PHYS_OFFSET + $(TEXT_OFFSET)  | $(CPP) $(CPP_FLAGS) -D__ASSEMBLY__ -xc -include arch/arm/include/asm/memory.h - | tail -n 1`])
 PARAMS_PHYS := $(params_phys-y)
 INITRD_PHYS := $(initrd_phys-y)

hui! Is this really robust?

Apologies for the delay, busy...

It can be but it is admittedly rather tricky to get the syntax right. I've no idea how the above worked the first time I tried but it didn't upon further inspection. I came up with this variation on the theme:

ZRELADDR = $(shell $(CONFIG_SHELL) -c 'printf "0x%08x" $$[echo PHYS_OFFSET + $(TEXT_OFFSET) | $(CPP) $(cpp_flags) -D__ASSEMBLY__ -xc -imacros asm/memory.h - 2>/dev/null | tail -1]')

This version seems to work for a number of zImage test builds I did. Alas, it is rather tricky to get the syntax right for all uses, e.g. I think uImage is still broken.

Quoted 8 lines
Quoted 5 lines

Since params_phys-y is (always?) constant relative to zreladdr-y, it can also be calculated in a similar fashion, e.g.

PARAMS_PHYS := $(shell printf "0x%08x" $$[$(ZRELADDR) - 0x7f00])

This isn't necessarily true I think. And I'd prefer getting rid of PARAMS_PHYS. This is only used for bootp and maybe if the bootloader doesn't pass r2 properly.

If the bootloader is passing params pointer, then sure, disregard.

Thanks!

--
Regards,
George

Quoted 7 lines

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                              | Uwe Kleine-K?nig            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |
#5 lore raw

Hello,

Quoted 51 lines · George G. Davis

Hi,

Quoted 34 lines · Uwe Kleine-K?nig

Hallo George,

Quoted 31 lines · George G. Davis
Quoted 19 lines · Russell King - ARM Linux
Quoted 18 lines · Uwe Kleine-K?nig

Hello,

currently all platforms need to define zreladdr-y in arch/arm/mach-$mach/Makefile.boot and PHYS_OFFSET (in arch/arm/mach-$mach/include/mach/memory.h).

Constraints for these are:

TEXTADDR = PAGE_OFFSET + TEXT_OFFSET
__virt_to_phys(virt) = virt - PAGE_OFFSET + PHYS_OFFSET (at least for
"small" virtual addresses)
ZRELADDR = __virt_to_phys(TEXTADDR)

(The equallity for __virt_to_phys only holds "normaly" according to
http://lists.arm.linux.org.uk/lurker/message/20010723.185051.94ce743c.en.html.
In practice it holds for addresses of the first bank of RAM which is enough for the purposes of this mail.)

Quoted 8 lines
Quoted 4 lines

So we can deduce ZRELADDR = PHYS_OFFSET + TEXT_OFFSET.

Is there something I missed or is it possible to get rid of zreladdr-y in .../Makefile.boot and define it according to the equation above?

You'd need to find some way to get PHYS_OFFSET out of the C code into the makefile. With all sorts of stuff going on in various platforms memory.h files, that doesn't look simple.

How about this?:

Quoted 13 lines

arch/arm/boot/Makefile endif · line 26

Quoted 12 lines
arch/arm/boot/Makefile +1 -1
index 4a590f4..b79050e 100644
@@ -21,7 +21,7 @@ endif
 #   ZRELADDR == virt_to_phys(PAGE_OFFSET + TEXT_OFFSET)
 #   PARAMS_PHYS must be within 4MB of ZRELADDR
 #   INITRD_PHYS must be in RAM
-ZRELADDR    := $(zreladdr-y)
+ZRELADDR    := $(shell printf "0x%08x" $$[`echo PHYS_OFFSET + $(TEXT_OFFSET)  | $(CPP) $(CPP_FLAGS) -D__ASSEMBLY__ -xc -include arch/arm/include/asm/memory.h - | tail -n 1`])
 PARAMS_PHYS := $(params_phys-y)
 INITRD_PHYS := $(initrd_phys-y)

hui! Is this really robust?

Quoted 1 line

Apologies for the delay, busy...

no problem.

Quoted 5 lines

It can be but it is admittedly rather tricky to get the syntax right. I've no idea how the above worked the first time I tried but it didn't upon further inspection. I came up with this variation on the theme:

ZRELADDR = $(shell $(CONFIG_SHELL) -c 'printf "0x%08x" $$[echo PHYS_OFFSET + $(TEXT_OFFSET) | $(CPP) $(cpp_flags) -D__ASSEMBLY__ -xc -imacros asm/memory.h - 2>/dev/null | tail -1]')

bash(1) has:

*Arithmetic Expansion*
[...] The format for arithmetic expansion is:

$((expression))

The old format $[expression] is deprecated and will be removed upcoming versions of bash.

Anyhow I think this yields more trouble than it's worth.

Maybe better move PHYS_OFFSET into Makefile.boot or arch/arm/Makefile? Or live with the redundancy? Maybe some time in the future we don't need ZRELADDR any more as it is calculated by zImage based on PHYS_OFFSET.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                              | Uwe Kleine-K?nig            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |
#6 lore raw

Hi,

Quoted 64 lines · Uwe Kleine-K?nig

Hello,

Quoted 51 lines · George G. Davis

Hi,

Quoted 34 lines · Uwe Kleine-K?nig

Hallo George,

Quoted 31 lines · George G. Davis
Quoted 19 lines · Russell King - ARM Linux
Quoted 18 lines · Uwe Kleine-K?nig

Hello,

currently all platforms need to define zreladdr-y in arch/arm/mach-$mach/Makefile.boot and PHYS_OFFSET (in arch/arm/mach-$mach/include/mach/memory.h).

Constraints for these are:

TEXTADDR = PAGE_OFFSET + TEXT_OFFSET
__virt_to_phys(virt) = virt - PAGE_OFFSET + PHYS_OFFSET (at least for
"small" virtual addresses)
ZRELADDR = __virt_to_phys(TEXTADDR)

(The equallity for __virt_to_phys only holds "normaly" according to
http://lists.arm.linux.org.uk/lurker/message/20010723.185051.94ce743c.en.html.
In practice it holds for addresses of the first bank of RAM which is enough for the purposes of this mail.)

Quoted 8 lines
Quoted 4 lines

So we can deduce ZRELADDR = PHYS_OFFSET + TEXT_OFFSET.

Is there something I missed or is it possible to get rid of zreladdr-y in .../Makefile.boot and define it according to the equation above?

You'd need to find some way to get PHYS_OFFSET out of the C code into the makefile. With all sorts of stuff going on in various platforms memory.h files, that doesn't look simple.

How about this?:

Quoted 13 lines

arch/arm/boot/Makefile endif · line 26

Quoted 12 lines
arch/arm/boot/Makefile +1 -1
index 4a590f4..b79050e 100644
@@ -21,7 +21,7 @@ endif
 #   ZRELADDR == virt_to_phys(PAGE_OFFSET + TEXT_OFFSET)
 #   PARAMS_PHYS must be within 4MB of ZRELADDR
 #   INITRD_PHYS must be in RAM
-ZRELADDR    := $(zreladdr-y)
+ZRELADDR    := $(shell printf "0x%08x" $$[`echo PHYS_OFFSET + $(TEXT_OFFSET)  | $(CPP) $(CPP_FLAGS) -D__ASSEMBLY__ -xc -include arch/arm/include/asm/memory.h - | tail -n 1`])
 PARAMS_PHYS := $(params_phys-y)
 INITRD_PHYS := $(initrd_phys-y)

hui! Is this really robust?

Quoted 1 line

Apologies for the delay, busy...

no problem.

Quoted 5 lines

It can be but it is admittedly rather tricky to get the syntax right. I've no idea how the above worked the first time I tried but it didn't upon further inspection. I came up with this variation on the theme:

ZRELADDR = $(shell $(CONFIG_SHELL) -c 'printf "0x%08x" $$[echo PHYS_OFFSET + $(TEXT_OFFSET) | $(CPP) $(cpp_flags) -D__ASSEMBLY__ -xc -imacros asm/memory.h - 2>/dev/null | tail -1]')

bash(1) has:

Quoted 7 lines

*Arithmetic Expansion*
[...] The format for arithmetic expansion is:

$((expression))

The old format $[expression] is deprecated and will be removed upcoming versions of bash.

Ah, thanks! I noticed there are a number of other cases of the deprecated $[expression] form in Linux kernel build scripts.

Quoted 1 line

Anyhow I think this yields more trouble than it's worth.

You're right.

Quoted 1 line

Maybe better move PHYS_OFFSET into Makefile.boot or arch/arm/Makefile?

Agreed.

Quoted 3 lines

Or live with the redundancy? Maybe some time in the future we don't need ZRELADDR any more as it is calculated by zImage based on PHYS_OFFSET.

That would be better.

Thanks!

--
Regards,
George

Quoted 7 lines

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                              | Uwe Kleine-K?nig            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |