Cross Compiling Kernel Help Required


Recommended Posts

+John Teacake

Hi All,

 

I think this might benefit all of us here who use it, I tried to compile the Mainline Kernel for the Raspberry Pi. I tried to write two guides. 

 

However I might be missing something really obvious here. They just wont boot on the Pi, Black screen. They produce the files with No errors .img file etc but they dont boot when I copy them to the SC card.

 

 

sudo apt-get update
sudo apt-get install build-essential gcc-arm-linux-gnueabi make ncurses-dev lib32ncurses5
sudo apt-get install linaro-image-tools
sudo apt-get install libc6-i386 lib32stdc++6 lib32gcc1 lib32ncurses5
sudo apt-get install lib32z1
PATH=$PATH:~/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian:~/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin
cd /usr/src
git clone git://github.com/raspberrypi/tools.git --depth=1
git clone git://git.denx.de/u-boot.git --depth=1
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git --depth=1
export KERNEL_SRC=/usr/src/linux
export CCPREFIX=/usr/src/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-
export MODULES_TEMP=/usr/src/modules
cd linux
ARCH=arm CROSS_COMPILE=${CCPREFIX} make bcm2835_defconfig
ARCH=arm CROSS_COMPILE=${CCPREFIX} chrt -i 0 make -j `grep -c ^processor /proc/cpuinfo`
*****************************************************
ARCH=arm CROSS_COMPILE=${CCPREFIX} make menuconfig
*****************************************************
*****************************************************
*****************************************************
*****************************************************

cd ../u-boot
ARCH=arm CROSS_COMPILE=${CCPREFIX} chrt -i 0 make rpi_2_config
ARCH=arm CROSS_COMPILE=${CCPREFIX} chrt -i 0 make -j `grep -c ^processor /proc/cpuinfo`
cd tools
nano boot.scr
-------->mmc dev 0
-------->setenv fdtfile bcm2835-rpi-b-plus.dtb
-------->setenv bootargs earlyprintk console=tty0 console=ttyAMA0 root=/dev/mmcblk0p2 rootwait
-------->fatload mmc 0:1 ${kernel_addr_r} zImage
-------->fatload mmc 0:1 ${fdt_addr_r} ${fdtfile}
-------->bootz ${kernel_addr_r} - ${fdt_addr_r}
./mkimage -A arm -O linux -T script -C none -n boot.scr -d boot.scr boot.scr.uimg
cd /usr/src/u-boot
mkdir /media/boot
mkdir /media/boot/backup
mv /media/boot/* /media/boot/backup/backup
https://github.com/raspberrypi/firmware/tree/master/boot
********************************************************
Fetch start.elf and bootcode.bin from https://github.com/raspberrypi/firmware/tree/master/boot and save it to your $SD
********************************************************
cd /media/boot
wget https://github.com/raspberrypi/firmware/blob/master/boot/start.elf
wget https://github.com/raspberrypi/firmware/blob/master/boot/bootcode.bin
cd ..
********************************************************
cd /usr/src
cp u-boot/u-boot.bin /media/boot/kernel.img
cp linux/arch/arm/boot/zImage /media/boot
cp linux/arch/arm/boot/dts/bcm2835-rpi-b-plus.dtb /media/boot
cp u-boot/tools/boot.scr.uimg /media/boot

OR


 

sudo apt-get install git-core gcc-4.7-arm-linux-gnueabi
sudo apt-get install libncurses5-dev
sudo ln -s /usr/bin/arm-linux-gnueabi-gcc-4.7 /usr/bin/arm-linux-gnueabi-gcc
mkdir raspberrypi
cd raspberrypi
git clone https://github.com/raspberrypi/tools.git
git clone -b rpi-4.5.y https://github.com/raspberrypi/linux.git
cd linux
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- bcm2709_defconfig
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- oldconfig
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- menuconfig

make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k -j4
mkdir ../modules
make modules_install ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- INSTALL_MOD_PATH=../modules/
cd ../tools/mkimage/
./imagetool-uncompressed.py ../../linux/arch/arm/boot/Image

mkdir tmp_kernel_boot
mkdir tmp_kernel_root
sudo cp kernel.img tmp_kernel_boot/
cd ../../modules/
sudo cp -a /root/raspberrypi/modules/lib/modules /root/raspberrypi/tools/mkimage/tmp_kernel_root/lib/
sudo cp -a /root/raspberrypi/modules/lib/modules /root/raspberrypi/tools/mkimage/tmp_kernel_root/lib/

KERNEL IS IN /root/raspberrypi/tools/mkimage
FIRMWARE AND MODULES ARE IN /root/raspberrypi/modules/lib
sudo cp kernel.img /<boot-parition-mount-point>/
sudo cp -a lib/modules/ /<root-partition-mount-point>/lib/
sudo cp -a lib/firmware/ /<root-partition-mount-point>/lib/
sync

 

Link to post
Share on other sites
simplezz

Have you tried following this guide? Perhaps it would be wise to post the lsblk -f of the target sd card to give us an idea of the partition layout and file systems you're using.

 

I did notice that the device tree blob overlays were missing from your copy commands. Whether that's the cause I'm not entirely sure.

 

  • Like 1
Link to post
Share on other sites
Unobscured Vision

You aren't getting any warnings either? Strange. Usually if something goes wrong you'll get some kind of output about it.

Link to post
Share on other sites
+John Teacake
55 minutes ago, Unobscured Vision said:

You aren't getting any warnings either? Strange. Usually if something goes wrong you'll get some kind of output about it.

 

1 hour ago, simplezz said:

Have you tried following this guide? Perhaps it would be wise to post the lsblk -f of the target sd card to give us an idea of the partition layout and file systems you're using.

 

I did notice that the device tree blob overlays were missing from your copy commands. Whether that's the cause I'm not entirely sure.

 

No warnings nothing, Just a black screen. 

 

I didn't try the official guide, I butchered a few other random blogs into one I thought I could understand. 

Link to post
Share on other sites
Unobscured Vision

Hey, believe me, I'm not knocking your goal. Compiling your own kernel is akin to a rite of passage for the most advanced 'nix users. After that it's building your own distro, datacenter admin, building your own Beowulf cluster, etc. Generally compiling your own kernel is the "entrance exam" for all of that. :yes: 

 

Doing it for ARM is even more of a challenge since the Documentation is harder to find; so yeah, kudos to you for trying it.

 

Plus, you'll get the latest/greatest improvements and features.

 

So let's backtrack what it could be.

 

I think @simplezz has it right. I'm not seeing your driver tree either. DId you also take into account that there will be a boatload of things your kernel won't need? Generally the ARCH=ARM flag will eliminate most of that already, but it's your job to make sure. You'd be surprised how one stupid thing you've overlooked will cause such a big problem. The same goes for if you've eliminated something it needed -- it'll fail to load if things aren't "good enough".

 

Then there's the bootloader. Make sure you've updated your bootloader on the Pi to load the kernel. That's usually the big showstopper. It should at least give you a boot menu.

 

Like I said, it's stupid but sometimes we "work faster than we think". Walk through your steps, think about what you're doing. Sometimes (usually) I've gotten a problem fixed simply because I'd gotten ahead of myself.

 

Keep trying, you'll get there. /highfive

Link to post
Share on other sites
+John Teacake

haha!! Thank's for that! I actually wrote a Kernel compilation guide with CPU Optimizations for "normal" systems...Again this is different to me as I have never cross compiled to Arm. I have found a guide to actually run it on the RPi which seems simple enough.........

 

sudo apt-get install bc unzip -y
wget https://github.com/raspberrypi/linux/archive/rpi-4.5.y.zip
unzip rpi-4.5.y.zip
cd linux-rpi-4.5.y
KERNEL=kernel7
make bcm2709_defconfig
make -j4 zImage modules dtbs
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 scripts/mkknlimg arch/arm/boot/zImage /boot/$KERNEL.img

 

THIS should be easy enough but I just have to run it on the Pi itself NOT Cross Compile. 

  • Like 1
Link to post
Share on other sites
This topic is now closed to further replies.
  • Recently Browsing   0 members

    No registered users viewing this page.