Как собрать ядро linux под arm
Операционная система linux часто используется для встраиваемых (они же embedded) устройств, которые в свою очередь часто построены на основе контроллеров с архитектурой ARM.
Исходный код
Скачать исходный код ядра linux можно с http://git.kernel.org
Например, если использовать код из проекта project:
После того как исходники будут скачаны, заходим в директорию с исходным кодом ядра linux.
Для того что бы отделить результат компиляции от исходного кода, создаем директорию build
Компилятор
Распаковываем ( например в /home/user ):
И устанавливаем переменную PATH:
Задаем переменные окружения для компиляции:
Конфигурирование ядра linux
Если нужная конфигурация уже существует ( например arch/arm/configs/colibri_pxa320_defconfig ), то выполняем:
Если необходимо создать свою конфигурацию ядра linux, или изменить существующую то запускаем:
и выбираем необходимые опции. Опции могут быть вкомпилированны в ядро или подгружаться как модули. В первом случае перед соответствующим пунктом меню отображается [*] , во втором [M].
Компиляция ядра linux
Что бы скомпилировать ядро надо выполнить команду:
Когда сборка ядра linux будет закончена, оно будет лежать в ../build/arch/arm/boot/uImage
Сброка модулей ядра linux
Если какие-то опции ядра были включены как модули, то их тоже надо скомпилировать
Что бы изменить директорию (папку) в которую modules_install установит модули, указываем путь, используя переменную INSTALL_MOD_PATH.
В дальнейшем, что бы положить модули ядра на устройство, надо просто скопировать, все что лежит в директории /home/user/tmp/modules в корень файловой системы устройства. При этом важно сохранить структуру каталогов, самый просто способ — упаковать папку, а затем разархивировать ее на приборе.
Очистка проекта
Что бы удалить все файлы, созданные при компиляции:
Если же необходимо удалить файлы, полученные при конфигурации ядра linux, нам поможет Мистер Пропер 🙂
ARM Linux 2.6 and upperВ¶
Compilation of kernelВ¶
In order to compile ARM Linux, you will need a compiler capable of generating ARM ELF code with GNU extensions. GCC 3.3 is known to be a good compiler. Fortunately, you needn’t guess. The kernel will report an error if your compiler is a recognized offender.
To build ARM Linux natively, you shouldn’t have to alter the ARCH = line in the top level Makefile. However, if you don’t have the ARM Linux ELF tools installed as default, then you should change the CROSS_COMPILE line as detailed below.
If you wish to cross-compile, then alter the following lines in the top level make file:
Do a вЂmake config’, followed by вЂmake Image’ to build the kernel (arch/arm/boot/Image). A compressed image can be built by doing a вЂmake zImage’ instead of вЂmake Image’.
Bug reports etcВ¶
Please send patches to the patch system. For more information, see http://www.arm.linux.org.uk/developer/patches/info.php Always include some explanation as to what the patch does and why it is needed.
When sending bug reports, please ensure that they contain all relevant information, eg. the kernel messages that were printed before/during the problem, what you were doing, etc.
Include filesВ¶
Several new include directories have been created under include/asm-arm, which are there to reduce the clutter in the top-level directory. These directories, and their purpose is listed below:
arch-* | machine/platform specific header files |
hardware | driver-internal ARM specific data structures/definitions |
mach | descriptions of generic ARM to specific machine interfaces |
proc-* | processor dependent header files (currently only two categories) |
Machine/Platform supportВ¶
The ARM tree contains support for a lot of different machine types. To continue supporting these differences, it has become necessary to split machine-specific parts by directory. For this, the machine category is used to select which directories and files get included (we will use $(MACHINE) to refer to the category)
To this end, we now have arch/arm/mach-$(MACHINE) directories which are designed to house the non-driver files for a particular machine (eg, PCI, memory management, architecture definitions etc). For all future machines, there should be a corresponding arch/arm/mach-$(MACHINE)/include/mach directory.
ModulesВ¶
Although modularisation is supported (and required for the FP emulator), each module on an ARM2/ARM250/ARM3 machine when is loaded will take memory up to the next 32k boundary due to the size of the pages. Therefore, is modularisation on these machines really worth it?
However, ARM6 and up machines allow modules to take multiples of 4k, and as such Acorn RiscPCs and other architectures using these processors can make good use of modularisation.
ADFS Image filesВ¶
You can access image files on your ADFS partitions by mounting the ADFS partition, and then using the loopback device driver. You must have losetup installed.
Please note that the PCEmulator DOS partitions have a partition table at the start, and as such, you will have to give вЂ-o offset’ to losetup.
Request to developersВ¶
When writing device drivers which include a separate assembler file, please include it in with the C file, and not the arch/arm/lib directory. This allows the driver to be compiled as a loadable module without requiring half the code to be compiled into the kernel image.
In general, try to avoid using assembler unless it is really necessary. It makes drivers far less easy to port to other hardware.
ST506 hard drivesВ¶
The ST506 hard drive controllers seem to be working fine (if a little slowly). At the moment they will only work off the controllers on an A4x0’s motherboard, but for it to work off a Podule just requires someone with a podule to add the addresses for the IRQ mask and the HDC base to the source.
As of 31/3/96 it works with two drives (you should get the ADFS *configure harddrive set to 2). I’ve got an internal 20MB and a great big external 5.25” FH 64MB drive (who could ever want more 🙂 ).
I’ve just got 240K/s off it (a dd with bs=128k); thats about half of what RiscOS gets; but it’s a heck of a lot better than the 50K/s I was getting last week 🙂
Known bug: Drive data errors can cause a hang; including cases where the controller has fixed the error using ECC. (Possibly ONLY in that case…hmm).
1772 FloppyВ¶
CONFIG_MACH_ and CONFIG_ARCH_ В¶
A change was made in 2003 to the macro names for new machines. Historically, CONFIG_ARCH_ was used for the bonafide architecture, e.g. SA1100, as well as implementations of the architecture, e.g. Assabet. It was decided to change the implementation macros to read CONFIG_MACH_ for clarity. Moreover, a retroactive fixup has not been made because it would complicate patching.
Previous registrations may be found online.
Kernel entry (head.S)В¶
The initial entry into the kernel is via head.S, which uses machine independent code. The machine is selected by the value of вЂr1’ on entry, which must be kept unique.
Due to the large number of machines which the ARM port of Linux provides for, we have a method to manage this which ensures that we don’t end up duplicating large amounts of code.
We group machine (or platform) support code into machine classes. A class typically based around one or more system on a chip devices, and acts as a natural container around the actual implementations. These classes are given directories — arch/arm/mach- — which contain the source files and include/mach/ to support the machine class.
For example, the SA1100 class is based upon the SA1100 and SA1110 SoC devices, and contains the code to support the way the on-board and off- board devices are used, or the device is setup, and provides that machine specific “personality.”
For platforms that support device tree (DT), the machine selection is controlled at runtime by passing the device tree blob to the kernel. At compile-time, support for the machine type must be selected. This allows for a single multiplatform kernel build to be used for several machine types.
For platforms that do not use device tree, this machine selection is controlled by the machine type ID, which acts both as a run-time and a compile-time code selection method. You can register a new machine via the web site at:
Note: Please do not register a machine type for DT-only platforms. If your platform is DT-only, you do not need a registered machine type.
Linux Kernel
Overview
Arm is an active maintainer and contributor to the Linux Kernel project, together with Linaro and a large number of partner companies and independent developers.
Arm maintains the arch/arm64 Linux Kernel tree, for all Arm 64-bit enabled systems and it actively contributes to the arch/arm tree for all legacy Arm 32-bit systems (Armv7 and Armv8 running at AArch32).
Arm also maintains the KVM/arm and KVM/arm64 ports of the popular Kernel Virtual Machine (KVM) hypervisor.
Arm develops and maintains the fundamental Arm Architecture enablement for the Linux kernel.
All the information regarding the Linux Kernel can be found in the official Kernel.org website.
Kernel versions highlights
Some arm64 highlights from recently released Linux Kernel versions
FTRACE_WITH_REGS support for arm64
Perf updates for arm64
GICv3 optimisation to avoid a heavy barrier when accessing the ICC_PMR_EL1 register
PAN bypass mitigation: disable execute-only permissions for user applications
KVM: Report stolen time to guest
KVM: Allow injection of data aborts from userspace
KVM: GICv4 performance improvements
Workaround for Neoverse-N1 erratum #1542419
Workaround for Cortex-A57 and A72 erratum #1319367
Armv8.2-LVA: 52-bit virtual addressing in the kernel
New ABI to allow tagged user pointers to be dereferenced by syscalls
Support for the PPTT «thread» flag introduced by ACPI 6.3
Improve in-kernel LSE atomics implementation
SCMI v2.0 fastchannel support for performance protocol
KVM: New ITS translation cache
KVM: Allow up to 512 CPUs to be supported with GICv3
Support for Arm64 Syscall emulation via PTRACE_SYSEMU
Support for Arm v8.5-CondM Condition code manipulation
Support for Arm v8.5-FRINT Floating point to Integer
Statistical Profiling Extensions (SPE) enabled on ACPI platforms
KVM: Handle Neoverse N1 erratum #1349291
KVM: Support for chained PMU counters in guests
KVM: Allow side-channel mitigation status (Spectre Var2/Var4) to be migrated
SVE2 exposed to user-space through HWCAP
Support for ARMv8.5-DCCVAP Data Cache Clean to Point of Deep Persistence
CPU timer erratum workaround (Neoverse-N1 #1188873 & #1418040)
Introduce perf PMU driver for the SMMUv3 performance counters
Populating sysfs with Spectre/Meltdown mitigations information
KVM: Support for SVE in Guests
KVM: Support for ARMv8.3 Pointer Authentication in Guests
KVM: Discrimination of PMU counters between host and guests
Support for arm64 pseudo NMI using GICv3 interrupt priorities
Support for ARMv8.3 Pointer Authentication ptrace regsets for key management
Uaccess macros clean-up
KVM: pre-nested virtualization code rework
Support for ARMv8.3 Pointer Authentication in userspace
Support for ARMv8.2-LVA: 52-bit virtual addressing for userspace (kernel remains 48-bit)
Support for the new ‘SB’ Speculation Barrier instruction (ARMv8.0-SB, introduced as part of the ARMv8.5 Extension)
Support for per-thread stack canaries
Support for kexec_file_load() for secure boot of a kexec payload but also for kexec performances improvement
KPTI whitelisting of Cortex-A CPUs unaffected by Meltdown
Patch in LSE atomics for per-cpu atomic operations
Initial support for memory hotplug
KVM: Large PUD support for HugeTLB
EAS (Energy Aware Scheduling)
Support for the new ARMv8.5 PSTATE.SSBS bit (ARMv8.0-SpecRest), used to mitigate Spectre-v4 dynamically without trapping to EL3 firmware
Support for ARMv8.2-TTCNP Common Not Private translations allowing threads of the same CPU to share the TLB entries
Core mmu_gather changes which allow tracking the levels of page-table being cleared together with the arm64 low-level flushing routines
Optimise emulation of MRS instructions to ID_* registers on ARMv8.4
Trap WFI instruction executed in user space
Arm Smmuv3 support non-strict mode
KVM: Improved guest IPA space support (32 to 52 bits)
KVM: RAS event delivery for 32bit
Support for qspinlock on arm64, replacing ticket lock code
GICv3 updates and LPI allocation refactoring
Support for the GCC «stackleak» plugin
Kexec/kdump support on systems booting with ACPI
Support for chained PMU counters, allowing 64-bit event counters to be constructed on current CPUs
KVM: Support for Group0 interrupts in guests
Support for arm64 SSBD (Speculative Store Bypass Disable) Spectrev4 mitigation using SMC firmware call to set a hardware defined bit
ACPI PPTT (Processor Properties Topology Table) parsing support and enable the feature for arm64
Turn LSE atomics on by default in Kconfig
Support for qspinlock in the generic codebase
KVM: Lazy context-switching of FPSIMD registers on arm64
KVM: Allow virtual redistributors to be part of two or more MMIO ranges