Kernel building

Original link:current page

Description:

with Raspbian Pi 3B+(install with 2018-11-13-raspbian-stretch-full.img)

$ sudo apt-get install bison flex libssl-dev git bc

The command in linux is(for linux kernel version 4.20)

git clone --depth=1 --branch rpi-4.20.y https://github.com/raspberrypi/linux

configure kernel

$ cd linux
$ KERNEL=kernel7
$ make bcm2709_defconfig

then make image

$ make -j4 zImage modules dtbs

after completion, install modules and copy files

$ sudo make modules_install
$ sudo cp arch/arm/boot/dts/*.dtb /boot/
$ sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
$ sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/
$ sudo cp arch/arm/boot/zImage /boot/$KERNEL.img

OK, now, let's reboot the pi, when completed, try command

$ uname -r
4.20.0-rc7-v7+

this means that the kernel building is success.


By the way, if you configure kernel with bcm2835_defconfig instead of bcm2709_defconfig then you may make the pi unable to boot.

I had tried cross compile the kernel on Ubuntu18.04 x64 PC, as above steps, but it failed, with many warning and error as follows:

./scripts/gcc-goto.sh: line 5: $'\r': command not found
./scripts/gcc-goto.sh: line 22: warning: here-document at line 6 delimited by end-of-file (wanted `END')
'config:6:warning: ignoring unsupported character '
'config:6:warning: ignoring unsupported character '
'config:8:warning: ignoring unsupported character '
'config:8:warning: ignoring unsupported character '
'config:10:warning: ignoring unsupported character '
'config:10:warning: ignoring unsupported character '
'cripts/Kconfig.include:11:warning: ignoring unsupported character '
'cripts/Kconfig.include:15:warning: ignoring unsupported character '
...

when openning the files with the warning or error

vi Kconfig -b

I found there is a “^M” at the end of each line
this may be related to the git configuration:

$ git config -l --global
...
core.autocrlf=true
...

then I config the git with

git config --global core.autocrlf false

to disable the autocrlf, and re-clone the source

git clone --depth=1 --branch rpi-4.20.y https://github.com/raspberrypi/linux

and complie, this time it pass without any error.
Also you can fix the errors and warnings by fixing the files with dos2unix command, as follows:

$ files=`find <kernel directory>`
$ for file in $files;do
> dos2unix $file
> done

or add a shell file

$ vim dos2unix_all.sh

input:

  if [[ $# == 0 ]]; then
    echo 
    echo "usage:$0 file|directory"
    echo
    exit
  fi
 
  files=`find $1`
 
  for file in $files; do
      dos2unix $file
  done

after saving

$ chmod a+x dos2unix_all.sh
$ ./dos2unix_all.sh <kernel directory>

the conversion may take some time.
you will get a correct kernel source.

  • Last modified: 2019/08/23 12:17