You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WIP: Add Build instructions for compiling a 64-Bit kernel (raspberrypi#1653)
* Declare build instructions as 32-bit
* Early 64-Bit guide. Needs Testing.
* Added some formatting for the config and build
* Move some instructions for CI that apply to both arches
* Added some better seperators
* Looks weird to read when generated into a web format so it has been clarified
* Clarify headings and add seperators
* Undo "Add Seperators" as it did not format well as I wished
* Use correct pi 3 defconfig
* Remove bad comment from code
* Fix instructions after following guide to compile for Pi 3
* Use distro cross-compilers in kernel build
* Fixed change after testing installation. Compiling is still the same
* Remove binutils requirment already as it is a dep for gcc-arm
* Remove zlib1g from instructions as mentioned in comments.
* Modifed configuring the kernel build to add instructions for the 64bit build
* Remove required packages as it is already in meta-package as rec
* Revert "Remove required packages as it is already in meta-package as rec"
This reverts commit d721932.
* remove ccache instructions for when we were using the tools repo
* combine dependencies and toolchain install instructions
* Remove addition to title
* Remove extra colon
* Lowercase *-Bit to *-bit
* Add README from build
* Fixed Capitialization for reviewed change
* Partially Undo Capitialization Fix
* Updated header to help user choose which compiling guide to use
* Revert "Updated header to help user choose which compiling guide to use"
This reverts commit 12fb61d.
* Lowercase "Bit" identifier
* New Header provided from comments
Copy file name to clipboardExpand all lines: linux/kernel/building.md
+68-6Lines changed: 68 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,13 @@
1
1
# Kernel building
2
2
3
-
There are two main methods for building the kernel. You can build locally on a Raspberry Pi, which will take a long time; or you can cross-compile, which is much quicker, but requires more setup.
3
+
The default compilers and linkers that come with an OS are configured to build executables to run on that OS - they are native tools - but that doesn't have to be the case. A cross-compiler is configured to build code for a target other than the one running the build process, and using it is called cross-compilation.
4
+
5
+
Cross-compilation of the Raspberry Pi kernel is useful for two reasons:
6
+
7
+
* it allows a 64-bit kernel to be built using a 32-bit OS, and vice versa, and
8
+
* even a modest laptop can cross-compile a Pi kernel significantly faster than the Pi itself.
9
+
10
+
The instructions below are divided into native builds and cross-compilation; choose the section appropriate for your situation - although there are many common steps between the two, there are also some important differences.
**Note**: On a Raspberry Pi 2/3/4, the `-j4` flag splits the work between all four cores, speeding up compilation significantly.
94
101
95
-
## Cross-compiling
102
+
## Cross-compiling
96
103
97
104
First, you will need a suitable Linux cross-compilation host. We tend to use Ubuntu; since Raspberry Pi OS is
98
105
also a Debian distribution, it means many aspects are similar, such as the command lines.
@@ -103,10 +110,21 @@ You can either do this using VirtualBox (or VMWare) on Windows, or install it di
103
110
104
111
To build the sources for cross-compilation, make sure you have the dependencies needed on your machine by executing:
105
112
```bash
106
-
sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev crossbuild-essential-armhf
113
+
sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev
107
114
```
115
+
108
116
If you find you need other things, please submit a pull request to change the documentation.
109
117
118
+
#### Install the 32-bit toolchain for a 32-bit kernel
119
+
```bash
120
+
sudo apt install crossbuild-essential-armhf
121
+
```
122
+
123
+
#### Or, install the 64-bit toolchain for a 64-bit kernel
124
+
```bash
125
+
sudo apt install crossbuild-essential-arm64
126
+
```
127
+
110
128
### Get sources
111
129
112
130
To download the minimal source tree for the current branch, run:
@@ -121,6 +139,7 @@ See [**Choosing sources**](#choosing_sources) above for instructions on how to c
121
139
122
140
Enter the following commands to build the sources and Device Tree files:
123
141
142
+
#### 32-bit configs
124
143
For Pi 1, Pi Zero, Pi Zero W, or Compute Module:
125
144
126
145
```bash
@@ -145,14 +164,36 @@ KERNEL=kernel7l
145
164
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2711_defconfig
146
165
```
147
166
148
-
Then, for all:
167
+
#### 64-bit configs
168
+
For Pi 3, Pi 3+ or Compute Module 3:
169
+
```bash
170
+
cd linux
171
+
KERNEL=kernel8
172
+
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcmrpi3_defconfig
173
+
```
149
174
175
+
For Raspberry Pi 4:
150
176
```bash
151
-
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs
177
+
cd linux
178
+
KERNEL=kernel8
179
+
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcm2711_defconfig
152
180
```
153
181
182
+
#### Build with configs
183
+
154
184
**Note**: To speed up compilation on multiprocessor systems, and get some improvement on single processor ones, use `-j n`, where n is the number of processors * 1.5. Alternatively, feel free to experiment and see what works!
155
185
186
+
##### For all 32-bit builds
187
+
```bash
188
+
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs
189
+
```
190
+
191
+
##### For all 64-bit builds
192
+
**Note**: Note the difference between Image target between 32 and 64-bit.
193
+
```bash
194
+
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image modules dtbs
195
+
```
196
+
156
197
### Install directly onto the SD card
157
198
158
199
Having built the kernel, you need to copy it onto your Raspberry Pi and install the modules; this is best done directly using an SD card reader.
@@ -190,14 +231,23 @@ sudo mount /dev/sdb6 mnt/fat32
190
231
sudo mount /dev/sdb7 mnt/ext4
191
232
```
192
233
193
-
Next, install the modules:
194
234
235
+
Next, install the kernel modules onto the SD card:
236
+
237
+
#### For 32-bit
195
238
```bash
196
239
sudo env PATH=$PATH make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=mnt/ext4 modules_install
197
240
```
198
241
242
+
#### For 64-bit
243
+
```bash
244
+
sudo env PATH=$PATH make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH=mnt/ext4 modules_install
245
+
```
246
+
199
247
Finally, copy the kernel and Device Tree blobs onto the SD card, making sure to back up your old kernel:
Another option is to copy the kernel into the same place, but with a different filename - for instance, kernel-myconfig.img - rather than overwriting the kernel.img file. You can then edit the config.txt file to select the kernel that the Pi will boot into:
Copy file name to clipboardExpand all lines: linux/kernel/configuring.md
+7-1Lines changed: 7 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,12 +22,18 @@ Once you've got everything set up and ready to go, you can compile and run the `
22
22
$ make menuconfig
23
23
```
24
24
25
-
If you're cross-compiling,:
25
+
If you're cross-compiling a 32-bit kernel:
26
26
27
27
```
28
28
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
29
29
```
30
30
31
+
Or, if you are cross-compiling a 64-bit kernel:
32
+
33
+
```
34
+
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig
35
+
```
36
+
31
37
The `menuconfig` utility has simple keyboard navigation. After a brief compilation, you'll be presented with a list of submenus containing all the options you can configure; there's a lot, so take your time to read through them and get acquainted.
32
38
33
39
Use the arrow keys to navigate, the Enter key to enter a submenu (indicated by `--->`), Escape twice to go up a level or exit, and the space bar to cycle the state of an option. Some options have multiple choices, in which case they'll appear as a submenu and the Enter key will select an option. You can press `h` on most entries to get help about that specific option or menu.
0 commit comments