Tiny Core Linux

Tiny Core Base => Raspberry Pi => Topic started by: sbp on February 22, 2015, 03:54:38 PM

Title: Community thread on building a RPi2 kernel
Post by: sbp 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
Title: Re: Community thread on building a RPi2 kernel
Post by: sbp 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?
Title: Re: Community thread on building a RPi2 kernel
Post by: bmarkus on February 22, 2015, 07:43:41 PM
Steen: It is not cleat what are you doing... :(
Title: Re: Community thread on building a RPi2 kernel
Post by: sbp 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
Title: Re: Community thread on building a RPi2 kernel
Post by: bmarkus 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.
Title: Re: Community thread on building a RPi2 kernel
Post by: bmarkus 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.
Title: Re: Community thread on building a RPi2 kernel
Post by: sbp 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
Title: Re: Community thread on building a RPi2 kernel
Post by: bmarkus 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"
Title: Re: Community thread on building a RPi2 kernel
Post by: sbp 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"
Title: Re: Community thread on building a RPi2 kernel
Post by: bmarkus 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
Title: Re: Community thread on building a RPi2 kernel
Post by: sbp 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?


Title: Re: Community thread on building a RPi2 kernel
Post by: sbp 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
Title: Re: Community thread on building a RPi2 kernel
Post by: Paul_123 on February 23, 2015, 09:08:57 PM
are you sure you have up to date extensions and dependencies?
Title: Re: Community thread on building a RPi2 kernel
Post by: sbp 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
Title: Re: Community thread on building a RPi2 kernel
Post by: andyj 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?
Title: Re: Community thread on building a RPi2 kernel
Post by: bmarkus on March 08, 2015, 03:27:12 PM

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?


flex.tcz is in the repo. Did you try to install it?
Title: Re: Community thread on building a RPi2 kernel
Post by: andyj on March 08, 2015, 03:51:36 PM
Probably, but I usually load from the command line so I must have guessed / typed the name wrong. I see it now in the app browser so it's good to know that it's there for future reference.

I did figure out the compressed module issue. I copied the updated modules.dep file from memory back to the working ramfs image directory on disk. Then I recreated the image and rebooted and it worked. I suppose that I could have chroot'ed to the image root, run depmod and then remake the image. I'll try that next time when I get around to loading wireless modules.
Title: Re: Community thread on building a RPi2 kernel
Post by: Mucke on March 21, 2015, 05:55:03 PM
Trying to compile the actual Rasbian kernel 3.18.7 on the Pi2 with 3.18.9_v7-piCore+ gives 2 problems here:

1. make mrproper
Code: [Select]
./scripts/link-vmlinux.sh: trap: line 113: ERR: invalid signal specification
2. make menuconfig
Code: [Select]
...scripts/kconfig/mconf.o: In function `show_help´:
mconf.c:(.text+0x98c): undefined reference to `stdscr´
...

Can someone tell me how to fix it? What is missed?
ncurses-dev.tcz is installed btw.

Mucke
Title: Re: Community thread on building a RPi2 kernel
Post by: andyj on March 21, 2015, 07:52:24 PM
1. Remove the ERR signal from the line in question.
2. I had to do a lot of hand patching to get mconf to build. Basically you need to add -lncurses after everywhere you see -lreadline in the files in that directory, IIRC. As you can see that was almost two weeks ago.
Title: Re: Community thread on building a RPi2 kernel
Post by: Mucke on March 23, 2015, 02:42:59 AM
1. Removing ERR helps

But I have not got a solution for your proposal 2.
mconf is in the folder /scripts/kconfig. There is no file with -lreadline in that directory.
Can you be a bit more precise?

Bela, how did you get your make menuconfig running on the Pi2 ?

Mucke
Title: Re: Community thread on building a RPi2 kernel
Post by: bmarkus on March 23, 2015, 02:51:40 AM

Bela, how did you get your make menuconfig running on the Pi2 ?


Easy. I'm not using it :)
Title: Re: Community thread on building a RPi2 kernel
Post by: andyj on March 28, 2015, 08:08:01 PM
Try this patch to the scripts directory:

--- linux-rpi-3.18.y/scripts/kconfig/Makefile
+++ linux-rpi-3.18.y-menuconfig-patched/scripts/kconfig/Makefile
@@ -212,7 +212,7 @@
 HOSTLOADLIBES_nconf    = $(shell \
                                pkg-config --libs menuw panelw ncursesw 2>/dev/null \
                                || pkg-config --libs menu panel ncurses 2>/dev/null \
-                               || echo "-lmenu -lpanel -lncurses"  )
+                               || echo "-lmenu -lpanel -lncursesw"  )
 $(obj)/qconf.o: $(obj)/.tmp_qtcheck
 
 ifeq ($(MAKECMDGOALS),xconfig)
--- linux-rpi-3.18.y/scripts/kconfig/lxdialog/check-lxdialog.sh
+++ linux-rpi-3.18.y-menuconfig-patched/scripts/kconfig/lxdialog/check-lxdialog.sh
@@ -15,6 +15,7 @@
                        fi
                done
        done
+       echo "-lncursesw"
        exit 1
 }
 
@@ -25,14 +26,14 @@
                echo '-DCURSES_LOC="<ncurses.h>" -DNCURSES_WIDECHAR=1'
        elif pkg-config --cflags ncurses 2>/dev/null; then
                echo '-DCURSES_LOC="<ncurses.h>"'
-       elif [ -f /usr/include/ncursesw/curses.h ]; then
-               echo '-I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"'
+       elif [ -f /usr/local/include/ncursesw/curses.h ]; then
+               echo '-I/usr/local/include/ncursesw -DCURSES_LOC="<curses.h>"'
                echo ' -DNCURSES_WIDECHAR=1'
-       elif [ -f /usr/include/ncurses/ncurses.h ]; then
-               echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"'
-       elif [ -f /usr/include/ncurses/curses.h ]; then
-               echo '-I/usr/include/ncurses -DCURSES_LOC="<curses.h>"'
-       elif [ -f /usr/include/ncurses.h ]; then
+       elif [ -f /usr/local/include/ncurses/ncurses.h ]; then
+               echo '-I/usr/local/include/ncurses -DCURSES_LOC="<ncurses.h>"'
+       elif [ -f /usr/local/include/ncurses/curses.h ]; then
+               echo '-I/usr/local/include/ncurses -DCURSES_LOC="<curses.h>"'
+       elif [ -f /usr/local/include/ncurses.h ]; then
                echo '-DCURSES_LOC="<ncurses.h>"'
        else
                echo '-DCURSES_LOC="<curses.h>"'
Title: Re: Community thread on building a RPi2 kernel
Post by: Mucke on March 29, 2015, 12:01:04 PM
Thanks, the patches allow to run make menuconfig smoothly.

Now after kernel compilation I get a next problem as mkknlimg does not run. It simplereports that for grep -b the option -b does not exist. So it seems that grep needs an update or a replace. Is there a proper tcx extension?

Mucke
Title: Re: Community thread on building a RPi2 kernel
Post by: Rich on March 29, 2015, 02:01:58 PM
Hi Mucke
Quote
So it seems that grep needs an update or a replace. Is there a proper tcx extension?
Maybe  grep.tcz ?
Title: Re: Community thread on building a RPi2 kernel
Post by: Mucke on March 29, 2015, 02:09:59 PM
Funny, I can bite myself
Honestly speaking I did not expect that there is a tcz option for grep itself, so I did not check. I was simply expecting to find it embedded in a package with other stuff without knowing what package it could be.
Thanks, I'll try it.

Mucke
Title: Re: Community thread on building a RPi2 kernel
Post by: bmarkus on March 29, 2015, 02:28:46 PM
In the base grep is provided by BusyBox as all other basic utilities. BusyBox versions do not implement all features of the GNU equivalent, specific applications require the original version from the repo.