From charlesreid1

Not Working Outline: Kali ARM Image

For this project, I was replicating the Raspberry Pi timelapse setup from the RaspberryPi/Timelapse page.

Hardware

  • Raspberry Pi
  • Pi camera
  • Camera case
  • Network cable
  • Power cable

Setting up the Pi

To begin with, I installed a fresh Kali Linux arm image. I wanted to make sure I had installed the operating system correctly and that I could reach the Pi just fine. I connected the Pi directly to my laptop using a crossover cable. After connecting the two, I restarted both machines. They automatically picked link-local addresses at 169.254.X.Y, which I was able to use to SSH directly into the Pi.

This confirmed that I had everything working ok on the Pi.

Connecting to the Pi

The next step was to connect to the Pi over a network, so that the Pi would be able to download and install any necessary libraries. I started by modifying cmdline.txt on the SD card to manually set the Pi's IP address to 192.168.0.111. I then plugged the Pi into the network router, and was able to SSH into the machine at 192.168.0.111.

Installing Libraries

Once on the Pi, I needed to install some libraries. From my previous adventure at RaspberryPi/Timelapse I knew I needed a few libraries:

  • python-picamera
  • python-picamera-docs

Can't use aptitude

These packages were not in the aptitude repositories for this OS:

# apt-get install -y python-picamera python-picamera-docs
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python-picamera
E: Unable to locate package python-picamera-docs

But that's ok, because we can use pip instead!

If this is a brand new Pi, you'll need to install some tools (not all necessary, but you'll need them sooner or later.) Start with screen, so you can run the installation process in the background:

apt-get install -y screen

Then install some utilities onto the Pi:

apt-get install -y vim aptitude

Next, install Python and tools for building stuff:

apt-get install -y python build-essential

Last, install pip:

apt-get install -y python-pip 

Using pip

Now we should have pip, which will enable us install the Pi camera API:

pip install picamera

(I found this by googling the term "picamera" - one of the top results was the page for this library in the pip repository.)

# pip install picamera
Collecting picamera
  Downloading picamera-1.12.tar.gz (109kB)
    100% |████████████████████████████████| 112kB 680kB/s
Building wheels for collected packages: picamera
  Running setup.py bdist_wheel for picamera ... done
  Stored in directory: /root/.cache/pip/wheels/ec/7e/4f/ff55e2d9ee8377f0452e7f03822c3ee914c8c75a9cb9f57642
Successfully built picamera
Installing collected packages: picamera
Successfully installed picamera-1.12

Errors with libmmal

I saw errors coming from missing libmmal files when I tried to import the picamera library. The following Python code imports the picamera library:

import picamera

This failed with the following error message:

Traceback (most recent call last):
  File "lapse.py", line 3, in <module>
    import picamera
  File "/usr/local/lib/python2.7/dist-packages/picamera/__init__.py", line 72, in <module>
    from picamera.exc import (
  File "/usr/local/lib/python2.7/dist-packages/picamera/exc.py", line 41, in <module>
    import picamera.mmal as mmal
  File "/usr/local/lib/python2.7/dist-packages/picamera/mmal.py", line 47, in <module>
    _lib = ct.CDLL('libmmal.so')
  File "/usr/lib/python2.7/ctypes/__init__.py", line 362, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libmmal.so: cannot open shared object file: No such file or directory

After some googling, I discovered that libmmal.so is supposed to reside in /opt/vc, which is where the Raspberry Pi stores its VideoCore API files. More information here: [1]

The source code for building this library is available on Github here: https://github.com/raspberrypi/firmware/tree/master/opt/vc

Precompiled binaries of these libraries are available here: https://github.com/raspberrypi/firmware/tree/master/hardfp/opt/vc

This repository looked promising, until it ended up being so large it ate up all the available space on the Pi: https://github.com/raspberrypi/firmware.git

It seems to have precompiled versions of libraries and binaries and things, available to port over to the Pi. Dunno.

Alternate route: install raspi-config

Even though it is intended for Raspbian, we can try using the raspi-config utility, which is what Raspbian users use to enable the camera module on their Raspberry Pi. It is not available on ours because we installed our own operating system.

The .deb file for the raspi-config utility is difficult to find, but the link to all the release versions listed by date going back about 5 years are available online here: http://archive.raspberrypi.org/debian/pool/main/r/raspi-config/

From there, you copy the link to the .deb installer file, and download it to the Pi:

wget http://archive.raspberrypi.org/debian/pool/main/r/raspi-config/raspi-config_20160527_all.deb

To install the contents of a deb file, use the dpkg utility with the -i flag, for install.

These packages have unmet dependencies:

# apt-get -f install libasound2 lua5.1 alsa-utils
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 alsa-utils : Depends: libfftw3-double3 but it is not going to be installed
 libasound2 : Depends: libasound2-data (>= 1.1.1-2) but 1.1.0-1 is to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

This whole deal is worded in a very confusing way. If you try running apt-get -f install (something), your command will fail, with everything depending on everything else and nothing actually installing and nothing working. But this is the wrong way to do it! They want you to run apt-get -f install with NO arguments. This installs all the necessary packages.

# apt-get -f install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  alsa-utils libasound2 libasound2-data libfftw3-double3 lua5.1
Suggested packages:
  libfftw3-bin libfftw3-dev
The following NEW packages will be installed:
  alsa-utils libfftw3-double3 lua5.1
The following packages will be upgraded:
  libasound2 libasound2-data
2 upgraded, 3 newly installed, 0 to remove and 488 not upgraded.
1 not fully installed or removed.
Need to get 2,229 kB of archives.
After this operation, 3,360 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://kali.localmsp.org/kali kali-rolling/main armhf lua5.1 armhf 5.1.5-8 [75.7 kB]
Get:2 http://kali.localmsp.org/kali kali-rolling/main armhf libasound2 armhf 1.1.1-2 [472 kB]
Get:3 http://kali.localmsp.org/kali kali-rolling/main armhf libasound2-data all 1.1.1-2 [198 kB]
Get:4 http://kali.localmsp.org/kali kali-rolling/main armhf libfftw3-double3 armhf 3.3.4-2+b1 [437 kB]
Get:5 http://kali.localmsp.org/kali kali-rolling/main armhf alsa-utils armhf 1.1.1-1 [1,047 kB]
Fetched 2,229 kB in 3s (723 kB/s)
Selecting previously unselected package lua5.1.
(Reading database ... 117736 files and directories currently installed.)
Preparing to unpack .../lua5.1_5.1.5-8_armhf.deb ...
Unpacking lua5.1 (5.1.5-8) ...
Preparing to unpack .../libasound2_1.1.1-2_armhf.deb ...
Unpacking libasound2:armhf (1.1.1-2) over (1.1.0-1) ...
Preparing to unpack .../libasound2-data_1.1.1-2_all.deb ...
Unpacking libasound2-data (1.1.1-2) over (1.1.0-1) ...
Selecting previously unselected package libfftw3-double3:armhf.
Preparing to unpack .../libfftw3-double3_3.3.4-2+b1_armhf.deb ...
Unpacking libfftw3-double3:armhf (3.3.4-2+b1) ...
Selecting previously unselected package alsa-utils.
Preparing to unpack .../alsa-utils_1.1.1-1_armhf.deb ...
Unpacking alsa-utils (1.1.1-1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for libc-bin (2.23-2) ...
Processing triggers for systemd (229-2) ...
Setting up lua5.1 (5.1.5-8) ...
update-alternatives: using /usr/bin/lua5.1 to provide /usr/bin/lua (lua-interpreter) in auto mode
update-alternatives: using /usr/bin/luac5.1 to provide /usr/bin/luac (lua-compiler) in auto mode
Setting up libasound2-data (1.1.1-2) ...
Setting up libasound2:armhf (1.1.1-2) ...
Setting up libfftw3-double3:armhf (3.3.4-2+b1) ...
Setting up alsa-utils (1.1.1-1) ...
Setting up raspi-config (20160527) ...
update-rc.d: We have no instructions for the raspi-config init script.
update-rc.d: It looks like a non-network service, we enable it.
Processing triggers for libc-bin (2.23-2) ...
Processing triggers for systemd (229-2) ...

Now we can install the raspi-config utility:

# dpkg -i raspi-config_20160527_all.deb
(Reading database ... 117835 files and directories currently installed.)
Preparing to unpack raspi-config_20160527_all.deb ...
Unpacking raspi-config (20160527) over (20160527) ...
Setting up raspi-config (20160527) ...
Processing triggers for systemd (229-2) ...