BL808 Custom Linux Kernel

From OpenBouffalo
Revision as of 08:26, 14 May 2023 by Gamiee (talk | contribs) (Restoring backup, author: Hunter1753)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

When developing for the BL808 you might find yourself wanting to customise the linux kernel or create new device drivers. This guide aims to give you all the tools to do just that.

Get SDK

You can download the SDK from the GitHub Openbouffalo Buildroot Releases Page or Build from source

if you choose to download the SDK you can extract it somewhere and skip to #Relocate the SDK

Requirements (when building from source)

For this you have to have downloaded and set up the buildroot environment (up until the build step - non inclusive).

Build SDK From Source

The buildroot system has a target [SDK] to be able to develop software easily for the BL808

$ make SDK

This creates a folder called ~/buildroot_bouffalo/buildroot/output/host/ where the sdk is located

Relocate the SDK

I want the SDK to be placed on the same level as the buildroot/ and buildroot_bouffalo/ folders, thats why we use the relocate-sdk.sh script

$ cd ~/buildroot_bouffalo/
$ cp -r ~/buildroot_bouffalo/buildroot/output/host/ ~/buildroot_bouffalo/bl808-sdk/
$ cd bl808-sdk
$ ./relocate-sdk.sh

(Optional) Add Environment Name To $PS1

in the file environment-setup you can add the line

PS1="(riscv) $PS1"

to show the prefix (riscv) while this environment is active

Activate environment

To activate the environment we have to source the environment-setup file

$ source environment-setup

Get Linux Source

Normally you would fork the project and use your own version, but for the sake of this guide i will use the original repository

$ cd ~/buildroot_bouffalo/
$ git clone https://github.com/openbouffalo/linux

Checkout Correct Branch

The Repository has multiple different branches. The bl808/all branch contains all the stable drivers, the bl808/boards contains the configuration for all drivers, the other bl808/* branches are the actual drivers.

If you want to create a new driver you should base it on the bl808/boards branch if it is not dependent on other drivers (e.g. the pinctrl or dma), otherwise just base it on the respective feature branch.

The proposed branching structure can be viewed here

If you just want to configure the Kernel how you want without adding your own drivers you can just use the bl808/all branch like we do in this tutorial

$ git checkout bl808/all

Copy Defconfig

We want to use the default config for the bl808 so we copy it from arch/riscv/configs/ to the .config file

$ cp arch/riscv/configs/bl808_defconfig .config

Make Menuconfig (Optional)

Now we can start to modify the configuration of the kernel

$ make menuconfig

Build

Now that we are all set up we can build the linux kernel for the first time

$ make -jN
Note
The N in this command should be replaced by the number of cores you want to use to compile the kernel

I have 24 cores and I want to use 20 of them so I use

$ make -j20

This will compile the kernel and output it to the folder arch/riscv/boot/ and the dtses to arch/riscv/boot/dts/bouffalolab/

  • arch/riscv/boot/Image
  • arch/riscv/boot/dts/bouffalolab/bl808-pine64-ox64.dts
  • arch/riscv/boot/dts/bouffalolab/bl808-sipeed-m1s.dts

Flash

If you used the method mentioned in Ox64 Flashing you can just place these files in the root of your SD card (replace the corresponding files)