OpenWrt Forum Archive

Topic: My Raspberry-Pi packages

The content of this topic has been archived on 13 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

In this thread I will publish my makefiles and mini-howtos for the Raspberry-Pi.

note:
Raspberry-Pi will abbreviated here as RPI.
The RPI version before 2 are called here 1.
I have only tested for RPI-1 on OpenWRT-15.05.
unless stated otherwise, run the commands from a Linux PC (I have used Porteus-KDE4-v3.1-x86_64).
The IP 192.168.1.1 is an example, it means the IP of the RPI.



Index:
1. Raspberry Pi Camera (ov5647) support
2. newer version of ffmpeg
3. Easycap videograpper (with usbtv or stk1160 chipset) support
4. bcm2835 library support
5. OpenWrt Raspberry Pi hardfloat build



1.) Raspberry Pi Camera (ov5647) support
-------------------------------------------------------------------

It will need:
    - the start_x.elf and fixup_x.dat in the bootpartition. Enabeling with "start_x=1" in config.txt
    - the bcm2835-v4l2 kernelmodule the source are include in the RPI-kernelsource.
    - the userprogramms raspivid and raspistill that can find here https://github.com/raspberrypi/userland
   
I have write makefiles and a build-and-download-script that are easy to use.
for RPI 1 & 2 OpenWRT-15.05 use this: owrt-rpicam-tools-15.05-1.tar.xz.
for RPI 1 (the SDK for 2 does not exist) on trunk use this: owrt-rpicam-tools-trunk-1.tar.xz. (I used a SDK snappshot from 20.09.2015).
   
The Script in my archiv download and extrackt the SDK, link my package directorys and run make.

instructions:

1.1) enable the start_x.elf:
    Mount the bootparition of the SD-Card on your PC.
    Go to there and run as root:
   

wget --no-check-certificate -O ./fixup_x.dat https://github.com/raspberrypi/firmware/blob/master/boot/fixup_x.dat?raw=true
wget --no-check-certificate -O ./start_x.elf https://github.com/raspberrypi/firmware/blob/master/boot/start_x.elf?raw=true

    put this onto your config.txt file (create it, if it not exist):
   

start_x=1
gpu_mem=128

    the gpu_mem=128 is not necessary but it should set (default is 64).

   
1.2) build the required packages:
    download and unpack my archiv.
    Change directory to it.
    You can take a look into the mkPkgWithSDK-15.05.sh file to see the usage.
    Or run it interativ.
    for 15.05 run as root:

./mkPkgWithSDK-15.05.sh

    for trunk run as root:

./mkPkgWithSDK-trunk.sh

1.3) Install the packages:
    The ready modules are in <build-dir>/owrtSDK<1|2>/bin/brcm2708/packages/base
    the modules are:
    - kmod-bcm2835-v4l2_3.18.20+2015.06.17-1_brcm2708.ipk    = the kernelmodule
    - raspicam_2015.09.09-2_brcm2708.ipk = contain the following applications and there librarys: raspistill, raspivid,
    raspiyuv  and raspividyuv
    - rpiuserland-rest_2015.09.09-2_brcm2708.ipk = contain all other applicatons and librarys of the raspberrypi/userland.

    Copy to your RPI run:

scp -r <build-dir>/owrtSDK<1|2>/bin/brcm2708/packages/base root@192.168.1.1://root

    via ssh on the RPI

cd ~/base
opkg update
opkg install kmod-bcm2835-v4l2_3.18.20+2015.06.17-1_brcm2708.ipk
opkg install raspicam_2015.09.09-2_brcm2708.ipk

   
   
1.4) test it from Linux-PC with vlc:
    simple test on RPI make a 5sek h264 Video on it
   

raspivid -o tvid.h264 

    stream test from RPI to your PC.

    On RPI:
   

opkg install ncat
raspivid -w 1920 -h 1080 -fps 20 -t 0 -o - | ncat -l 4711

    on your PC:
   

mknod /tmp/vidpipe p
nc 192.168.1.1 4711 | ffmpeg -i - -f mpeg - >> /tmp/vidpipe
vlc /tmp/vidpipe

    It is realy hard to get get a fast (small delay), cheap (small cpu and ram load) and low bandwidth (h264) stream.
    Here an another example that work at me but only in this constallation and only on Friday.
    On PC:

nc -l -p 1234 | mplayer -cache 1000 -

    On RPI:

raspivid -md 2 -ex night -ih -fl -fps 5 -t 0 -o tcp://<IP-OF-THE-PC>:1234

    when everybody have an example that work with ffmpeg and ffserver or another example i am realy thankfull.




2.) newer version of ffmpeg
-----------------------------------------------------------------------

I have littlebit modifie the orginal makefile.
I add a newer version and enable vpx support.

Makefiles and a build-and-download-script,
for RPI 1 & 2 OpenWRT-15.05 and RPI 1 trunk, use this:owrt-ffmpeg-1.tar.xz. (md5 = 576dcc581fa7e5e7cf6150ffc5724fb5)

2.1) build the required packages:
    download and unpack my archiv.
    Change directory to it.
    You can take a look into the mkPkgWithSDK.sh file to see the usage.
    Or run it interativ.
   
    The ready modules are in <build-dir>/owrtSDK<1|2|1t>/bin/brcm2708/packages/base





3.) Easycap videograpper (with usbtv or stk1160 chipset) support
-----------------------------------------------------------------------

note:
I have only test the usbtv chipset.
More information about Easycap videograppers can find at http://linuxtv.org/wiki/index.php/Easycap.

It will need:
  - the usbtv or stk1160 kernelmodule. The source are include in the RPI-kernelsource.
 
Makefiles and a build-and-download-script,
for RPI 1 & 2 OpenWRT-15.05 use this: owrt-easycap-15.05-1.tar.xz (md5 = eea300a82c9267074545ee59e29b1c9e).
 
instructions:

3.1) build the required packages:
    download and unpack my archiv.
    Change directory to it.
    You can take a look into the mkPkgWithSDK-15.05.sh file to see the usage.
    Or run it interativ.
   
    The ready modules are in <build-dir>/owrtSDK<1|2|1t>/bin/brcm2708/packages/base
   
3.2) test it:
    grab video:
    (/dev/video0 are an example replace by the right videodevice)
   

ffmpeg -i /dev/video0 -vcodec copy -an -f avi tvid0.avi

    note there is a error message in ffmpeg (2.7.2 and 2.8.1 )like this:
    "frame=   17 fps=0.0 q=-1.0 size=    4731kB time=00:00:00.65 bitrate=59563.7kbits[video4linux2,v4l2 @ 0xc24200] Dequeued v4l2 buffer contains corrupted data (691200 bytes)."
    No idea what it mean.
   
    grab sound:
    (default are an example rplace by the right PCM device name. Find out with "arecord -L")
   

arecord -D default out.wav



4.) bcm2835 library support
-----------------------------------------------------------------------

This is a C library for Raspberry Pi (RPi). It provides access to GPIO and other IO functions on the Broadcom BCM 2835 chip,
allowing access to the GPIO pins on the 26 pin IDE plug on the RPi board so you can control and interface with various external devices.

It is from here: http://www.airspayce.com/mikem/bcm2835/
for RPI 2 read this part:

For this library to work correctly on RPI2, you MUST have the device tree support enabled in the kernel. You should also ensure you are using the latest version of Linux. The library has been tested on RPI2 with 2015-02-16-raspbian-wheezy and ArchLinuxARM-rpi-2 as of 2015-03-29.
When device tree suport is enabled, the file /proc/device-tree/soc/ranges will appear in the file system, and the bcm2835 module relies on its presence to correctly run on RPI2 (it is optional for RPI1). Without device tree support enabled and the presence of this file, it will not work on RPI2.

   
I have done Makefiles and a build-and-download-script here: owrt-bcm2835-library-1.tar.xz (md5 = 61e45446c8b612897f92530987dc5192).
In the package/bcm2835 is the makefile for building and adding the header and static-library files to the SDK.
In the package/bcm2835_examples is the "blink" and "event" example that is included in the bcm2835 library source.
blink switsch the the pin-11 (gpio-17) permanent on/off.
event wait for a low event on pin-15 (gpio-22).

instructions:

4.1) adding bcm2835 to the SDK:
    download and unpack my archiv.
    Change directory to it.
    You can take a look into the mkPkgWithSDK.sh file to see the usage.
    Or run it interativ.
    example:

./mkPkgWithSDK.sh

    choice 1 for RPI-1 sdkversion=15.05, 2 for RPI-2 sdkversion=15.05 or 1t for RPI-1 sdkversion=trunk
    If your choice 1 and the other values are the default values (build directory = /tmp/build and $MV_DN = owrtSDK1)
    Then is your modified SDK in /tmp/build/owrtSDK1
   
4.2) compile the blink and event examples:
    Take a look in ./mkYourPkg.sh file.
    If your new SDK in /tmp/build/owrtSDK1
    run:

SDK_D=/tmp/build/owrtSDK1 ./mkYourPkg.sh

   
4.3) Install the packages:
    The ready modules are in /tmp/build/owrtSDK1/bin/brcm2708/packages/base
    the module is: bcm2835_examples_1.46-1_brcm2708.ipk
   
    Copy to your RPI run:

scp /tmp/build/owrtSDK1/bin/brcm2708/packages/base/bcm2835_examples_1.46-1_brcm2708.ipk root@192.168.1.1://root

    via ssh on the RPI

opkg install bcm2835_examples_1.46-1_brcm2708.ipk

    Now you can test by typing via ssh on the RPI "event" or "blink"
   



   
5.) OpenWrt Raspberry Pi hardfloat build
----------------------------------------------

OpenWrt is in many cases the best choice for the Raspberry-Pi but OpenWrt is softfloat:
here is a got howto for build Openwrt hardfloat.

I have build Openwrt-15.05 for RPI-1 complete(md5: 27637371c0db5d7cddb8307d4d206893),
Openwrt-trunk (ca 2015.11.03) for RPI-1 base(md5: 7c37007411a1e5355c18cec14b62d0d0),
and build scripts for simple using (md5: 969bf11747a1248b71aa54a237bd1a5e).

note: the builds are not strong tested



5.1) Instructions fo my scripts:

you need:
25GB free space on /tmp/build (the build directory names should be short)
Full write rights for unprivileged user on /tmp/build
Diverse developing packages like ccache or zlib
A fast and stable internet connection.
a lot of time:

For Openwrt-15.05 RPI-1|2 use ./owrtb-rpi-15.05.sh RPI-1|2
For Openwrt-trunk RPI-1 use ./owrtb-rpi-trunk.sh (i have no configuration for RPI-2 yet)
Take a look at the head of the script and run it for help without any commands.
It is self explanatory

as root:
unpack buildscr.tar.gz and go to buildscr
make full write rights to ./dl and ./result

chmod -R 0777 ./dl ./result 

as unprivileged user:
(it is possible to run ./owrtb-rpi-15.05.sh as root, but not ./owrtb-rpi-trunk.sh)
for this example we build Openwrt-15.05 for RPI-2 hardfloat:
run:

./owrtb-rpi-15.05.sh cfg-base -2

This command download, unpack and configure the source.
At menuconfig you may a change but should not.

./owrtb-rpi-15.05.sh build-base -2

this is the build command (make V=s).
On a Pentium D i need 5h

./owrtb-rpi-15.05.sh cfg-pkg -2

It use the created SDK for package building.
Unpacking and configuration.

./owrtb-rpi-15.05.sh rebuild-pkg -2

On a Pentium D i need 24h
It build the packages with IGNORE_ERRORS=1 you should use the command mutiple times.
When no new packages will be build you are ready.

./owrtb-rpi-15.05.sh mkindex -2

It creates a make log from the packages that will not be build.
And it make the package index.

Your result is in ./result/owrtbuild-15.05-rpi2hf-${BUILDNAME_SFX}
in bcm2708 (RPI-1) or bcm2709 (RPI-2) are images, packages etc.
in the last error_*.log file you can see which build was wrong.
in the errorpkg.tar.xz is a copy of following directorys from the SDK:
./feeds and ./package contain now only the fail packages.
./ready_feeds are the pass packages.
./log the make log of the fail packages.



   
   
last modified on 17.11.2015

(Last edited by Plonk34 on 17 Nov 2015, 06:15)

I have make a update:
Buildscripts, configs and the package-source from below are inside
this archive: buildscr-16.05.1.tar.gz (md5=8a582240c3b8488c134bee687d4f2054)

the Camera driver bcm2835-v4l2 are now inside trunk, it called kmod-video-bcm2835.



Raspberry Pi 1
It is softfloat by default.
I have make hardfloat builds with this parameter: "-O3 -pipe -march=armv6 -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard"

OpenWRT Chaos-Calmer (15.05):
build        owrtbuild-rpi1hf-15.05.1-2016.05.01.tar.xz                 (md5=18cbceb763f7a3a9f1f3dc5261c753f4)
image     ext4img-15.05.1-rpi1-2016.05.08_12-52-12.tar.xz    (md5=ea923a741ec7c573ced419c71692524b)

OpenWRT designed driver of Chaos-Calmer (trunk):
build        owrtbuild-rpi1hf-trunk-2016.05.27.tar.xz                 (md5=8c4ec2f10997f4f50b85267ffce5549b)
image     ext4img-trunk-rpi1-2016.06.17_09-59-00.tar.xz    (md5=48a6c3fea1e71cba6eb3259d657d53a2)





Raspberry Pi 2
The trunk branch (later 15.05) is hardfloat.
I have make a trunk build, but i have not tested.

OpenWRT designed driver of Chaos-Calmer (trunk):
build        owrtbuild-rpi2hf-trunk-2016.05.26.tar.xz                 (md5=171d3c84a2d846bd259929cef73b226d)
image     ext4img-trunk-rpi2-2016.06.17_10-34-05.tar.xz    (md5=a5dcfc26b4bf99d0d76afea45a568691)



Raspberry Pi 3
It is hardfloat by default and the subtarget 2710 are in trunk, but not in chaos-calmer.
I have make a trunk build, but i have not tested.

OpenWRT designed driver of Chaos-Calmer (trunk):
build        owrtbuild-rpi3hf-trunk-2016.04.30.tar.xz                (md5=165b68ff27ce5aa6743954b2d7e271cb)
image     ext4img-trunk-rpi3-2016.06.17_10-59-53.tar.xz   (md5=e867759811483a9a1f0da1d3d16e6d9a)






Installing the ext4 image:

It exist many methods to install the ext4 image.
the simplest are (/dev/sdd are an example it means your SD-card)

 dd of=/dev/sdd if=./openwrt-brcm2708-bcm2708-rpi-ext4-sdcard.img bs=4M

or prepare the SD-card manuell see here.

My favorite is to use the OpenWrt-ImageBuilder:
Basically i have used this code for building the images from below.

# Unpack image builder and change directory to it.
rm -r ./OpenWrt-ImageBuilder-brcm2708-bcm2710.Linux-x86_64
tar -xf /pathOfImageBuilder/OpenWrt-ImageBuilder-brcm2708-bcm2710.Linux-x86_64.tar.bz2
cd ./OpenWrt-ImageBuilder-brcm2708-bcm2710.Linux-x86_64

# on chaos_calmer RPI-1 download the original firmware
wget -c --no-check-certificate -O ./rpi-firmware-38aa676b044f8de46aedb4bd972538a7ad6a3ce1tar.gz https://github.com/Hexxeh/rpi-firmware/archive/38aa676b044f8de46aedb4bd972538a7ad6a3ce1.tar.gz
test -d ./rpi-firmware-38aa676b044f8de46aedb4bd972538a7ad6a3ce1 && rm -r ./rpi-firmware-38aa676b044f8de46aedb4bd972538a7ad6a3ce1
tar -xf ./rpi-firmware-38aa676b044f8de46aedb4bd972538a7ad6a3ce1.tar.gz

# giving packages repositories paths to Imagebuilder
cat << EOF > ./repositories.conf

## the syntax is "src <any-name-for-distinguish> <destination>"
## note PathToPackagesStepX starts with /

src chaos_calmer1_step1_base     file://${PathToPackagesStep1}/base
src chaos_calmer1_step1_kernel     file://${PathToPackagesStep1}/kernel

src chaos_calmer1_step2_base         file://${PathToPackagesStep2}/base
src chaos_calmer1_step2_custom         file://${PathToPackagesStep2}/custom
src chaos_calmer1_step2_custom_kernel     file://${PathToPackagesStep2}/custom_kernel
src chaos_calmer1_step2_kernel         file://${PathToPackagesStep2}/kernel
src chaos_calmer1_step2_luci         file://${PathToPackagesStep2}/luci
src chaos_calmer1_step2_management     file://${PathToPackagesStep2}/management
src chaos_calmer1_step2_packages     file://${PathToPackagesStep2}/packages
src chaos_calmer1_step2_routing     file://${PathToPackagesStep2}/routing
src chaos_calmer1_step2_telephony     file://${PathToPackagesStep2}/telephony


# example for a Remote package repositorie:
#src/gz chaos_calmer_base http://downloads.openwrt.org/chaos_calmer/15.05.1/brcm2708/bcm2708/packages/base


## This is the local package repository, do not remove!
src imagebuilder file:packages

EOF





## add a extra system root to the image (these files inside will overcopy)
mkdir ./my-extra-root

# causes that the RPI work as dhcpclient
mkdir -p ./my-extra-root/etc/config
cat << EOF > ./my-extra-root/etc/config/network
# Copyright (C) 2006 OpenWrt.org

config interface loopback
    option ifname    lo
    option proto    static
    option ipaddr    127.0.0.1
    option netmask    255.0.0.0

config interface lan
    option ifname    eth0
    option proto    dhcp
    option ip6assign 60

config globals globals
    option ula_prefix auto
EOF

# causes that the third partition (if exist) are mounted
cat << EOF > ./my-extra-root/etc/rc.local
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

test -d /mnt/mmcblk0p3 || mkdir -p /mnt/mmcblk0p3
mount /dev/mmcblk0p3 /mnt/mmcblk0p3

exit 0
EOF

# copy the complete packages to the Image
mkdir -p ./my-extra-root/opt/repository/build1
cp -a ${PathToPackagesStep1} ./my-extra-root/opt/repository/build1
mkdir -p ./my-extra-root/opt/repository/build2
cp -a ${PathToPackagesStep2} ./my-extra-root/opt/repository/build2

# modifie opkg so that the local copy of packages will be used
cat << EOF > ./my-extra-root/etc/opkg.conf
dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists
option overlay_root /overlay
# option check_signature 1
EOF

mkdir -p ./my-extra-root/etc/opkg
cat << EOF > ./my-extra-root/etc/opkg/distfeeds.conf

EOF
cat << EOF > ./my-extra-root/etc/opkg/customfeeds.conf
# add your custom package feeds here
#
# src/gz example_feed_name http://www.example.com/path/to/files

src/gz chaos_calmer1_1base    file:///opt/repository/build1/packages/base
src/gz chaos_calmer1_1kernel     file:///opt/repository/build1/packages/kernel

src/gz chaos_calmer1_2base        file:///opt/repository/build2/packages/base
src/gz chaos_calmer1_2kernel         file:///opt/repository/build2/packages/kernel
src/gz chaos_calmer1_2packages         file:///opt/repository/build2/packages/packages
src/gz chaos_calmer1_2luci         file:///opt/repository/build2/packages/luci
src/gz chaos_calmer1_2routing         file:///opt/repository/build2/packages/routing
src/gz chaos_calmer1_2telephony     file:///opt/repository/build2/packages/telephony
src/gz chaos_calmer1_2management     file:///opt/repository/build2/packages/management
src/gz chaos_calmer1_2custom         file:///opt/repository/build2/packages/custom
src/gz chaos_calmer1_2custom_kernel     file:///opt/repository/build2/packages/custom_kernel

EOF





# changing size of partition1 + 2
sed s/".*CONFIG_BRCM2708_SD_BOOT_PARTSIZE.*"/"CONFIG_BRCM2708_SD_BOOT_PARTSIZE=32"/ -i ./.config
sed s/".*CONFIG_TARGET_ROOTFS_PARTSIZE.*"/"CONFIG_TARGET_ROOTFS_PARTSIZE=984"/ -i ./.config
# more inodes for more files in image
sed s/".*CONFIG_TARGET_EXT4_MAXINODE.*"/"CONFIG_TARGET_EXT4_MAXINODE=16000"/ -i ./.config




# creating the image
# PROFILE=RaspberryPi_3 = subtarget bcm2710 / PROFILE=RaspberryPi_2 = subtarget bcm2709 / PROFILE=RaspberryPi = subtarget bcm2708
# FILES=my-extra-root/    overcopy the image root with files from ./my-extra-root
# BIN_DIR=../mybindir    where the resulting image are saved
# PACKAGES="kmod-video-bcm2835 luci" add luci and the camera driver
mkdir -p ../mybindir
make image PROFILE=RaspberryPi_3 FILES=my-extra-root/ BIN_DIR=../mybindir PACKAGES="kmod-video-bcm2835 luci"
# or use this example it removes the ppp and ppp-mod-pppoe module
# make image PROFILE=RaspberryPi_3 FILES=my-extra-root/ BIN_DIR=../mybindir PACKAGES="-ppp -ppp-mod-pppoe kmod-video-bcm2835 luci"





## making some changes in partition 1 of the image
# mount the partition 1 of image to /mnt/owrt/p1
OFFSETBLK=$(fdisk -l ../mybindir/openwrt-brcm2708-bcm2710-rpi-ext4-sdcard.img | grep ".img1" | sed -r s/"[[:blank:]]+"/":"/g | cut -d: -f3)
mkdir -p /mnt/owrt/p1
umount /mnt/owrt/p1
mount -o loop,offset=$(($OFFSETBLK * 512)) ../mybindir/openwrt-brcm2708-bcm2710-rpi-ext4-sdcard.img /mnt/owrt/p1
# moving config.txt and cmdline.txt to *.old for info 
cd /mnt/owrt/p1
mv /mnt/owrt/p1/config.txt /mnt/owrt/p1/config.txt.old

# make a new conifig.txt
cat << EOF > /mnt/owrt/p1/config.txt

boot_delay=1

kernel=kernel.img

start_x=1
gpu_mem=128

dtparam=i2c1=on
# on old models use:
#dtparam=i2c0=on
# instead
dtparam=spi=on
dtparam=i2s=on

EOF

## adding start_x.elf for camera support
## on trunk use this:
# wget --no-check-certificate -O ./fixup_x.dat https://github.com/raspberrypi/firmware/blob/master/boot/fixup_x.dat?raw=true
# wget --no-check-certificate -O ./start_x.elf https://github.com/raspberrypi/firmware/blob/master/boot/start_x.elf?raw=true
## on chaos calmer use copy from original
cp -avf ./rpi-firmware-38aa676b044f8de46aedb4bd972538a7ad6a3ce1/start_x.elf /mnt/owrt/p1
cp -avf ./rpi-firmware-38aa676b044f8de46aedb4bd972538a7ad6a3ce1/fixup_x.dat /mnt/owrt/p1

# umount the image
cd ~
sync
umount /mnt/owrt/p1




############################################################################################

I wondering that nobody complain.
The RPI-1 trunk images was readonly.
(RPI-2 / 3 no idea, i can not test but i thing it was the same.)
I have only done a short test, after building.
For few days need my image and noticed that it is readonly.
The workaround is here: https://forum.openwrt.org/viewtopic.php?id=65359
Thanks for that.

I have fixed all images now.



last modified on 18.06.2016

(Last edited by Plonk34 on 18 Jun 2016, 09:12)

Plonk34, I see that you are poweruser with Raspberry Pi and OpenWRT.
Maybe you can advise with my problem?
https://forum.openwrt.org/viewtopic.php?id=66309

I would like to install python rpi.gpio to use it with my HD44780 LCD.
Did you have similar problem?

Best regards

Not at the moment.
I have not much time at the moment.
And i have not much experience with python.
For playing with GPIOs i was used C and the bcm2835 library.

Have i right understand you have try to install RPi.GPIO with pip or python install on the RPI with OpenWRT on it ?

I thing the best way is to make a RPi.GPIO package.
Copy the Makefile from an equal package and modifie them and try to build the package via SDK.

I can confirm camera works on Raspberry PI3 with the above information.
Compiled the openwrt from master branch shaid 5ce38c486c525b28d9784f83e839537aa0149123, added start_x.elf and fixup_x.dat in /boot and added gpu_mem=128 and start_x=1 in /boot/config.txt

I have /dev/video0 and raspistil works.

hello,

was your build with ext4 or jffs2?

reg

ext4
I was tryed a lot to start RPI with jffs2 or squashfs, but i fail always.

The discussion might have continued from here.