24 Replies Latest reply on Mar 27, 2015 2:50 PM by ragnar.jensen

    Kernel compilation walk-through


      There have been a few comments recently about compilation of the "Cirrus-Logic" Linux kernel, so I thought I'd post my recipe.  This is for native compilation running on a fresh installation of Rasbian 2014-12-24 (2014-12-24-wheezy-raspbian.zip).  It takes about 10 hours so let it run overnight.  The comments are minimal, but the process is well described in the Debian documentation.

      NB this will compile the v3.12 kernel, which only works on the original Raspberry Pi series.  It will not work on an Raspberry Pi 2.


      # How to recompile the Raspberry-Pi kernel

      # see http://elinux.org/Raspberry_Pi_Kernel_Compilation


      ### PREREQUISITES : install compiler (~2MB of disk space)


      sudo apt-get update

      sudo apt-get -y dist-upgrade

      sudo apt-get -y install gcc make bc screen ncurses-dev


      ### get source for alternative kernel


      mkdir ~/tmp

      cd ~/tmp

      git init


      git clone --depth 1 https://github.com/CirrusLogic/wiki-content.git # download audio-card config scripts

      mv wiki-content/scripts ~/

      rm -rf wiki-content


      git clone -b rpi-3.12.y --depth 1 https://github.com/CirrusLogic/rpi-linux.git # download kernel source

      tar -czvf rpi-kernel-3-12-33-cirrus.tgz rpi-linux # save source as tar for next time

      #tar -xzvf rpi-kernel-3-12-33-cirrus.tgz # extract source from saved tar instead of re-downloading

      cd rpi-linux


      ### configure & compile kernel


      make mrproper         # clean up build directory

      make bcmrpi_defconfig # create config for Cirrus Logic audio card (same as official instructions)

      make oldconfig        # ensure config is up to date

      make menuconfig       # give kernel unique suffix : General Setup -> Local version

      #zcat /proc/config.gz | diff - .config # compare with running config

      uname -a              # running kernel version

      make kernelversion    # new kernel version

      make kernelrelease

      nohup make &          # compile (about 10 hours)


      ### compile and install kernel and modules


      make KBUILD_DEBARCH=armhf deb-pkg # create packages

      ver=$(make kernelrelease)         # get release string

      sudo dpkg -i ../linux-image-${ver}_${ver}-1_armhf.deb

      sudo mv /boot/vmlinuz-${ver} /boot/kernel_new.img

      sudo rm /boot/*${ver}


      ### configure bootloader and modules


      sudo perl -i.original -pe 's/^\s*(kernel=.+)$/\#${1}/' /boot/config.txt

      echo -e "\n#Use new kernel\nkernel=kernel_new.img" | sudo tee -a /boot/config.txt


      sudo perl -i.original -pe 's/^(snd-bcm2835)/\#${1}/' /etc/modules # disable onboard sound

      echo 'snd-soc-rpi-wsp' | sudo tee -a /etc/modules # enable Cirrus sound


      sudo perl -i.original -pe 's/^(.+-bcm2708)/\#${1}/' /etc/modprobe.d/raspi-blacklist.conf # enable spi and i2c

      echo 'softdep arizona-spi pre: arizona-ldo1

      blacklist snd-soc-pcm512x

      #blacklist snd-soc-wm8804

      ' | sudo tee -a /etc/modprobe.d/raspi-blacklist.conf


      ### configure alsa


      echo 'pcm.!default {

              type hw

              card sndrpiwsp



      ctl.!default {

              type hw

              card sndrpiwsp

      }' > ~/.asoundrc


      # power off, connect Cirrus Audio Card & reboot

      sudo halt

        • Re: Kernel compilation walk-through

          Tim Giles schrieb:


          It takes about 10 hours so let it run overnight.

          That's only one side of the truth. Do you know how to cross-compile a kernel. It takes me on an 8 core about 10 minutes!

          Take a look at


          and have fun.

          If there's someone who likes to install a precompiled kernel in deb-format  (DOES NOT WORK FOR Raspberry Pi 2! ) ->


            • Re: Kernel compilation walk-through

              That's only one side of the truth. Do you know how to cross-compile a kernel. It takes me on an 8 core about 10 minutes!

              That's an incomplete truth.  It's a false generalization that's based upon the assumption that everyone uses a debian-type 32-bit compatible linux system.  Now that we're in the 21st Century, the world is full of 64-bit only installations and those boxes aren't going to result in a make that requires only 10-minutes of seat time.


              If a user happens to be running something like 32-bit Ubuntu on an 8-core box then he might succeed in a 10-minute 8-core make.  In that case, things will probably "just work" because as a matter of coincidence he happens to be running a backward-compatible system on the same type of backward-compatible platform as the guy who wrote the incomplete set of cross-compiling instructions that are tailored to that type of platform.  Try cross compiling a 32-bit deb target using a 64-bit-only RPM-based system and let us know how that works out.  There will be far less seat-time and a lot less frustration required if you compile natively on the Pi and let it run overnight.


              I've been building linux from source code for ~15 years.  I have my own 40-core distributed compiling farm.  I have enough experience with cross-compiling under distcc that I understand the pitfalls of cross-compiling, and that it's a bad idea to blindly recommend cross-compiling for everyone.  If a n00b is interested in compiling a kernel for the first time, I'd want to know exactly what kind of environment they're working in before making a recommendation that involved cross-compiling.  Cross-compiling can be fraught with errors while compiling in the native environment is simple by comparison.  Personally, I think that the recommendation to compile on the native platform is a more responsible recommendation to make, irrespective of how much wall-clock-time may be involved.


              In the big scheme of things, how much wall-clock-time it takes to compile a kernel isn't really relevant.  It's only relevant to someone who is intent on staring at the monitor and watching everything happen in real-time.


              I think that Tim is doing the community a great service by posting foolproof instructions on how to perform a native compile on the Raspberry Pi.  IMO too many guides offer only cross-compiling instructions, which I think is irresponsible and short-sighted.  I would not consider recommending cross-compiling until after I had performed the due diligence required to ensure that such a recommendation would work properly on the user's system.  Anything less amounts to a bum steer.


              Thanks for posting this, Tim.

            • Re: Kernel compilation walk-through

              I don't know what kind of problem you have with cross compiling. This will work  on ANY  64-bit linux system.

              All yours


                • Re: Kernel compilation walk-through

                  Unfortunately, that statement isn't accurate.


                  Read through the other thread about ELF errors.  Based on your experience, you should know what they are.


                  The RPi is a 32-bit system.  You can't build 32-bit code on a 64-bit-only system, because the libraries required to build 32-bit code are absent.  You need to have a 32-bit toolkit installed on a 64-bit system to build 32-bit code, or you're guaranteed to fail. 


                  It seems that a lot of people don't know this, probably because they've been blindly installing 32-bit libraries on their 64-bit systems without even knowing it, and they aren't aware of why they have success.  The truth is that it won't work on any 64-bit system; it will only work on a 64-bit system that has 32-bit ELF addressing.

                • Re: Kernel compilation walk-through



                  what I do need to change if I would like to compile 3.12.x    Cirrus Audio Code against the RPI 3.18.x  Kernel?  If I follow the Script it automatically selects teh 3.12 code stream.


                  Did anybody try this already and did it work out? I would like to geht the Audio Card running onto the RPI 2.


                  kind regards,



                  • Re: Kernel compilation walk-through

                    there is a new 3.18y with device overlay on the cirrus github now. compiled it, didn't work, loaded pcm512x modules which complains alot about regulator.


                    anybody able to make it work?

                      • Re: Kernel compilation walk-through

                        This should work and provide full audio card support.

                        Can I check of you have followed the instructions on the wiki, "Building the code"? This has been updated to reflect 3.18. (update to reflect latest wiki instructions)

                        We did see something similar which was resolved in step 4, specifically the important notice about adding trailer support to the kernel..


                        Background here if required


                        If the kernel fails to come up in DT mode, this is probably because the kernel image does not have a valid trailer. Use knlinfo to check for one, and mkknlimg utility to add one.

                          • Re: Kernel compilation walk-through

                            Hi Scott,


                            I built the kernel on the pi. Took 1.5Hrs. Followed this guide here. http://www.raspberrypi.org/documentation/linux/kernel/building.md new kernel boots fine but no card detected.


                            Now i mkknlimg the kernel, but still not detecting the card.


                            Here is some info from the pi.


                            pi@raspberrypi ~ $ uname -a
                            Linux raspberrypi 3.18.9-v7 #1 SMP PREEMPT Tue Mar 24 21:25:06 UTC 2015 armv7l GNU/Linux
                            pi@raspberrypi ~ $ aplay -l
                            aplay: device_list:252: no soundcards found...
                            pi@raspberrypi ~ $ lsmod
                            Module                  Size  Used by
                            arizona_ldo1            2708  0
                            arizona_spi             1285  0
                            spi_bcm2708             5117  0
                            snd_soc_rpi_wsp         7785  0
                            snd_soc_wm8804          8721  0
                            snd_soc_bcm2708_i2s     6344  0
                            regmap_spi              1732  2 snd_soc_wm8804,arizona_spi
                            regmap_mmio             2949  1 snd_soc_bcm2708_i2s
                            regmap_i2c              2273  1 snd_soc_wm8804
                            snd_soc_core          136200  3 snd_soc_wm8804,snd_soc_rpi_wsp,snd_soc_bcm2708_i2s
                            snd_compress            7598  1 snd_soc_core
                            snd_pcm_dmaengine       3323  1 snd_soc_core
                            snd_pcm                73019  4 snd_soc_wm8804,snd_soc_core,snd_soc_rpi_wsp,snd_pcm_dmaengine
                            snd_seq                52256  0
                            snd_seq_device          5449  1 snd_seq
                            snd_timer              17524  2 snd_pcm,snd_seq
                            snd                    50614  6 snd_soc_core,snd_timer,snd_pcm,snd_seq,snd_seq_device,snd_compress
                            evdev                   9873  3
                            joydev                  8689  0
                            fixed                   2421  2
                            i2c_bcm2708             4964  0
                            uio_pdrv_genirq         3001  0
                            uio                     7732  1 uio_pdrv_genirq
                            pi@raspberrypi ~ $ sudo ./knlinfo /boot/kernel.new.dt
                            Kernel trailer found at 3959160/0x3c6978:
                              KVer: "Linux version 3.18.9-v7 (pi@raspberrypi) (gcc version 4.6.3 (Debian 4.6.3-14+rpi1) ) #1 SMP PREEMPT Tue Mar 24 21:25:06 UTC 2015"
                              DTOK: true
                            pi@raspberrypi ~ $ ls /boot/overlays/
                            ds1307-rtc-overlay.dtb         pcf2127-rtc-overlay.dtb
                            hifiberry-amp-overlay.dtb      pcf8523-rtc-overlay.dtb
                            hifiberry-dac-overlay.dtb      pps-gpio-overlay.dtb
                            hifiberry-dacplus-overlay.dtb  README
                            hifiberry-digi-overlay.dtb     rpi-cirrus-wm5102-overlay.dtb
                            iqaudio-dac-overlay.dtb        w1-gpio-overlay.dtb
                            iqaudio-dacplus-overlay.dtb    w1-gpio-pullup-overlay.dtb
                            pi@raspberrypi ~ $ cat /boot/config.txt
                            # For more options and information see
                            # http://www.raspberrypi.org/documentation/configuration/config-txt.md
                            # Some settings may impact device functionality. See link above for details


                            # uncomment if you get no picture on HDMI for a default "safe" mode


                            # uncomment this if your display has a black border of unused pixels visible
                            # and your display can output without overscan


                            # uncomment the following to adjust overscan. Use positive numbers if console
                            # goes off screen, and negative if there is too much border


                            # uncomment to force a console size. By default it will be display's size minus
                            # overscan.


                            # uncomment if hdmi display is not detected and composite is being output


                            # uncomment to force a specific HDMI mode (this will force VGA)


                            # uncomment to force a HDMI mode rather than DVI. This can make audio work in
                            # DMT (computer monitor) modes


                            # uncomment to increase signal to HDMI, if you have interference, blanking, or
                            # no display


                            # uncomment for composite PAL


                            #uncomment to overclock the arm. 700 MHz is the default.


                            pi@raspberrypi ~ $ cat /etc/modules
                            # /etc/modules: kernel modules to load at boot time.
                            # This file contains the names of kernel modules that should be loaded
                            # at boot time, one per line. Lines beginning with "#" are ignored.
                            # Parameters can be specified after the module name.


                            pi@raspberrypi ~ $ cat /etc/modprobe.d/raspi-blacklist.conf
                            softdep arizona-spi pre: arizonaldo1
                            softdep spi-bcm2708 pre: fixed


                            #blacklist snd_soc_pcm512x
                            #blacklist snd_soc_tas5713
                            #blacklist snd_soc_pcm512x_i2c

                          • Re: Kernel compilation walk-through

                            I also got a lot of errors about voltage regulators not found and my card was not detected.

                            All that went away after I updated my firmware, I was still on firmware for my old 3.12 kernel.


                            Now happy listening to music from the Cirrus Logic card on a B+ with kernel 3.18

                            The Compile Machine is busy cooking one up for the Pi2...