linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] powerpc/Makefile: Don't use $(ARCH) unnecessarily
@ 2023-12-06 11:55 Michael Ellerman
  2023-12-06 11:55 ` [PATCH 2/4] powerpc/vdso: No need to undef powerpc for 64-bit build Michael Ellerman
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Michael Ellerman @ 2023-12-06 11:55 UTC (permalink / raw)
  To: linuxppc-dev

There's no need to use $(ARCH) for references to the arch directory in
the source tree, it is always arch/powerpc.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/Makefile | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index f19dbaa1d541..b0bc17c35ed7 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -161,7 +161,7 @@ CFLAGS-y += $(CONFIG_TUNE_CPU)
 
 asinstr := $(call as-instr,lis 9$(comma)foo@high,-DHAVE_AS_ATHIGH=1)
 
-KBUILD_CPPFLAGS	+= -I $(srctree)/arch/$(ARCH) $(asinstr)
+KBUILD_CPPFLAGS	+= -I $(srctree)/arch/powerpc $(asinstr)
 KBUILD_AFLAGS	+= $(AFLAGS-y)
 KBUILD_CFLAGS	+= $(call cc-option,-msoft-float)
 KBUILD_CFLAGS	+= $(CFLAGS-y)
@@ -232,7 +232,7 @@ BOOT_TARGETS2 := zImage% dtbImage% treeImage.% cuImage.% simpleImage.% uImage.%
 
 PHONY += $(BOOT_TARGETS1) $(BOOT_TARGETS2)
 
-boot := arch/$(ARCH)/boot
+boot := arch/powerpc/boot
 
 $(BOOT_TARGETS1): vmlinux
 	$(Q)$(MAKE) $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
@@ -336,7 +336,7 @@ PHONY += $(generated_configs)
 
 define archhelp
   echo '* zImage          - Build default images selected by kernel config'
-  echo '  zImage.*        - Compressed kernel image (arch/$(ARCH)/boot/zImage.*)'
+  echo '  zImage.*        - Compressed kernel image (arch/powerpc/boot/zImage.*)'
   echo '  uImage          - U-Boot native image format'
   echo '  cuImage.<dt>    - Backwards compatible U-Boot image for older'
   echo '                    versions which do not support device trees'
@@ -347,12 +347,12 @@ define archhelp
   echo '                    (your) ~/bin/$(INSTALLKERNEL) or'
   echo '                    (distribution) /sbin/$(INSTALLKERNEL) or'
   echo '                    install to $$(INSTALL_PATH) and run lilo'
-  echo '  *_defconfig     - Select default config from arch/$(ARCH)/configs'
+  echo '  *_defconfig     - Select default config from arch/powerpc/configs'
   echo ''
   echo '  Targets with <dt> embed a device tree blob inside the image'
   echo '  These targets support board with firmware that does not'
   echo '  support passing a device tree directly.  Replace <dt> with the'
-  echo '  name of a dts file from the arch/$(ARCH)/boot/dts/ directory'
+  echo '  name of a dts file from the arch/powerpc/boot/dts/ directory'
   echo '  (minus the .dts extension).'
   echo
   $(foreach cfg,$(generated_configs),
-- 
2.43.0


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

* [PATCH 2/4] powerpc/vdso: No need to undef powerpc for 64-bit build
  2023-12-06 11:55 [PATCH 1/4] powerpc/Makefile: Don't use $(ARCH) unnecessarily Michael Ellerman
@ 2023-12-06 11:55 ` Michael Ellerman
  2023-12-06 16:18   ` Segher Boessenkool
  2023-12-06 11:55 ` [PATCH 3/4] powerpc/Makefile: Default to ppc64le_defconfig when cross building Michael Ellerman
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Michael Ellerman @ 2023-12-06 11:55 UTC (permalink / raw)
  To: linuxppc-dev

The vdso Makefile adds -U$(ARCH) to CPPFLAGS for the vdso64.lds linker
script. ARCH is always powerpc, so it becomes -Upowerpc, which means
undefine the "powerpc" symbol.

But the 64-bit compiler doesn't define powerpc in the first place,
compare:

  $ gcc-5.1.0-nolibc/powerpc64-linux/bin/powerpc64-linux-gcc -m32 -E -dM - </dev/null | grep -w powerpc
  #define powerpc 1
  $ gcc-5.1.0-nolibc/powerpc64-linux/bin/powerpc64-linux-gcc -m64 -E -dM - </dev/null | grep -w powerpc
  $

So there's no need to undefine it for the 64-bit linker script.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/kernel/vdso/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile
index 0c7d82c270c3..1b93655c2857 100644
--- a/arch/powerpc/kernel/vdso/Makefile
+++ b/arch/powerpc/kernel/vdso/Makefile
@@ -71,7 +71,7 @@ AS64FLAGS := -D__VDSO64__
 targets += vdso32.lds
 CPPFLAGS_vdso32.lds += -P -C -Upowerpc
 targets += vdso64.lds
-CPPFLAGS_vdso64.lds += -P -C -U$(ARCH)
+CPPFLAGS_vdso64.lds += -P -C
 
 # link rule for the .so file, .lds has to be first
 $(obj)/vdso32.so.dbg: $(src)/vdso32.lds $(obj-vdso32) $(obj)/vgettimeofday-32.o FORCE
-- 
2.43.0


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

* [PATCH 3/4] powerpc/Makefile: Default to ppc64le_defconfig when cross building
  2023-12-06 11:55 [PATCH 1/4] powerpc/Makefile: Don't use $(ARCH) unnecessarily Michael Ellerman
  2023-12-06 11:55 ` [PATCH 2/4] powerpc/vdso: No need to undef powerpc for 64-bit build Michael Ellerman
@ 2023-12-06 11:55 ` Michael Ellerman
  2023-12-06 11:55 ` [PATCH 4/4] powerpc/Makefile: Auto detect cross compiler Michael Ellerman
  2023-12-21 10:38 ` [PATCH 1/4] powerpc/Makefile: Don't use $(ARCH) unnecessarily Michael Ellerman
  3 siblings, 0 replies; 8+ messages in thread
From: Michael Ellerman @ 2023-12-06 11:55 UTC (permalink / raw)
  To: linuxppc-dev

If the kernel is being cross compiled, there is no information from
uname on which defconfig is most appropriate, so the Makefile defaults
to ppc64.

However these days almost all distros that support powerpc are little
endian, so it's more likely that defaulting to ppc64le_defconfig will
produce something useful for a user.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index b0bc17c35ed7..48c06f5a0dc1 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -16,9 +16,9 @@ HAS_BIARCH	:= $(call cc-option-yn, -m32)
 CROSS32_COMPILE ?=
 
 # If we're on a ppc/ppc64/ppc64le machine use that defconfig, otherwise just use
-# ppc64_defconfig because we have nothing better to go on.
+# ppc64le_defconfig because we have nothing better to go on.
 uname := $(shell uname -m)
-KBUILD_DEFCONFIG := $(if $(filter ppc%,$(uname)),$(uname),ppc64)_defconfig
+KBUILD_DEFCONFIG := $(if $(filter ppc%,$(uname)),$(uname),ppc64le)_defconfig
 
 new_nm := $(shell if $(NM) --help 2>&1 | grep -- '--synthetic' > /dev/null; then echo y; else echo n; fi)
 
-- 
2.43.0


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

* [PATCH 4/4] powerpc/Makefile: Auto detect cross compiler
  2023-12-06 11:55 [PATCH 1/4] powerpc/Makefile: Don't use $(ARCH) unnecessarily Michael Ellerman
  2023-12-06 11:55 ` [PATCH 2/4] powerpc/vdso: No need to undef powerpc for 64-bit build Michael Ellerman
  2023-12-06 11:55 ` [PATCH 3/4] powerpc/Makefile: Default to ppc64le_defconfig when cross building Michael Ellerman
@ 2023-12-06 11:55 ` Michael Ellerman
  2023-12-06 16:25   ` Segher Boessenkool
  2023-12-21 10:38 ` [PATCH 1/4] powerpc/Makefile: Don't use $(ARCH) unnecessarily Michael Ellerman
  3 siblings, 1 reply; 8+ messages in thread
From: Michael Ellerman @ 2023-12-06 11:55 UTC (permalink / raw)
  To: linuxppc-dev

If no cross compiler is specified, try to auto detect one.

Look for various combinations, matching:
  powerpc(64(le)?)?(-unknown)?-linux(-gnu)?-

There are more possibilities, but the above is known to find a compiler
on Fedora and Ubuntu (which use linux-gnu-), and also detects the
kernel.org cross compilers (which use linux-).

This allows cross compiling with simply:

 # Ubuntu
 $ sudo apt install gcc-powerpc-linux-gnu
 # Fedora
 $ sudo dnf install gcc-powerpc64-linux-gnu

 $ make ARCH=powerpc defconfig
 $ make ARCH=powerpc -j 4

Inspired by arch/parisc/Makefile.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/Makefile | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 48c06f5a0dc1..051247027da0 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -10,6 +10,17 @@
 # Rewritten by Cort Dougan and Paul Mackerras
 #
 
+ifdef cross_compiling
+  ifeq ($(CROSS_COMPILE),)
+    # Auto detect cross compiler prefix.
+    # Look for: (powerpc(64(le)?)?)(-unknown)?-linux(-gnu)?-
+    CC_ARCHES := powerpc powerpc64 powerpc64le
+    CC_SUFFIXES := linux linux-gnu unknown-linux-gnu
+    CROSS_COMPILE := $(call cc-cross-prefix, $(foreach a,$(CC_ARCHES), \
+                       $(foreach s,$(CC_SUFFIXES),$(a)-$(s)-)))
+  endif
+endif
+
 HAS_BIARCH	:= $(call cc-option-yn, -m32)
 
 # Set default 32 bits cross compilers for vdso and boot wrapper
-- 
2.43.0


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

* Re: [PATCH 2/4] powerpc/vdso: No need to undef powerpc for 64-bit build
  2023-12-06 11:55 ` [PATCH 2/4] powerpc/vdso: No need to undef powerpc for 64-bit build Michael Ellerman
@ 2023-12-06 16:18   ` Segher Boessenkool
  0 siblings, 0 replies; 8+ messages in thread
From: Segher Boessenkool @ 2023-12-06 16:18 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linuxppc-dev

On Wed, Dec 06, 2023 at 10:55:46PM +1100, Michael Ellerman wrote:
> But the 64-bit compiler doesn't define powerpc in the first place,

Yes, only __powerpc__ (and __powerpc64__) :-)


Segher

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

* Re: [PATCH 4/4] powerpc/Makefile: Auto detect cross compiler
  2023-12-06 11:55 ` [PATCH 4/4] powerpc/Makefile: Auto detect cross compiler Michael Ellerman
@ 2023-12-06 16:25   ` Segher Boessenkool
  2023-12-07  4:48     ` Michael Ellerman
  0 siblings, 1 reply; 8+ messages in thread
From: Segher Boessenkool @ 2023-12-06 16:25 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linuxppc-dev

On Wed, Dec 06, 2023 at 10:55:48PM +1100, Michael Ellerman wrote:
> Look for various combinations, matching:
>   powerpc(64(le)?)?(-unknown)?-linux(-gnu)?-
> 
> There are more possibilities, but the above is known to find a compiler
> on Fedora and Ubuntu (which use linux-gnu-), and also detects the
> kernel.org cross compilers (which use linux-).

$ sh ../config.sub powerpc64-linux
powerpc64-unknown-linux-gnu

I am very very lazy, so buildall uses short names everywhere :-)

Btw, can you build the kernel for a config that differs in 32/64 or
BE/LE with the default your compiler uses?  There is no reason this
shouldn't work (you don't use any system libraries), but you need to
use the correct compiler command-line flags for that always.

Acked-by: Segher Boessenkool <segher@kernel.crashing.org>


Segher

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

* Re: [PATCH 4/4] powerpc/Makefile: Auto detect cross compiler
  2023-12-06 16:25   ` Segher Boessenkool
@ 2023-12-07  4:48     ` Michael Ellerman
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Ellerman @ 2023-12-07  4:48 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: linuxppc-dev

Segher Boessenkool <segher@kernel.crashing.org> writes:
> On Wed, Dec 06, 2023 at 10:55:48PM +1100, Michael Ellerman wrote:
>> Look for various combinations, matching:
>>   powerpc(64(le)?)?(-unknown)?-linux(-gnu)?-
>> 
>> There are more possibilities, but the above is known to find a compiler
>> on Fedora and Ubuntu (which use linux-gnu-), and also detects the
>> kernel.org cross compilers (which use linux-).
>
> $ sh ../config.sub powerpc64-linux
> powerpc64-unknown-linux-gnu
>
> I am very very lazy, so buildall uses short names everywhere :-)

I used to use just ppc64-gcc :)

I can add more variants but didn't want to add too many unless someone
is actually using them.

> Btw, can you build the kernel for a config that differs in 32/64 or
> BE/LE with the default your compiler uses?  There is no reason this
> shouldn't work (you don't use any system libraries), but you need to
> use the correct compiler command-line flags for that always.

Yes it should work. I've tested at least ppc64le/ppc64/ppc defconfigs.

There have been bugs in the past but AFAIK we have fixed all of them,
though there's probably some still lurking for more obscure configs.

> Acked-by: Segher Boessenkool <segher@kernel.crashing.org>

Thanks.

cheers

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

* Re: [PATCH 1/4] powerpc/Makefile: Don't use $(ARCH) unnecessarily
  2023-12-06 11:55 [PATCH 1/4] powerpc/Makefile: Don't use $(ARCH) unnecessarily Michael Ellerman
                   ` (2 preceding siblings ...)
  2023-12-06 11:55 ` [PATCH 4/4] powerpc/Makefile: Auto detect cross compiler Michael Ellerman
@ 2023-12-21 10:38 ` Michael Ellerman
  3 siblings, 0 replies; 8+ messages in thread
From: Michael Ellerman @ 2023-12-21 10:38 UTC (permalink / raw)
  To: linuxppc-dev, Michael Ellerman

On Wed, 06 Dec 2023 22:55:45 +1100, Michael Ellerman wrote:
> There's no need to use $(ARCH) for references to the arch directory in
> the source tree, it is always arch/powerpc.
> 
> 

Applied to powerpc/next.

[1/4] powerpc/Makefile: Don't use $(ARCH) unnecessarily
      https://git.kernel.org/powerpc/c/dc420877b5bd92db5d80df6b117c7a0f987290af
[2/4] powerpc/vdso: No need to undef powerpc for 64-bit build
      https://git.kernel.org/powerpc/c/42449052c94f22e18e01d71147d8fd75cb58132a
[3/4] powerpc/Makefile: Default to ppc64le_defconfig when cross building
      https://git.kernel.org/powerpc/c/22f17b02f88b48c01d3ac38d40d2b0b695ab2d10
[4/4] powerpc/Makefile: Auto detect cross compiler
      https://git.kernel.org/powerpc/c/402928b58ec62b42b11992a7b51ff2f56ed65a18

cheers

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

end of thread, other threads:[~2023-12-21 10:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-06 11:55 [PATCH 1/4] powerpc/Makefile: Don't use $(ARCH) unnecessarily Michael Ellerman
2023-12-06 11:55 ` [PATCH 2/4] powerpc/vdso: No need to undef powerpc for 64-bit build Michael Ellerman
2023-12-06 16:18   ` Segher Boessenkool
2023-12-06 11:55 ` [PATCH 3/4] powerpc/Makefile: Default to ppc64le_defconfig when cross building Michael Ellerman
2023-12-06 11:55 ` [PATCH 4/4] powerpc/Makefile: Auto detect cross compiler Michael Ellerman
2023-12-06 16:25   ` Segher Boessenkool
2023-12-07  4:48     ` Michael Ellerman
2023-12-21 10:38 ` [PATCH 1/4] powerpc/Makefile: Don't use $(ARCH) unnecessarily Michael Ellerman

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