Wikia

CHDK Wiki

Changes: Getting CHDKPTP on BeagleBone Black to work

Edit

Back to page

(Crosscompile CHDKPTP)
(Miscellaneous spelling & typos)
Line 1: Line 1:
 
=Intro=
 
=Intro=
   
Would it not be great to use a small computer board like the BeagleBone Black to contol you Canon CHDK enabled camera?
+
Would it not be great to use a small computer board like the BeagleBone Black to contol your 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!
+
Then via using the remoteshoot analyze, 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 your pictures of a slow growing flower in your garden. The possibilities would be endless!
   
 
So that is what we are set out to do; '''Make CHDKPTP work on a Beagle Bone Black'''.
 
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.
+
And the "We" is "You" here. As you know, Open-source does not work without '''your contribution''' in whatever way. So, take your chance for for fame and glory, try it, improve this page; let's get it to work together.
   
 
===Outcome===
 
===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.
 
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.
+
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.
 
We assume you use Linux and have basic knowlege about using the bash shell.
Line 19: Line 19:
   
 
* learning to use CHDK
 
* learning to use CHDK
* Letting you know how to use the CHDKPTP client
+
* letting you know how to use the CHDKPTP client
* Educating about crosscompiling
+
* educating about crosscompiling
* Using the Linux shell
+
* using the Linux shell
   
 
For all of the above there are other resources
 
For all of the above there are other resources
Line 27: Line 27:
 
=Start=
 
=Start=
   
Let's start by taking a coffee an listen to some uplifting music, e,g, Marasco - It's a feeling
+
Let's start by taking a coffee and listening to some uplifting music, e,g, Marasco - It's a feeling
   
 
Then first compile CDKPTP to be able to test on local PC
 
Then first compile CDKPTP to be able to test on local PC
Line 41: Line 41:
 
$ cd ~/develop/chdkptp/
 
$ cd ~/develop/chdkptp/
   
OK now copy the basic config file
+
Ok now copy the basic config file
   
 
$ cp -av config-sample-linux.mk config.mk
 
$ cp -av config-sample-linux.mk config.mk
Line 53: Line 53:
 
$ make
 
$ 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"
+
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.
+
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==
 
==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.
+
Grab your 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 [http://mighty-hoernsche.de/ latest CHDK] version on your SD of the camera. Older versions of CHDK tend to not work with well togeter with CHDKPTP.
+
Also be sure you installed the [http://mighty-hoernsche.de/ latest CHDK] version on your SD of the camera. Older versions of CHDK tend to not work with well together with CHDKPTP.
   
 
1. Connect your CHDK enabled camera, in our test case my Canon IXUS200 IS. Power up the camera in playback mode.
 
1. Connect your CHDK enabled camera, in our test case my Canon IXUS200 IS. Power up the camera in playback mode.
Line 74: Line 74:
 
<con>q
 
<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:
+
Note that IMG_6666.jpg is 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
 
This page is not about learning to use CHDK
   
Line 109: Line 109:
 
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
 
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
+
Connect BBB to UAB port, we can connect to it by default using the Agstrom Linux already installed from the factory
   
 
So let's copy our "Hello" over to your BBB via
 
So let's copy our "Hello" over to your BBB via
Line 124: Line 124:
 
==Crosscompile LUA==
 
==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...)
+
We must get the **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:
 
Cross compiled Lua for ARM architecture via:
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 a compile error if we don't disable it. Ao alter it via:
+
Disable readline library, it is optional feature we do not use, we get a compile error if we don't disable it. So alter it via:
   
 
$ nano src/luaconf.h
 
$ nano src/luaconf.h
Line 186: Line 186:
 
===Test Lua===
 
===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
+
For fun we can see if the Lua executable works on the BBB, just to boost confidence that the Lua library also compiled correctly
   
 
$ rsync -av --progress root@lua 192.168.7.2:~/
 
$ rsync -av --progress root@lua 192.168.7.2:~/
Line 203: Line 203:
 
3
 
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.
+
Yes? wow, it worked(tm). We do not need this Lua executable, we only want the library to link to the CHDKPTP executable, but it was nice to toy around with it a little.
   
=== Avaialble ===
+
=== Available ===
   
Now let'ssee if the compiler has created the library file we need for CHDKPTP to link to:
+
Now let's see if the compiler has created the library file we need for CHDKPTP to link to:
   
 
$ ls *.a
 
$ ls *.a
Line 215: Line 215:
 
==Crosscompile LibUSB==
 
==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
+
And we also need to crosscompile LibUSB ( http://www.libusb.org/ ). CHDKPTP interacts over USB and for this uses libusb, so on to compiling the library
   
 
$ cd ~/develop/chdkptp-bbb
 
$ cd ~/develop/chdkptp-bbb
Line 246: Line 246:
 
PTPIP_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
+
And also let's put those locations in the path of the CHDK config.mk so the compiler knows where it can find the libraries to link to
   
 
LUA_INCLUDE_DIR=$(PWD)/lua-5.1.5/src
 
LUA_INCLUDE_DIR=$(PWD)/lua-5.1.5/src
Line 268: Line 268:
 
Now we will crosscompile CHDKPTP via
 
Now we will crosscompile CHDKPTP via
   
{TODO} add much more explanation here
+
{TODO} add much more explaination here
   
 
$ make
 
$ make
Line 278: Line 278:
 
=The Future=
 
=The Future=
   
Help us out to relize our dream; CHDKPTP on the BeagleBone Black by improving this page.
+
Help us out to realize our dream; CHDKPTP on the BeagleBone Black by improving this page.
   
 
=Links=
 
=Links=

Revision as of 23:31, February 24, 2014

Intro

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

Then via using the remoteshoot analyze, 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 your pictures of a slow growing flower in your garden. The possibilities would be endless!

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 you know, Open-source does not work without your contribution in whatever way. So, 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 and listening 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 your 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 together 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 is 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 from the 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 the **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. So 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 confidence that 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 library to link to the CHDKPTP executable, but it was nice to toy around with it a little.

Available

Now let's see 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 uses 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 let's put those locations in the path of the CHDK config.mk so the compiler knows where it can find the libraries 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 explaination 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 realize our dream; CHDKPTP on the BeagleBone Black by improving this page.

Links

Around Wikia's network

Random Wiki