- ARM Linux 2.6 and upperВ¶
- Compilation of kernelВ¶
- Bug reports etcВ¶
- Include filesВ¶
- Machine/Platform supportВ¶
- ModulesВ¶
- ADFS Image filesВ¶
- Request to developersВ¶
- ST506 hard drivesВ¶
- 1772 FloppyВ¶
- CONFIG_MACH_ and CONFIG_ARCH_ В¶
- Kernel entry (head.S)В¶
- Как собрать ядро linux под arm
- Исходный код
- Компилятор
- Конфигурирование ядра linux
- Компиляция ядра linux
- Сброка модулей ядра linux
- Очистка проекта
- Kernel/Traditional compilation
- Contents
- Preparation
- Install the core packages
- Create a kernel compilation directory
- Download the kernel source
- Unpack the kernel source
- Kernel configuration
- Default Arch configuration
- Advanced configuration
- Compilation
- Installation
- Install the modules
- Copy the kernel to /boot directory
- Make initial RAM disk
- Automated preset method
- Manual method
- Copy System.map
- Bootloader configuration
ARM Linux 2.6 and upperВ¶
Please check for updates.
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:
machine/platform specific header files
driver-internal ARM specific data structures/definitions
descriptions of generic ARM to specific machine interfaces
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В¶
This also seems to work OK, but hasn’t been stressed much lately. It hasn’t got any code for disc change detection in there at the moment which could be a bit of a problem! Suggestions on the correct way to do this are welcome.
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 под 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, нам поможет Мистер Пропер 🙂
Источник
Kernel/Traditional compilation
This article is an introduction to building custom kernels from kernel.org sources. This method of compiling kernels is the traditional method common to all distributions. It can be, depending on your background, more complicated than using the Kernels/Arch Build System. Consider the Arch Build System tools are developed and maintained to make repeatable compilation tasks efficient and safe.
Contents
Preparation
It is not necessary (or recommended) to use the root account or root privileges (i.e. via Sudo) for kernel preparation.
Install the core packages
Install the base-devel package group, which contains necessary packages such as make and gcc . It is also recommended to install the following packages, as listed in the default Arch kernel PKGBUILD: xmlto , kmod , inetutils , bc , libelf , git , cpio , perl , tar , xz .
Create a kernel compilation directory
It is recommended to create a separate build directory for your kernel(s). In this example, the directory kernelbuild will be created in the home directory:
Download the kernel source
Download the kernel source from https://www.kernel.org. This should be the tarball ( tar.xz ) file for your chosen kernel.
It can be downloaded by simply right-clicking the tar.xz link in your browser and selecting Save Link As. , or any other number of ways via alternative graphical or command-line tools that utilise HTTP, TFTP, Rsync, or Git.
In the following command-line example, wget has been installed and is used inside the
/kernelbuild directory to obtain kernel 4.8.6:
You should also verify the correctness of the download before trusting it. First grab the signature, then use that to grab the fingerprint of the signing key, then use the fingerprint to obtain the actual signing key:
Note the signature was generated for the tar archive (i.e. extension .tar ), not the compressed .tar.xz file that you have downloaded. You need to decompress the latter without untarring it. Verify that you have xz installed, then you can proceed like so:
Do not proceed if this does not result in output that includes the string «Good signature».
If wget was not used inside the build directory, it will be necessary to move the tarball into it, e.g.
Unpack the kernel source
Within the build directory, unpack the kernel tarball:
To finalise the preparation, ensure that the kernel tree is absolutely clean; do not rely on the source tree being clean after unpacking. To do so, first change into the new kernel source directory created, and then run the make mrproper command:
Kernel configuration
This is the most crucial step in customizing the default kernel to reflect your computer’s precise specifications. Kernel configuration is set in its .config file, which includes the use of Kernel modules. By setting the options in .config properly, your kernel and computer will function most efficiently.
You can do a mixture of two things:
- Use the default Arch settings from an official kernel (recommended)
- Manually configure the kernel options (optional, advanced and not recommended)
Default Arch configuration
This method will create a .config file for the custom kernel using the default Arch kernel settings. If a stock Arch kernel is running, you can use the following command inside the custom kernel source directory:
Otherwise, the default configuration can be found online in the official Arch Linux kernel package.
Advanced configuration
There are several tools available to fine-tune the kernel configuration, which provide an alternative to otherwise spending hours manually configuring each and every one of the options available during compilation.
Those tools are:
- make menuconfig : Command-line ncurses interface superseded by nconfig
- make nconfig : Newer ncurses interface for the command-line
- make xconfig : User-friendly graphical interface that requires packagekit-qt5 to be installed as a dependency. This is the recommended method — especially for less experienced users — as it is easier to navigate, and information about each option is also displayed.
- make gconfig : Graphical configuration similar to xconfig but using gtk. This requires gtk2 , glib2 and libgladeAUR .
The chosen method should be run inside the kernel source directory, and all will either create a new .config file, or overwrite an existing one where present. All optional configurations will be automatically enabled, although any newer configuration options (i.e. with an older kernel .config ) may not be automatically selected.
Once the changes have been made save the .config file. It is a good idea to make a backup copy outside the source directory. You may need to do this multiple times before you get all the options right.
If unsure, only change a few options between compilations. If you cannot boot your newly built kernel, see the list of necessary config items here.
Running lspci -k # from liveCD lists names of kernel modules in use. Most importantly, you must maintain cgroups support. This is necessary for systemd. For more detailed information, see Gentoo:Kernel/Gentoo Kernel Configuration Guide and Gentoo:Intel#Kernel or Gentoo:Ryzen#Kernel for Intel or AMD Ryzen processors.
Compilation
Compilation time will vary from as little as fifteen minutes to over an hour, depending on your kernel configuration and processor capability. Once the .config file has been set for the custom kernel, within the source directory run the following command to compile:
Installation
Install the modules
Once the kernel has been compiled, the modules for it must follow. First build the modules:
Then install the modules. As root or with root privileges, run the following command to do so:
This will copy the compiled modules into /lib/modules/ — . For example, for kernel version 4.8 installed above, they would be copied to /lib/modules/4.8.6-ARCH . This keeps the modules for individual kernels used separated.
Copy the kernel to /boot directory
The kernel compilation process will generate a compressed bzImage (big zImage) of that kernel, which must be copied to the /boot directory and renamed in the process. Provided the name is prefixed with vmlinuz- , you may name the kernel as you wish. In the examples below, the installed and compiled 4.8 kernel has been copied over and renamed to vmlinuz-linux48 :
Make initial RAM disk
If you do not know what making an initial RAM disk is, see Initramfs on Wikipedia and mkinitcpio.
Automated preset method
An existing mkinitcpio preset can be copied and modified so that the custom kernel initramfs images can be generated in the same way as for an official kernel. This is useful where intending to recompile the kernel (e.g. where updated). In the example below, the preset file for the stock Arch kernel will be copied and modified for kernel 4.8, installed above.
First, copy the existing preset file, renaming it to match the name of the custom kernel specified as a suffix to /boot/vmlinuz- when copying the bzImage (in this case, linux48 ):
Second, edit the file and amend for the custom kernel. Note (again) that the ALL_kver= parameter also matches the name of the custom kernel specified when copying the bzImage :
Finally, generate the initramfs images for the custom kernel in the same way as for an official kernel:
Manual method
Rather than use a preset file, mkinitcpio can also be used to generate an initramfs file manually. The syntax of the command is:
- -k ( —kernel ): Specifies the modules to use when generating the initramfs image. The name will be the same as the name of the custom kernel source directory (and the modules directory for it, located in /usr/lib/modules/ ).
- -g ( —generate ): Specifies the name of the initramfs file to generate in the /boot directory. Again, using the naming convention mentioned above is recommended.
For example, the command for the 4.8 custom kernel installed above would be:
Copy System.map
The System.map file is not required for booting Linux. It is a type of «phone directory» list of functions in a particular build of a kernel. The System.map contains a list of kernel symbols (i.e function names, variable names etc) and their corresponding addresses. This «symbol-name to address mapping» is used by:
- Some processes like klogd, ksymoops, etc.
- By OOPS handler when information has to be dumped to the screen during a kernel crash (i.e info like in which function it has crashed).
If your /boot is on a filesystem which supports symlinks (i.e., not FAT32), copy System.map to /boot , appending your kernel’s name to the destination file. Then create a symlink from /boot/System.map to point to /boot/System.map- :
After completing all steps above, you should have the following 3 files and 1 soft symlink in your /boot directory along with any other previously existing files:
- Kernel: vmlinuz-
- Initramfs: Initramfs- .img
- System Map: System.map-
- System Map kernel symlink
Bootloader configuration
Add an entry for your new kernel in your bootloader’s configuration file. See Arch boot process#Feature comparison for possible boot loaders, their wiki articles and other information.
Источник