CHDK Wiki
(Inital page with instruction to get CHDKPTP running headless on a BeagleBone Black)
 
No edit summary
 
(18 intermediate revisions by 4 users not shown)
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 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 oucome of this 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 also assume you use Linux, in our case Ubuntu 12.04 LTS 64bit
+
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=
 
=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
   
Thne first compile CDKPTP to be able to test on local PC
+
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 liblua5.1 liblua5.1-dev
 
$ sudo apt-get install libusb-1.0-0 libusb-1.0-dev
 
$ sudo apt-get install libusb-1.0-0 libusb-1.0-dev
   
  +
Let's get the CHDKPTP source
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:
 
   
  +
$ mkdir -p ~/develop/
http://trac.assembla.com/chdk/browser/trunk/core/ptp.h
 
  +
$ cd ~/develop/
  +
$ svn co http://subversion.assembla.com/svn/chdkptp/trunk chdkptp
  +
$ cd ~/develop/chdkptp/
   
  +
Ok now copy the basic config file
Copy the config file "cp /usr/src/chdkptp/config-sample-linux.mk config.mk"
 
  +
 
$ 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
 
Compile the local CHDKPTP client via
Line 34: Line 53:
 
$ make
 
$ make
   
  +
==Local PC Test==
Connect your camera, in our test case my Canon IXUS200 IS.
 
  +
Power up the camera in playback mode
 
  +
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 together with CHDKPTP.
  +
  +
To run chdkptp on Linux, the Lua path must be set, or the chdkptp must be run from the lua sub-directory. The recommended way to do this is using a shell script, like the example provided in chdkptp-sample.sh. Edit chdkptp-sample.sh, change CHDKPTP_DIR to the full path to the directory where the chdkptp binary is and save the file as chdkptp.sh. Remember to make chdkptp.sh executable.
  +
 
1. Connect your CHDK enabled camera, in our test case my Canon IXUS200 IS. Power up the camera in playback mode.
  +
  +
2. Run chdkptp
  +
 
$ ./chdkptp.sh -i -c
   
 
<con> =switch_mode_usb(1)
$ cd lua
 
 
<con> lua shoot()
$ ../chdkptp -i -c
 
 
<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:
<con> =switch_mode_usb(1)
 
  +
This page is not about learning to use CHDK
<con> lua set_zoom(3)
 
<con> lua shoot()
 
<con> =switch_mode_usb(0)
 
<con> download A/DCIM/123CANON/IMG_6666.JPG ~/develop/chdkptp-bbb/IMG_6666.jpg
 
<con>q
 
   
 
=Crosscompiling=
 
=Crosscompiling=
Line 79: Line 107:
 
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 94: Line 122:
 
==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:
   
 
$ mkdir -p ~/develop/
 
$ mkdir -p ~/develop/
  +
$ cd ~/develop/
$ svn co {TODO} url here} chdkptp-bbb
 
$ cd ~/develop/chdkptp-bbb/
+
$ 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
 
$ wget http://www.lua.org/ftp/lua-5.1.5.tar.gz
 
$ tar -xvzf lua-5.1.5.tar.gz
 
$ tar -xvzf lua-5.1.5.tar.gz
$ 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. So 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 */
  +
 
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
 
$ cd ~/develop/chdkptp-bbb/lua-5.1.5/src
  +
$ nano Makefile
$ make linux CC=arm-linux-gnueabi-gcc AR="arm-linux-gnueabi-ar rcu" RANLIB=arm-linux-gnueabi-ranlib
 
   
  +
Chnage the lines so the look like:
OR
 
   
  +
...
1. change the luaconf.h:
 
   
 
CC=arm-linux-gnueabi-gcc
#define LUA_USE_READLINE /* needs some extra libraries */
 
to
 
// #define LUA_USE_READLINE /* needs some extra libraries */
 
   
  +
...
2. change the Makefile
 
   
 
MYCFLAGS=-march=armv7-a -mtune=cortex-a8 -mfpu=neon
! CC= arm-linux-gnueabi-gcc
 
! MYCFLAGS= -march=armv7-a -mtune=cortex-a8 -mfpu=neon
 
   
  +
...
! $(MAKE) all MYCFLAGS+=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl"
 
   
 
Now crosscompile it via:
 
Now crosscompile it via:
Line 133: Line 174:
 
$ make linux
 
$ make linux
   
Discover if the platform is compiled for is correct:
+
Wait and discover after compiling if the file is compiled for the correct platform processor architecture via:
   
 
$ file lua
 
$ file lua
   
  +
This will give someting like:
Then see if the compiler has created the file and i
 
   
  +
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
$ ls *.a
 
 
Is it there? great! ...on to compiling other code needed
 
   
 
===Test Lua===
 
===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
+
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 152: Line 191:
 
$ ./lua
 
$ ./lua
   
In prompt:
+
On he Lua prompt type:
   
 
> a=1
 
> a=1
Line 162: Line 201:
 
3
 
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.
Yes? wow, it worked(tm)
 
  +
  +
=== 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==
 
==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
$ wget http://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-1.0.18/libusb-1.0.18.tar.bz2/download?use_mirror=netcologne#
+
$ wget [http://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-1.0.18/libusb-1.0.18.tar.bz2/download?use_mirror=netcologne# 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
 
$ tar -xvf libusb-1.0.18.tar.bz2
$ cd ~/develop/chdkptp-bbb/libusb-1.0.18
+
$ cd ./libusb-1.0.18
$ ./configure --host=arm-linux-gnueabi --disable-udev --disable-shared --with-pic
+
$ ./configure --host=arm-linux-gnueabi --disable-udev --disable-shared
  +
$ make
   
  +
If everything was correct, the UAS library to link to is now compiled...
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
 
  +
As is look like LibUSB for ARM will not work CHDKPTP still ses the old function o we need to add the Compat LIBUSB library
  +
 
{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==
 
==Crosscompile CHDKPTP==
   
 
We know we had already create a "liblua.a" and a "libusb-1.0.a"
 
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/
Good lets put that location in the path of the CHDK config.mk
 
  +
$ cp -av config-sample-linux.mk 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
 
  +
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_INCLUDE_DIR=$(PWD)/lua-5.1.5/src
Line 192: Line 254:
 
LUA_LIB=lua
 
LUA_LIB=lua
   
also changed the LUA_LIB in include.mk to
+
And also change the LUA_LIB in include.mk
  +
  +
$ nano include.mk
   
 
LUA_LIB=lua
 
LUA_LIB=lua
   
Give the compile a hint where to find the location of libusb
+
Now give the compiler a good hint where to find the location of libusb
   
 
LIBUSB_INCLUDE_DIR=$(PWD)/libusb-1.0.18/libusb
 
LIBUSB_INCLUDE_DIR=$(PWD)/libusb-1.0.18/libusb
Line 206: Line 270:
 
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 216: Line 280:
 
=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=
  +
  +
* http://www.metastatic.org/text/libtool.html
  +
* DistCC
  +
* Lua
  +
* LibUSB

Latest revision as of 21:23, 30 April 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

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.

To run chdkptp on Linux, the Lua path must be set, or the chdkptp must be run from the lua sub-directory. The recommended way to do this is using a shell script, like the example provided in chdkptp-sample.sh. Edit chdkptp-sample.sh, change CHDKPTP_DIR to the full path to the directory where the chdkptp binary is and save the file as chdkptp.sh. Remember to make chdkptp.sh executable.

1. Connect your CHDK enabled camera, in our test case my Canon IXUS200 IS. Power up the camera in playback mode.

2. Run chdkptp

$ ./chdkptp.sh -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...


As is look like LibUSB for ARM will not work CHDKPTP still ses the old function o we need to add the Compat LIBUSB library

{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