CHDK Wiki
Line 136: Line 136:
 
$ cd ./lua-5.1.5
 
$ cd ./lua-5.1.5
   
Disable readline library, it is optional feature we do not use, we get compiler error if we don't disable it {FIXME}plz in src/luaconf.h comment out the lines that have "LUA_USE_READLINE" and in src/Makefile remove "-lreadline" everywhere.
+
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
Now it will look like: $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl"
 
   
  +
So it will become like:
Crosscompile it via:
 
   
 
/* #define LUA_USE_READLINE*/ /* needs some extra libraries */
$ cd ~/develop/chdkptp-bbb/lua-5.1.5/src
 
$ make linux CC=arm-linux-gnueabi-gcc AR="arm-linux-gnueabi-ar rcu" RANLIB=arm-linux-gnueabi-ranlib
 
   
 
And also the Makefile via:
OR
 
   
  +
$ nano src/Makefile
1. change the luaconf.h:
 
   
  +
So it becomes:
#define LUA_USE_READLINE /* needs some extra libraries */
 
  +
...
to
 
// #define LUA_USE_READLINE /* needs some extra libraries */
 
   
  +
linux:
2. change the Makefile
 
 
$(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl"
  +
...
  +
 
Crosscompile it via:
  +
 
$ cd ~/develop/chdkptp-bbb/lua-5.1.5/src
 
$ make linux CC=arm-linux-gnueabi-gcc AR="arm-linux-gnueabi-ar rcu" RANLIB=arm-linux-gnueabi-ranlib
   
  +
Alternative is to change the Makefile to contain:
! CC= arm-linux-gnueabi-gcc
 
! MYCFLAGS= -march=armv7-a -mtune=cortex-a8 -mfpu=neon
 
   
 
CC= arm-linux-gnueabi-gcc
! $(MAKE) all MYCFLAGS+=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl"
 
 
MYCFLAGS= -march=armv7-a -mtune=cortex-a8 -mfpu=neon
   
 
Now crosscompile it via:
 
Now crosscompile it via:
Line 164: Line 169:
 
$ make linux
 
$ make linux
   
Discover if the platform is compiled for is correct:
+
Discover if the file is compiled for the correct platform processor arcitecture via:
   
 
$ file lua
 
$ file lua

Revision as of 20:03, 17 February 2014

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"
...

Crosscompile it via:

$ cd ~/develop/chdkptp-bbb/lua-5.1.5/src
$ make linux CC=arm-linux-gnueabi-gcc AR="arm-linux-gnueabi-ar rcu" RANLIB=arm-linux-gnueabi-ranlib

Alternative is to change the Makefile to contain:

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

Now crosscompile it via:

$ make linux

Discover if the file is compiled for the correct platform processor arcitecture via:

$ file lua

Then see if the compiler has created the file and i

$ ls *.a

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

Test Lua

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

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

In prompt:

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

Outputs:

3

Yes? wow, it worked(tm)

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/download?use_mirror=netcologne#
$ tar -xvf libusb-1.0.18.tar.bz2 
$ cd ~/develop/chdkptp-bbb/libusb-1.0.18
$ ./configure --host=arm-linux-gnueabi --disable-udev --disable-shared --with-pic

That compiled at least!

{TODO} determine if we use a shared lib and also if fPIC is needed

anyhow now we have the "usb-1.0.a" library file 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"

Good lets put that location in the path of the CHDK config.mk Note that libs the lib part of the filename is always left off if defined. Good 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

also changed the LUA_LIB in include.mk to

LUA_LIB=lua

Give the compile a 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