WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Community thread on building a RPi2 kernel  (Read 13831 times)

Offline sbp

  • Sr. Member
  • ****
  • Posts: 429
    • piCorePlayer homepage
Community thread on building a RPi2 kernel
« on: February 22, 2015, 03:54:38 PM »
Hi I just started this thread in order to collect all the info we collect on how to build a kernel/piCore for RPi2

I have the build a 3.18.7 kernel which boots fine.
I build directly on the RPi2 it took about three hours.

Info:
1. You can have two kernels on the boot section.
    kernel.img will be used if booting from a RPi and kernel7.img will be used by RPi2.
     

2. Initramfs can be loaded like this:    "initramfs piCore3187mm.gz followkernel"  in the config.txt file

3. I was thinking that if I made the uname similar in both kernel then it should be able to use the same initramfs file.
It seems almost to work -  except for some sound modules:

Code: [Select]
modprobe: can't load module snd (kernel.tclocal/kernel/sound/core/snd.ko: Invalid module format
modprobe: can't load module reg_map_mmio (kernel/drivers/base/regmap/regmap-mmio.ko): Invalid module format
modprobe: can't load module regmap_I2c (kernel/drivers/base/regmap/regmap-I2c.ko): Invalid module format

So for now sound is not working.
And if I can't fix this we will have to use two separate initramfs files so that means two separate piCore images

Bela - would it help to have these modules build into the kernel instead of having them as modules?

Please report all your findings here which could help to build for the RPi2

Steen
« Last Edit: February 22, 2015, 03:56:20 PM by sbp »

Offline sbp

  • Sr. Member
  • ****
  • Posts: 429
    • piCorePlayer homepage
Re: Community thread on building a RPi2 kernel
« Reply #1 on: February 22, 2015, 04:55:54 PM »
Could the problem be caused by using different versions of GCC compiler?

The kernel.img (for the RPi) was build using a cross-compiler as was the initramfs file on a Debian based computer.

The kernel7.img (for the RPi2) was build natively on the RPi2.

Is that a problem?

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Community thread on building a RPi2 kernel
« Reply #2 on: February 22, 2015, 07:43:41 PM »
Steen: It is not cleat what are you doing... :(
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline sbp

  • Sr. Member
  • ****
  • Posts: 429
    • piCorePlayer homepage
Re: Community thread on building a RPi2 kernel
« Reply #3 on: February 23, 2015, 01:52:40 AM »
Sorry - I will try to explain better.

I would see if it was possible to build one piCore image that could be used in both a new RPi2 as well as in the old RPi's. Something like the newer raspbian versions are able to do.

Therefore I made two kernels: kernel.img (for the old RPI) and kernel7.img (for the new RPi2.
These two kernels were both placed in the boot partition, and when booting in an old RPi it will boot using kernel.img whereas when booting in a RPi2 it will boot from kernel7.img.

This is working fine - it automatically boots from the correct kernel and then start loading the initramfs file.

Next I wanted to use the same initramfs file in both a RPi and RPi2.
Therefore when I build the kernel.img and kernel7.img I used the same localversion name (-piCore). So inside the initramfs it links back to 3.18.7-piCore which is correct for both kernels.

I thought that it should be possible because RPi2 are able to execute armv6 code and essentially that is how a single raspbian image can be used in both RPi versions.

But somehow it seems like going the TinyCore way we have some kernel stuff (which needs to be RPi or RPi2 specific) put into the initramfs. Therefore, when loading modules build for RPi on a RPi2 kernel we get into trouble.

Steen

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Community thread on building a RPi2 kernel
« Reply #4 on: February 23, 2015, 02:12:55 AM »
It doesn't work. You have two different kernels. They differ not only in target ARM code but built for different hardware. each kernel require its own kernel modules two work. If you want to follow the Raspbian way, you need different unames. In 6.0alpha2 for RPi it is 3.18.6-piCore+, for RPi2 it is 3.18.6_v7-piCore+. You can have both in initrd without conflict and it will work. However one of them is not used like one of the kernels which is against the Core philosophy to have unneded. Also kernel.tclocal must point to the proper directory. To adjust it during startup require some modifications. Next the issue is /tce. No problem as long as you have apps for armv6 only but armv7 build apps may fail on armv6.

To summarize it is not supported.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Community thread on building a RPi2 kernel
« Reply #5 on: February 23, 2015, 04:11:59 AM »

I build directly on the RPi2 it took about three hours.


Just built 3.18.7 on RPi2. It took 1h 32 min including building kernel, modules, device tree and kernel headers using -j4 and performance governor.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline sbp

  • Sr. Member
  • ****
  • Posts: 429
    • piCorePlayer homepage
Re: Community thread on building a RPi2 kernel
« Reply #6 on: February 23, 2015, 04:52:25 AM »
Hi Bela

Thanks for the info - could you please see if I could do it in a better way:

I used a  clean raspbian with the gcc already installed (I think it is version 4.6.3)

1. Fetching via github the source.
2. make mrproper
3. Copy your ".config" file from the RPi2 link you provided
4. make ARCH=arm menuconfig   -  and save it
5. make ARCH=arm -j4

Then wait.
I did not add any configuration flags to the compiler (mostly because I did not know how to do that)

If I want to make a kernel for the older RPi's on the RPi2 can I then configure the compiler to that?
And what would the exact command for that look like?

Steen

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Community thread on building a RPi2 kernel
« Reply #7 on: February 23, 2015, 05:26:13 AM »
Hi

never used Raspbian to build kernel. For crosscompilation my script:

Code: [Select]
#!/bin/sh

export CCPREFIX=/home/mb/x-tools/armv6-rpi-linux-gnueabi/bin/armv6-rpi-linux-gnueabi-

export CFLAGS="-march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp"

#make ARCH=arm CROSS_COMPILE=${CCPREFIX} -j4  oldconfig
#make ARCH=arm CROSS_COMPILE=${CCPREFIX} -j4  menuconfig
make ARCH=arm CROSS_COMPILE=${CCPREFIX} -j4  bzImage
make ARCH=arm CROSS_COMPILE=${CCPREFIX} -j4  modules
make ARCH=arm CROSS_COMPILE=${CCPREFIX} -j4  INSTALL_MOD_PATH=/tmp/mmm3186  INSTALL_MOD_STRIP=1 modules_install
make ARCH=arm CROSS_COMPILE=${CCPREFIX} -j4  INSTALL_HDR_PATH=/tmp/hdr3186  headers_install
make ARCH=arm CROSS_COMPILE=${CCPREFIX} -j4  dtbs

Building it native in piCore the only difference to comment

export CCPREFIX=/home/mb/x-tools/ar......

as no crosscompiler used.

For RPi2 use

export CFLAGS="-march=armv7-a -mtune=cortex-a7 -mfpu=neon"
« Last Edit: February 23, 2015, 05:30:23 AM by bmarkus »
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline sbp

  • Sr. Member
  • ****
  • Posts: 429
    • piCorePlayer homepage
Re: Community thread on building a RPi2 kernel
« Reply #8 on: February 23, 2015, 05:56:14 AM »
Hi

never used Raspbian to build kernel. For crosscompilation my script:

export CCPREFIX=/home/mb/x-tools/armv6-rpi-linux-gnueabi/bin/armv6-rpi-linux-gnueabi-

Thank you very much - this is exactly the kind of info that I need ( and I think is very difficult to find).

From your CCPREFIX=/home/mb/x-tools/armv6-rpi-linux-gnueabi/bin/armv6-rpi-linux-gnueabi-
I understand that this is for building for the old armv6 RPi's.

If I would like to crosscompile for the new armv7 RPi2 could that be done in a similar way to the armv6 version?
And what would the correct CCPREFIX string then be as we probably should not use armv6-rpi-linux-gnueabi?

And then use:
export CFLAGS="-march=armv7-a -mtune=cortex-a7 -mfpu=neon"
« Last Edit: February 23, 2015, 05:58:06 AM by sbp »

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Community thread on building a RPi2 kernel
« Reply #9 on: February 23, 2015, 11:34:16 AM »
Hi

never used Raspbian to build kernel. For crosscompilation my script:

export CCPREFIX=/home/mb/x-tools/armv6-rpi-linux-gnueabi/bin/armv6-rpi-linux-gnueabi-

Thank you very much - this is exactly the kind of info that I need ( and I think is very difficult to find).

From your CCPREFIX=/home/mb/x-tools/armv6-rpi-linux-gnueabi/bin/armv6-rpi-linux-gnueabi-
I understand that this is for building for the old armv6 RPi's.


No it is a link to the ARM crosscompiler toolchain components used to build a kernel. This GCC crosscompiler is used to build kernel for the different ARM targets, armv6, armv7, ... armv6 in the path is just a directory name from the past.

As I wrote in previous post, for armv7 you need the matching .config for the given hardware and to set target CPU options in the environment variable, that's all. It works for other boards too.

For GCC options see https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline sbp

  • Sr. Member
  • ****
  • Posts: 429
    • piCorePlayer homepage
Re: Community thread on building a RPi2 kernel
« Reply #10 on: February 23, 2015, 03:05:49 PM »
Hi Bela

Sorry for all my questions.
It is strange that this new RPi2 is giving me so much trouble. But now I managed to build the kernel and the initramfs file. It boots fine and load most of the extensions.

Code: [Select]
tc@piCorePlayer:~$ df
Filesystem                Size      Used Available Use% Mounted on
rootfs                  834.3M      9.9M    824.4M   1% /
tmpfs                   834.3M      9.9M    824.4M   1% /
tmpfs                   463.5M         0    463.5M   0% /dev/shm
/dev/mmcblk0p2           37.7M     17.0M     18.1M  48% /mnt/mmcblk0p2
/dev/loop0              112.0K    112.0K         0 100% /tmp/tcloop/dropbear
/dev/loop1               20.0K     20.0K         0 100% /tmp/tcloop/busybox-httpd
/dev/loop2              256.0K    256.0K         0 100% /tmp/tcloop/libfaad
/dev/loop3              128.0K    128.0K         0 100% /tmp/tcloop/libsoxr
/dev/loop4               12.0K     12.0K         0 100% /tmp/tcloop/libogg
/dev/loop5               64.0K     64.0K         0 100% /tmp/tcloop/libmad
/dev/loop6              212.0K    212.0K         0 100% /tmp/tcloop/libvorbis
/dev/loop7              128.0K    128.0K         0 100% /tmp/tcloop/libffi
/dev/loop8               36.0K     36.0K         0 100% /tmp/tcloop/libelf
/dev/loop9               28.0K     28.0K         0 100% /tmp/tcloop/gamin
/dev/loop10             256.0K    256.0K         0 100% /tmp/tcloop/ncurses
/dev/loop11             384.0K    384.0K         0 100% /tmp/tcloop/libasound
/dev/loop12             640.0K    640.0K         0 100% /tmp/tcloop/alsa-modules-3.18.7-piCore
/dev/loop13             256.0K    256.0K         0 100% /tmp/tcloop/alsa
/dev/loop14              32.0K     32.0K         0 100% /tmp/tcloop/firmware-ralinkwifi
/dev/loop15             212.0K    212.0K         0 100% /tmp/tcloop/firmware-rtlwifi
/dev/loop16               2.5M      2.5M         0 100% /tmp/tcloop/wireless-3.18.7-piCore
/dev/loop17              16.0K     16.0K         0 100% /tmp/tcloop/libiw
/dev/loop18              48.0K     48.0K         0 100% /tmp/tcloop/wireless_tools
/dev/loop19             116.0K    116.0K         0 100% /tmp/tcloop/readline
tc@piCorePlayer:~$

I have also build alsa-modules-3.18.7-piCore and wireless-3.18.7-piCore which seems to be loaded.
However other essential packages are not loaded. Like wifi.tcz and alsa-control.tzc

Code: [Select]
tc@piCorePlayer:~$ tce-load -i wifi
mount: mounting /dev/loop20 on /tmp/tcloop/openssl-1.0.1 failed: Invalid argument
tc@piCorePlayer:~$

or
Code: [Select]
tc@piCorePlayer:~$ tce-load -i alsa-config
mount: mounting /dev/loop20 on /tmp/tcloop/alsa-config failed: Invalid argument
tc@piCorePlayer:~$

Any suggestions?



Offline sbp

  • Sr. Member
  • ****
  • Posts: 429
    • piCorePlayer homepage
Re: Community thread on building a RPi2 kernel
« Reply #11 on: February 23, 2015, 04:26:46 PM »
OK found the problem

I don't know if you on purpose left an empty directory hardcoded into usr/local/lib/modules/3.18.6-piCore_v7/kernel in your initramfs file.

I don't think you have this in previous versions.

But after deleting the directory everything is working again. -----

[EDIT] Not fully working. alsa and wifi packages can still not be loaded



Regards
Steen
« Last Edit: February 23, 2015, 04:41:06 PM by sbp »

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1262
Re: Community thread on building a RPi2 kernel
« Reply #12 on: February 23, 2015, 09:08:57 PM »
are you sure you have up to date extensions and dependencies?

Offline sbp

  • Sr. Member
  • ****
  • Posts: 429
    • piCorePlayer homepage
Re: Community thread on building a RPi2 kernel
« Reply #13 on: February 24, 2015, 03:17:02 PM »
Hi Paul

THANK YOU for that suggestion - it seems like both audio and wifi is working now after updating all modules.

So piCorePlayer for RPi2 is now very close to being ready.

Steen

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: Community thread on building a RPi2 kernel
« Reply #14 on: March 08, 2015, 11:15:33 AM »
I would still like for us to have a common kernel code to work from. I downloaded the 3.18.y RPi linux kernel and built it. It turns out y is 9, so now it seems that I'm ahead of everyone. It works, so it wasn't all for naught. I built it in TC on a RPi 2 so it took "only" a few hours.

A few things:

1. make menuconfig doesn't work because ncurses-dev doesn't have a pkg-config file. I was able to hand patch some files to get around this, but an update to ncurses-dev would make it easier.
2. make zImage needs bc at some point. bc requires lex, so I had to download and build flex and bc to finish the compile. Are there equivalent packages or commands for these that I couldn't find, or can we get these?
3. The modules in the initial ram fs (do we have a special name for it on the RPi?) are compressed, but an early modprobe in tc-config won't find modules like snd-bcm2835 unless they are uncompressed. But somewhere in the boot process that gets fixed. Why is that, and how could I load compressed modules earlier?