1

I'm new to embedded linux and just started building a custom kernel for raspberry 4 board. There are several tutorials on how to compile linux kernel for specific boards. To my understanding I can specify the cpu type and toolchain as parameters to make command with ARCH and CROSS_COMPILE but I wonder how compiler recognizes for which specific ARM architecture (ARMv7,ARMv8 etc...) I want to get a kernel image.

sepp2k
  • 363,768
  • 54
  • 674
  • 675
mkurus
  • 13
  • 2
  • 1
    The compiler defaults to a base set of ARM instructions, which can make the resulting image portable. The Linux **man** page for **gcc** mentions `-march=`, `-mtune=`, and `-mcpu=` as options that can specify/tune the generated instructions. See https://stackoverflow.com/questions/40442218/how-to-pass-compiler-options-during-linux-kernel-compilation You could also custom-build a toolchain for a specific sub-arch and/or processor type, to ensure that all code for a project is consistently compiled with the desired optimizations. – sawdust Aug 26 '21 at 21:05
  • The compiler does not know what architecture your product needs you have to tell it. If the question is how does the compiler know what code to generate for a particular architecture, that information is in the compiler code itself. – old_timer Aug 28 '21 at 05:41

1 Answers1

1

Since Armv7a and Armv8a architectures use different/incompatible instructions sets, the compiler you will use will be specific to one of the Armv7a/Armv8a architectures.

It will therefore not need to 'know' for which architecture it is compiling your kernel for, because it will have no choice.

Your 'make' commands will have to begin with one these statements:

# Armv7a/Aarch32/32 bit Arm Linux kernel
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf-  ... 

# Armv8a/Aarch64/64 bit Arm Linux kernel
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu-  ...

All different combinations of ARCH/CROSS_COMPILE will not work.

Please note that the exact name of for toolchains may vary slightly - I used the Arm toolchains triplets for the purpose of this answer.

Frant
  • 5,382
  • 1
  • 16
  • 22