Announcement

Collapse
No announcement yet.

Announcement

Collapse
No announcement yet.

Bash script to crosscompile rk3188 linux kernel and create linuxroot in a wheezy box

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Bash script to crosscompile rk3188 linux kernel and create linuxroot in a wheezy box

    I made a bash script to fully automate the crosscompilation process, so anyone can easily build their own kernel+linux on rk devices.
    It also installs wheezy in a chroot environment, to create linuxroot with compiled kernel modules, so it can later be copied to microsd.
    You can include more wheezy packages with their dependencies very easily, just modify the debootstrap --include swith. You can add lxde there for example if you want to have X installed.

    To test it just run this AS ROOT in a wheezy box or VM, it should install croscompilers and some more dependencies:

    Code:
    wget http://solidpc.net/initramfs-3.0.36/crosscompile-script.sh
    # I usually have a look at the script before running it
    bash -v crosscompile-script.sh |tee crosscompile.log
    It copies your existing /etc/passwd and /etc/shadow to the linuxroot /etc directory, so be careful!!!
    This is to avoid entering the chroot environment to create users and set passwords, it uses those from the main host.
    You might prefer to chroot to the linuxroot directory and do that manually, but you can do it later anyway.

    It might take a quite long time to run, depending on your cpu and internet speed, but dependencies and wheezy packages are only downloaded on the first run. git contents are downloaded on every run (about 130mb). It takes less than an hour in my OVH KS16G dedicated server with 100M bw.

    When finished all the output files will be in /root/rk3188/kernel/kernels/$DATE/

    You can use your custom config, if you place it in /root/rk3188/kernel/config-ramoncio-Linux3188 it gets copied over .config
    I can post mine if someone if interested, but I just enabled a couple of modules and that's it.

    Changes or comments are appreciated, as I gathered information from several places, and I'm sure it can be improved.


    One question, how to enable internal nand memory in .config? I can only see the sd card...
    Last edited by ramoncio; 11-23-2015, 07:12.

    #2
    Linuxroot tar.gz

    Great idea to combine all steps into a single script. Right now I have only CentOS 6.4 and Ubuntu 12.04 handy here, however, most steps seem to run fine on Ubuntu 12.04 too - until kernel compilation where it claims about different architectures.

    However, I build the kernel side-by-side on CentOS 6.4 (with my needed kernel .config) and merged the firmware/modules lib folder into linuxroot. The RK3188 (QC802) boots fine with Debian linuxroot, but essential commands like modprobe or ifconfig are missing. I fear something went wrong during linuxroot creation. Do you have a .tar.gz version of your linuxroot to test against?

    Best wishes,

    mark.sch

    Comment


      #3
      Originally posted by mark.sch View Post
      Great idea to combine all steps into a single script. Right now I have only CentOS 6.4 and Ubuntu 12.04 handy here, however, most steps seem to run fine on Ubuntu 12.04 too - until kernel compilation where it claims about different architectures.

      However, I build the kernel side-by-side on CentOS 6.4 (with my needed kernel .config) and merged the firmware/modules lib folder into linuxroot. The RK3188 (QC802) boots fine with Debian linuxroot, but essential commands like modprobe or ifconfig are missing. I fear something went wrong during linuxroot creation. Do you have a .tar.gz version of your linuxroot to test against?

      Best wishes,

      mark.sch
      Hi mark!
      I also get some warnings about setting the proper CC variable for the host, I haven't figured that out yet. But the build progress goes on fine and all files are created in kernels/$DATE

      You need to run the script in a wheezy box, I haven't tried in ubuntu, it should be adapted, but not too much.

      I'll build you a custom linuxroot asap. Just the minimal wheezy so you can install with apt-get or do I include lxde?
      If you have a fast internet connection this process is pretty fast, but I run it once from home and it took much more time. That's why I run it in a dedicated server with 100M/100M bw.

      Yesterday I finally found the good rk3188 linux kernel here:



      I'm still reading it from the begining.

      Comment


        #4
        Hello Ramoncio,

        I was following your mentioned thread also some time ago. Basically I found 4 main sources/guys working on rk3188 kernels:

        - http://www.rikomagic.co.uk/downloads/ The AP6210-kernel released from Rikomagic
        - https://github.com/omegamoon/rockchip-rk3188-mk908
        - https://github.com/aloksinha2001/Linux3188 seems to have most activity right now
        - https://github.com/Galland/Linux3188 basically a fork from aloksinha with tweaks

        After testing different kernels I work with aloksinha kernel sources right now. I put initramfs, compiled kernel modules and a modified kernel .config and build script (I use CentOS 6.4) into my fork here:

        Linux Source - RK3188 - PicUntu. Contribute to mark-sch/RK3188-Kernel-QC802 development by creating an account on GitHub.


        picuntu-kernel-qc802.img is the compiled kernel I am actually using, it boots with your debian linuxroot. For the missing modprobe and ifconfig commands I added module-init-tools and net-tools to your qemu-debootstrap setup:

        qemu-debootstrap --verbose --variant=minbase --arch=armhf --include=vim,wireless-tools,module-init-tools,net-tools,wpasupplicant,sudo wheezy /root/rk3188/linuxroot http://ftp.debian.org/debian

        However, there is no networking right now using the debian linuxroot, did you add further packages to get the network running?

        Comment


          #5
          Hi Mark,

          Internal wifi is quite tricky at the moment. I think my CX-919 device has AP6210 module, but I haven't been able to make it work with different kernels. Also, it seems you can't simply enable all RK wifi modules, you have to choose which one to compile the kernel for, which disables the rest of them.

          What I did is to enable ath9k_htc module and used a USB TP-Link adapter. Anyway wifi speed is not good at all, I think there is a problem with too many interrupts for the usb otg module to handle. I also have similar problems with my Hauppauge HVR900 and jerky DVB-T in vdr, someone needs to fix this interrupt issue, they fixed it in raspberri pi kernel and quality has improved drastically since then.

          I just received a Linksys USB300M USB ethernet adapter, so I can forget about wifi problems for now, let someone else fight with wifi modules.

          I also switched to aloksinha sources, I'll post my modified script this weekend after I successfully compile a couple of kernels.

          Comment


            #6
            Hi Ramoncio,

            networking with RK3066/RK3188 is really a piece of pain. I also use a $5 USB2Ethernet adapter, using dm9601 kernel module. With static IP it works, DHCP is broken, have read several threads about this issue. On RK3066/MK808 I have WLAN working too, but it is loosing connection after some hours - but using a script to monitor network status and doing a service restart is fine.

            Right now I am playing side-by-side with wheezy and precise pangolin linuxroot, both seem to work pretty well, will install further software packages to see if it can replace the x64 home server hardware

            Comment


              #7
              hi

              hi ramoncio, thanks for the script i tried it and managed to compile the kernel and create de rootfs, i copied the rootfs to my sd and system booted , but nothing worked , i think the rootfs lacks modules, shoul i copy them to /lib?


              Are you improving this script? did it uses the last (and best) sources availables for rk3188?


              PD:Soy espaƱol

              Comment


                #8
                very good script!

                Hi ramoncio,

                I just tried your script and seems to successfully build a kernel and the rootfs. It sounds nooby, but can u explain how its possible to flash my neo x7? I tried to flash it on my windows 8.1 system, but the driver don't work on that. What I have to do, for flashing it on Debian.

                Many thanks!

                Comment


                  #9
                  Originally posted by hiddenbit View Post
                  Hi ramoncio,

                  I just tried your script and seems to successfully build a kernel and the rootfs. It sounds nooby, but can u explain how its possible to flash my neo x7? I tried to flash it on my windows 8.1 system, but the driver don't work on that. What I have to do, for flashing it on Debian.

                  Many thanks!
                  Hi hiddenbit, thanks for your input!
                  This script is a bit outdated (as there are newer kernel sources), but it automates the processes quite well.

                  I have never flashed from linux, I compile on my dedicated ovh server, download the resulting files and flash from my Win7 laptop.
                  I have used heimdall to flash a couple of Samsung android devices from linux, but I'm not sure if it will work for rk3188 devices (most likely not). Be careful so you don't end up with a mini brick.

                  Comment


                    #10
                    Here is the script, the link at the top post is broken a long time ago, maybe someone can adapt it for his needs.

                    Code:
                    #!/bin/bash
                    BUILDDIR="/root/rk3188";
                    FECHA=`date +%Y.%m.%d.%Hh.%Mm`;
                    
                    # Installs crosscompilation environment, if not installed
                    PKG="gcc-4.7-arm-linux-gnueabihf";
                    dpkg-query -l $PKG
                    if [ $? = 1 ]; then
                    apt-get -y install git build-essential xapt fakeroot kernel-package u-boot-tools \
                    zlib1g-dev libncurses5-dev
                    echo "deb http://www.emdebian.org/debian/ unstable main
                    deb http://www.emdebian.org/debian wheezy main
                    " > /etc/apt/sources.list.d/emdebian.list
                    apt-get update
                    apt-get -y install emdebian-archive-keyring
                    apt-get update
                    xapt -a armhf -m libstdc++6-4.7-dev
                    apt-get -y install gcc-4.7-arm-linux-gnueabihf
                    cd /usr/bin
                    for i in arm-linux-gnueabi*-4.7 ; do ln -s $i ${i%%-4.7} ; done
                    else echo $PKG already installed
                    fi
                    
                    # Installs debootstraped minimal wheezy on $BUILDDIR/linuxroot if not installed
                    # see here for used tricks http://www.raspberrypi.org/phpBB3/viewtopic.php?f=9&t=850
                    if [ -d $BUILDDIR/linuxroot ]; then
                    echo "Already installed wheezy on linuxroot"
                    else
                    apt-get y install qemu-user-static binfmt-support debootstrap
                    mkdir -p $BUILDDIR/linuxroot
                    cd $BUILDDIR/linuxroot
                    qemu-debootstrap --verbose --variant=minbase --arch=armhf --include=vim,wireless-tools,wpasupplicant,sudo \
                    wheezy $BUILDDIR/linuxroot http://ftp.debian.org/debian
                    echo "nameserver 8.8.8.8" > $BUILDDIR/linuxroot/etc/resolv.conf
                    echo "nameserver 194.224.52.4" >> $BUILDDIR/linuxroot/etc/resolv.conf
                    echo "/dev/disk/by-label/linuxroot / ext4 rw,data=writeback,noatime,nodiratime 0 1" > $BUILDDIR/linuxroot/etc/fstab
                    echo "tmpfs /var/run tmpfs defaults,noatime,nodiratime 0 0" >> $BUILDDIR/linuxroot/etc/fstab
                    echo "tmpfs /var/log tmpfs defaults,noatime,nodiratime 0 0" >> $BUILDDIR/linuxroot/etc/fstab
                    echo "tmpfs /tmp tmpfs defaults,noatime,nodiratime,mode=1777 0 0" >> $BUILDDIR/linuxroot/etc/fstab
                    echo "tmpfs /var/lock tmpfs defaults,noatime,nodiratime 0 0" >> $BUILDDIR/linuxroot/etc/fstab
                    echo "tmpfs /var/tmp tmpfs defaults,noatime,nodiratime 0 0" >> $BUILDDIR/linuxroot/etc/fstab
                    echo "vm.swappiness=10" > $BUILDDIR/linuxroot/etc/sysctl
                    echo "kernel.panic = 10" > $BUILDDIR/linuxroot/etc/sysctl #reboot on k panic
                    echo "kernel.printk = 3 4 1 3" >> $BUILDDIR/linuxroot/etc/sysctl #less messages flooding console
                    if [ ! -f /etc/passwd ]; then
                    #copies local machine users if /etc/passwd is missing
                    cp /etc/passwd /etc/shadow $BUILDDIR/linuxroot/etc/
                    fi
                    fi
                    
                    mkdir -p $BUILDDIR/kernel/kernels $BUILDDIR/linuxroot
                    cd $BUILDDIR/kernel
                    mkdir -p initramfs-3.0.36
                    cd initramfs
                    wget http://montenegrojoyeros.com/initramfs-3.0.36/initramfs-3.0.36+.cpio
                    wget http://montenegrojoyeros.com/initramfs-3.0.36/fakeramdisk.gz
                    cd ..
                    
                    #NAME="Linux3188";
                    NAME="3188-SRC-AP6210";
                    #NAME="rockchip-rk3188-mk908";
                    cd $BUILDDIR/kernel
                    #rm -rf $NAME
                    if [ -d $NAME ]; then
                    echo "Already downloaded kernel sources"
                    else
                    #git clone https://github.com/omegamoon/$NAME.git
                    #git clone https://github.com/aloksinha2001/$NAME.git
                    #git clone https://github.com/Galland/$NAME.git
                    git clone https://github.com/linuxium/$NAME.git
                    mv $NAME/kernel_ruikemei/* $NAME/kernel_ruikemei/.[^.]* $NAME/
                    #cp arch/arm/configs/rk3188_dongle_defconfig .config
                    
                    #git clone https://github.com/linuxium/$NAME/kernel.git $NAME
                    fi
                    
                    cd $NAME
                    cp .config .config-$NAME-$FECHA
                    #sed -i "s,CONFIG_INITRAMFS_SOURCE=\"\",CONFIG_INITRAMFS_S OURCE=\"../initramfs/initramfs-3.0.36-$NAME+.cpio\",g" .config
                    #sed -i "s,CONFIG_INITRAMFS_SOURCE=\"\",CONFIG_INITRAMFS_S OURCE=\"../initramfs/initramfs-3.0.36-linuxium+.cpio\",g" .config
                    mv .config config.bak
                    make KDIR=./ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- mrproper
                    mv config.bak .config
                    cp arc/arm/configs/rk3188_mk908_defconfig .config
                    cp ../config-ramoncio-$NAME .config
                    #define environment
                    export ARCH=arm
                    export KDIR=./
                    export GYP_DEFINES="target_arch=arm"
                    export CC=arm-linux-gnueabihf-gcc
                    export CXX=arm-linux-gnueabihf-g++
                    export AR=arm-linux-gnueabihf-ar
                    export CC_host=gcc
                    export CXX_host=g++
                    export DEB_HOST_ARCH=armhf
                    export MAKEFLAGS="CC=arm-linux-gnueabihf-gcc"
                    export CONCURRENCY_LEVEL=`grep -m1 cpu\ cores /proc/cpuinfo | cut -d : -f 2`
                    #build
                    cd $BUILDDIR/kernel/$NAME
                    DEB_HOST_ARCH=armhf fakeroot make-kpkg --arch arm --cross-compile arm-linux-gnueabihf- --initrd kernel_image kernel_headers
                    make KDIR=./ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j5 INSTALL_MOD_PATH=output modules > /dev/null
                    make KDIR=./ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j5 INSTALL_MOD_PATH=output modules_install > /dev/null
                    #mkinitramfs -c -o ../initramfs-3.0.36/initramfs-3.0.36-$NAME+.cpio
                    wget http://montenegrojoyeros.com/initramfs-3.0.36/mkbootimg
                    cp ../initramfs-3.0.36/mkbootimg .
                    chmod +x mkbootimg
                    #makes recovery image
                    ./mkbootimg --kernel arch/arm/boot/Image --ramdisk ../initramfs-3.0.36/fakeramdisk.gz --base 60400000 --pagesize 16384 --ramdiskaddr 62000000 -o recovery-3.0.36-$NAME.img
                    #compresses and sorts output
                    mkdir -p $BUILDDIR/kernel/kernels/$NAME-$FECHA
                    cp .config $BUILDDIR/kernel/kernels/$NAME-$FECHA/config-3.0.36-$NAME-$FECHA
                    cp ../initramfs-3.0.36/initramfs-3.0.36+.cpio $BUILDDIR/kernel/kernels/$NAME-$FECHA/
                    cd output/lib
                    rm -rf $BUILDDIR/linuxroot/lib/*
                    cp -a * $BUILDDIR/linuxroot/lib/
                    tar cfvz $BUILDDIR/kernel/kernels/$NAME-$FECHA/modules-3.0.36-$NAME-$FECHA.tgz * > /dev/null
                    cd ../../
                    cp recovery-3.0.36-$NAME.img $BUILDDIR/kernel/kernels/$NAME-$FECHA/recovery-3.0.36-$NAME-$FECHA.img
                    mv ../*.deb $BUILDDIR/kernel/kernels/$NAME-$FECHA/
                    cd $BUILDDIR/linuxroot/
                    tar cfvz $BUILDDIR/kernel/kernels/$NAME-$FECHA/linuxroot-wheezy-3.0.36-$NAME-$FECHA.tgz * > /dev/null
                    cd $BUILDDIR
                    exit 0
                    
                    
                    mkdir /mnt/vdrroot/
                    vgscan
                    vgchange -a y
                    mount /dev/mapper/vdr-root /mnt/vdrroot/
                    mount /dev/sda1 /mnt/vdrroot/boot
                    mount -o bind /proc /mnt/vdrroot/proc
                    mount -o bind /dev /mnt/vdrroot/dev
                    mount -o bind /dev/pts /mnt/vdrroot/dev/pts
                    mount -o bind /sys /mnt/vdrroot/sys
                    chroot /mnt/vdrroot/
                    
                    ....
                    
                    exit
                    umount /mnt/vdrroot/proc
                    umount /mnt/vdrroot/dev
                    umount /mnt/vdrroot/dev/pts
                    umount /mnt/vdrroot/sys

                    Comment

                    Working...
                    X