Wikia

CHDK Wiki

Getting CHDKPTP on BeagleBone Black to work

Talk2
572pages on
this wiki
Revision as of 20:34, February 17, 2014 by Openuas (Talk | contribs)

Intro

Would it not be great to use a small computer board like the BeagleBone Black to contol you Canon CHDK enabled camera?

Then via using the remoteshoot analyse, alter, detect or do whatever with the picture taken. Or imagine even running a small webserver on the board where everyone could just connect to look at you pictures of a slow growing flower in your garden. The possibilities would be endess!

So that is what we are set out to do; Make CHDKPTP work on a Beagle Bone Black.

And the "We" is "You" here. As ou know, Open-source does not work without your contribution in whatever way. o, take your chance for for fame and glory, try it, improve this page; let's get it to work together.

Outcome

The wished outcome of this combined effort is a working crosscompiled chdkptp non gui client that runs on a BeagleBone black mini computer board. Note: And this via pure cross compiling, thus not compiling on the BBB but on the local PC with ARM GCC crosscompiler of choice installed.

We assume you use Linux and have basic knowlege about using the bash shell.

What this page is not about

  • learning to use CHDK
  • Letting you know how to use the CHDKPTP client
  • Educating about crosscompiling
  • Using the Linux shell

For all of the above there are other resources

Start

Let's start by taking a coffee an listen to some uplifting music, e,g, Marasco - It's a feeling

Then first compile CDKPTP to be able to test on local PC

$ sudo apt-get install liblua5.1 liblua5.1-dev
$ sudo apt-get install libusb-1.0-0 libusb-1.0-dev

Let's get the CHDKPTP source

$ mkdir -p ~/develop/
$ cd ~/develop/
$ svn co http://subversion.assembla.com/svn/chdkptp/trunk chdkptp
$ cd ~/develop/chdkptp/

OK now copy the basic config file

$ cp -av config-sample-linux.mk config.mk

Edit config.mk and disable the GUI settings

$ nano config.mk

Compile the local CHDKPTP client via

$ make

Note:If it does not work I recall, someone wrote "I downloaded a ptp.h file which differs from the ptp.h file in the svn download, and put it into /usr/src/chdkptp/core. I did this by downloading it to my laptop. The file came from here:http://trac.assembla.com/chdk/browser/trunk/core/ptp.h"

That step above I've skipped and it still worked, so likely obsolete, but better mention it here. If all Works 100% we can clean up the instruction on this page a little more.

Local PC Test

Grab you Camera. We assume you already have CHDK working on your camera, if not, make that happen first before you continue. Also be sure you installed the latest CHDK version on your SD of the camera. Older versions of CHDK tend to not work with well togeter with CHDKPTP.

1. Connect your CHDK enabled camera, in our test case my Canon IXUS200 IS. Power up the camera in playback mode. 2. start the CHDKPTP client in the lua subdirectory... inconvieniently strange; really needed?, Yes! So start via:

$ cd ~/develop/chdkptp/lua
$ ../chdkptp -i -c

<con> =switch_mode_usb(1) <con> lua shoot() <con> =switch_mode_usb(0) <con> download A/DCIM/123CANON/IMG_6666.JPG IMG_6666.jpg <con>q

Note that IMG_6666.jpg if ]fictional, will be different on your camera. To learn more about how to use the cleint read: This page is not about learning to use CHDK

Crosscompiling

Now on to the real deal of what this what page is all about:

Tryout

First a small cross compile "Hello world" tryout to get in the crosscompiling mood

$ nano hello.c
#include <stdio.h>

int main(int argc, char* argv[])
{
  printf("Hello ARM World!\n");
  return 0;
}
$ nano crosscompile.sh
arm-linux-gnueabi-gcc -march=armv7-a -mtune=cortex-a8 -mfpu=neon -o hello hello.c
$ sh crosscompile.sh

Now let see if it is really for an ARM

$ file hello

Yes, it gives:

hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.31, Builld[sha1]=0xd0aa97ca192c969e7111e97aaa4604983ca62196, not stripped

Connect BBB to UAB port, we can connect to it by default using the Agstrom Linux already installed off factory

So let's copy our "Hello" over to your BBB via

$ rsync -av --progress hello root@192.168.7.2:~/
$ ssh root@192.168.7.2
$ cd ~
$ ./hello

This should give:

Hello ARM World!

Crosscompile LUA

We must get this **liblua.a** file... then we can link that later on to chdkptp (static), maybe we even start using dynamic libraries if it will save humongoes memory...)

Cross compiled Lua for ARM architecture via:

$ mkdir -p ~/develop/
$ cd ~/develop/
$ svn co http://subversion.assembla.com/svn/chdkptp/trunk chdkptp-bbb
$ cd ./chdkptp-bbb/ 
$ wget http://www.lua.org/ftp/lua-5.1.5.tar.gz
$ tar -xvzf lua-5.1.5.tar.gz
$ cd ./lua-5.1.5

Disable readline library, it is optional feature we do not use, we get a compile error if we don't disable it. Ao alter it via:

$ nano src/luaconf.h

So it will become like:

/* #define LUA_USE_READLINE*/   /* needs some extra libraries */

And also the Makefile via:

$ nano src/Makefile

So it becomes:

...
linux:
       $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl"
...

Time to change the Makefile in the src directory:

$ cd ~/develop/chdkptp-bbb/lua-5.1.5/src
$ nano Makefile

Chnage the lines so the look like:

...
CC=arm-linux-gnueabi-gcc
...
MYCFLAGS=-march=armv7-a -mtune=cortex-a8 -mfpu=neon
...

Now crosscompile it via:

$ make linux

Wait and discover after compiling if the file is compiled for the correct platform processor architecture via:

$ file lua

This will give someting like:

ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.31 BuildID[sha1]=0x4cafebabe74366e902dc33deba62443b5cfa2044, not stripped

Test Lua

For fun we can see if the Lua executable works on the BBB, just to boost confifence to expect the Lua library also compiled correctly

$ rsync -av --progress root@lua 192.168.7.2:~/
$ ssh root@lua 192.168.7.2
$ cd ~
$ ./lua

On he Lua prompt type:

> a=1
> b=2
> print(a+b)

Outputs:

3

Yes? wow, it worked(tm). We do not need this Lua executable, we only want the libary to link to the CHDKPTP executable, but it was nice to toy around with it a little.

Avaialble

Now let'ssee if the compiler has created the library file we need for CHDKPTP to link to:

$ ls *.a

Is it there? great! ...on to compiling other code needed

Crosscompile LibUSB

And we also need to crosscompile LibUSB ( http://www.libusb.org/ ). CHDKPTP interacts over USB and for this used libusb, so on to compiling the library

$ cd ~/develop/chdkptp-bbb
$ wget http://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-1.0.18/libusb-1.0.18.tar.bz2
$ tar -xvf libusb-1.0.18.tar.bz2 
$ cd ./libusb-1.0.18
$ ./configure --host=arm-linux-gnueabi --disable-udev --disable-shared
$ make

If everything was correct, the UAS library to link to is now compiled...

{TODO} determine if we use a shared lib and also if fPIC (--with-pic) is needed

This "usb-1.0.a" library file can be found in ~develop/chdkptp-bbb/libusb-1.0.18/libusb/.libs

Crosscompile CHDKPTP

We know we had already create a "liblua.a" and a "libusb-1.0.a" Note that the lib part of the filename is always left off if used in a config file.

$ cd ~/develop/chdk-bbb/
$ cp -av config-sample-linux.mk config.mk

Edit config.mk and disable the GUI settings

$ nano config.mk

IUP_SUPPORT=0
CD_SUPPORT=0
PTPIP_SUPPORT=0

And also lets put those locations in the path of the CHDK config.mk so the compiler know where it can find the libraies to link to

LUA_INCLUDE_DIR=$(PWD)/lua-5.1.5/src
LUA_LIB_DIR=$(PWD)/lua-5.1.5/src
LUA_LIB=lua

And also change the LUA_LIB in include.mk

$ nano include.mk
LUA_LIB=lua

Now give the compiler a good hint where to find the location of libusb

LIBUSB_INCLUDE_DIR=$(PWD)/libusb-1.0.18/libusb
LIBUSB_LIB_DIR=$(PWD)/libusb-1.0.18/libusb/.libs
LIBUSB_LIB=usb-1.0

Add the crosscopile extra option st include.mk

Now we will crosscompile CHDKPTP via

{TODO} add much more explanation here

$ make

Optimize

We have Hard Float options, but not of real bennefit for this as far as I can see, so for now , being able to compile is enough, no optimalization, only if needed. Boring, no doubt, however feel free to add it, it is a Wiki afteral

The Future

Help us out to relize our dream; CHDKPTP on the BeagleBone Black by improving this page.

Links

Around Wikia's network

Random Wiki