BeagleBoneBlack Tutorials Rev 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

Android on Beaglebone Black (Rev 2)

Android on BeagleBone Black


UTN-FRA
Laboratorio de Software Libre
Erneto !igliotti
UTN FRA LSL http://www.lslfra.com.ar 1
Android on Beaglebone Black (Rev 2)
"ontent
T#torial $% &
Creating an S car! An!roi! Te"as #nstr$ments #mage for %eagle&one %lac'.
T#torial $2 &
Accessing the An!roi! Console &( A%.
T#torial $' &
Controlling )*#+s o,er An!roi! +perating S(stem.
T#torial $( &
Creating a &oot script for har!ware initiali-ation.
T#torial $) &
Compiling Te"as #nstr$ments An!roi! 'ernel from so$rce.
T#torial $* &
#.C mo!$les. /"ample with L012 temperat$re sensor.
T#torial $+ &
UART1 an! UART. mo!$les.
T#torial $, &
S*# mo!$le.
T#torial $- &
Compiling a c$stom An!roi! !ri,er as a char !e,ice.
T#torial %$ &
Accessing to har!ware from c$stom An!roi! !ri,er.
T#torial % % &
Compiling 'ernel 3.4 with !e,ice tree s$pport for An!roi!.
T#torial %2 &
Using *50 mo!$les.
T#torial %' &
Using AC mo!$le.
E.a/0le& 1tt0&22o#rceforge3net20ro4ect2androidonbeaglebonebt#torial
Rev3 "orrection
6 +riginal !oc$ment
1 S*# T$torial: cloc' pin m$st &e inp$t
. T(pographical errors7 8ernel 3.47 *507AC
Licene
T1i work i licened #nder t1e "reative "o//on Attrib#tion-S1areAlike (3$ 5nternational
Licene3 To view a co06 of t1i licene7 viit
1tt0&22creativeco//on3org2licene2b6-a2(3$2deed3en8US3
9Android on Beaglebone Black: b6 Erneto !igliotti3
"ontact & ernetogigliotti;g/ail3co/
UTN FRA LSL http://www.lslfra.com.ar .
Android on Beaglebone Black (Rev 2)
T#torial $%& Creating S car! An!roi! Te"as #nstr$ments #mage for %eagle&one %lac'.
Re9$irements:
This t$torial is &ase! in a *C with U&$nt$ 13 :;&it +perating S(stem.
0icro S car! class 1< preferentiall(.
First of all7 we ha,e to !ownloa! the T# An!roi! #mage from T#=s we& page:
http://!ownloa!s.ti.com/sitara>an!roi!/es!/T#>An!roi!>e,8it/T#>An!roi!>?%>;>.>.>e,8it>;>1>
1/in!e">FS.html
#n the @*re6%$ilt #magesA section7 we !ownloa! @%eagle&one %lac'A
5hen the file is finishe! to !ownloa!7 we ha,e to $ncompress it. #nsi!e the fol!er we will fin!
the script @m'mmc6an!roi!.shA with this script we will &e a&le to create an An!roi! #mage for
o$r %eagle&one %lac'.
Steps
1B *l$g (o$r micro S car! in the SCar! rea!er.
#f (o$ ha,e a note&oo' with an integrate! rea!er7 the car! will appear in /!e,/mmc&l'. #f (o$
ha,e an US% rea!er7 the car! will appear in /!e,/s!c or /!e,/s!C it will !epen! how man(
partitions (o$ ha,e in (o$r comp$ter.
#n this t$torial we will $se mmc&l' !e,ice
.B As root7 grant e"ec$tion permissions for the script:
chmod +x mkmmc-android.sh
3B /"ec$te the script an! image will &e copie! into the S car!:
./mkmmc-android.sh /dev/mmcblk
<ARN5N!& #f (o$ p$t a wrong path where it sa(s @mmc&l'A(o$ can !estro( (o$r partition.
+nce the script finishe!7 (o$ can p$t the S car! into the %eagle&one %lac' an! power it7
An!roi! will &oot.
UTN FRA LSL http://www.lslfra.com.ar 3
Android on Beaglebone Black (Rev 2)
T#torial $2& Accessing the An!roi! Console &( A%
Re9$irements:
An!roi! S8 installe! in (o$r comp$ter
5hen we pl$g the %eagle=s mini US% connector to o$r comp$ter7 we can connect to An!roi! &(
A%.
The first step is to config$re U&$nt$ for recogni-e the %eagle&one %lac' as a ,ali! US% !e,ice.
Steps
1B As root7 create the file @/etc/$!e,/r$les.!/216an!roi!.r$les A
nano /etc/udev/rules.d/51-android.rules
.B *$t the following te"t insi!e the file:
SU%SDST/0EEF$s&F7 SDSFSGi!Hen!orIEEF14!1F7 0+/EF<:::F
SU%SDST/0EEF$s&F7 SDSFSGi!Hen!orIEEF<;21F7 0+/EF<:::F
3B As root7 change the file=s permissions:
chmod a+r /etc/udev/rules.d/51-android.rules
;B As root7 go to the a!& !irector( insi!e An!roi!6S8 an! 'ill a!& an! restart it listing the
!e,ices !etecte! J%eagle&one %lac' m$st &e pl$gge!B:
./adb kill-server
./adb devices
The o$tp$t will &e something li'e:
List of devices attached
0123456789ABCDEF device
2B Then we are a&le to enter in the An!roi! console t(ping:
./adb shell
:B if we want to cop( a file from o$r comp$ter to the %eagle&one %lac' we can $se the @p$shA
a!&=s comman!:
./adb push ~/beagleboneblack/foo.txt /etc/
5e can too open /clipse an! $se the &oar! as another em$lator or phone7 !ownloa!ing
applications in it.
UTN FRA LSL http://www.lslfra.com.ar ;
Android on Beaglebone Black (Rev 2)
T#torial $'& Controlling )*#+s o,er An!roi! +perating S(stem
#n this t$torial we are going to control $ser=s le! in the &oar!.
*rocessor pins for Users Le!s:
USR< )*#+1>.1
USR1 )*#+1>..
USR. )*#+1>.3
USR3 )*#+1>.;
)*#+ control is not a,aila&le for !efa$lt7 we nee! to create a !irector( for each )*#+ we want to
control7 an! there will &e files in there that will allow $s to control the pins.
Steps
1B /nter to An!roi! Console &( a!&
./adb shell
.B )o to !irector( s(s/class/gpio:
cd /sys/class/gpio
3B There7 we will fin! the files an! !irectories:
export
gpiochip0
gpiochip32
gpiochip64
gpiochip96
unexport
/ach gpiochipCC correspon!s to a 3. &it )*#+ *ort. For pin n$m&er calc$lation7 we nee! to
calc$late the follow:
pin n$m&er E Jport n$m&er K 3.B L gpio n$m&er
for e"ample7 for $ser le! < J )*#+1>.1 B
pin n$m&er E J1 K 3.B L .1 E 23
3B Now we 'now the pin n$m&er we want to control7 we nee! to generate the !irector( for this
pin7 that is ma!e writing the pin n$m&er in the @e"portA file:
echo 53 > /sys/class/gpio/export
;B one that7 a new !irector( will appear:
export
gpio53 <- This directory is new
gpiochip0
gpiochip32
gpiochip64
UTN FRA LSL http://www.lslfra.com.ar 2
Android on Beaglebone Black (Rev 2)
gpiochip96
unexport
2B )o to this !irector(:
cd gpio53
:B There7 we will fin! some files:
active_low
direction
edge
power
subsystem
uevent
value
1B 5e will $se @!irectionA file to config$re the pin as inp$t or o$tp$t. 5e write @highA in it for
o$tp$t:
echo high > direction
4B Now we can control the pin state $sing @,al$eA file7 writing a @1A7 $ser le! < will t$rn on7 an!
writing a @<A7 $ser le! < will t$rn off.
echo 0 > value
echo 1 > value
Consi!erations:
5hen we re&oot the &oar! the @gpio23A !irector( will not &e a,aila&le an! we will nee! to
create it again. This pro&lem is sa,e! $sing a &oot script where this initiali-ation is ma!e.
UTN FRA LSL http://www.lslfra.com.ar :
Android on Beaglebone Black (Rev 2)
T#torial $(& Creating a &oot script for har!ware initiali-ation.
#f we want that )*#+s Jor other har!ware mo!$lesB are initiali-e! when An!roi! &oots7 we nee!
to create a script with the gpios config$ration steps. 5e will name this file @cri0tg0io31A
The content of this file will &e:
MConfig$re L/ US/R < 6 )*#+1>.1
echo 23 N /s(s/class/gpio/e"port
c! /s(s/class/gpio/gpio23
M irection : o$t
echo high N !irection
echo < N ,al$e
chmo! 111 ,al$e
chmo! 111 !irection
Now we nee! to e"ec$te this script at the &eginning of the An!roi! &ooting. For that7 we nee!
to e!it the @init3rcA file that is place! in An!roi!=s file s(stem root.
Since we can not e!it the file insi!e An!roi! +perating S(stem Jwe !o not ha,e a te"t e!itor in
An!roi! consoleB we are going to e!it the file pl$gging the S car! in o$r comp$ter an! e!iting
the file from there.
5hen we !o that7 fo$r partitions will appear:
&oot
rootfs
$sr!ata
!ata
#n rootfs partition7 we will fin! the init.rc file. Now we can e!it it with ,im or nano.
Steps
1B +pen init.rc file with nano
.B Search for the lines:
ser,ice !e&$gger! /s(stem/&in/!e&$gger!
class main
%ellow these lines7 we are going to write o$r script initiali-ation:
ser,ice scriptgpios /s(stem/&in/sh /s(stem/etc/scriptgpios.sh
class main
oneshot
3B Cop( @scriptgpios.shA from (o$r comp$ter to @/s(stem/etcA in the rootfs partition of the S
car!. This file m$st ha,e e"ec$tion permissions.
Then we $nmo$nt all partitions an! p$t S car! again in the &oar!7 when An!roi! &oots7 this
time )*#+s will &e config$re!.
UTN FRA LSL http://www.lslfra.com.ar 1
Android on Beaglebone Black (Rev 2)
T#torial $)& Compiling Te"as #nstr$ments An!roi! 'ernel from so$rce.
#f we want to compile An!roi! 'ernel J $sef$l if we want to create o$r c$stom !ri,ers B we nee!
to !ownloa! T#6e,8it from Te"as we& page:
http://!ownloa!s.ti.com/sitara>an!roi!/es!/T#>An!roi!>e,8it/T#>An!roi!>?%>;>.>.>e,8it>;>1>
1/in!e">FS.html
#n the @T# An!roi! So$rcesA section7 we !ownloa! @T# An!roi! ?% ;.... e,8itH;.1.1 A0332"
So$rcesA
Steps
1B The file !ownloa!e! is a @.&inA we nee! to change e"ec$tion permissions an! e"ec$te it:
chmod +x TI_Android_JB_4.2.2_DevKit_4.1.1.bin
./TI_Android_JB_4.2.2_DevKit_4.1.1.bin
5e s$ppose this file is in @O/&eagle&one&lac'A !irector(7 if (o$ are $sing another path7 pa(
attention an! change it in all parts where it appears.
.B +nce the &inar( file !ecompresse!7 the !irector( @T#>An!roi!>?%>;....>e,8it>;.1.1A will
appear. Now we can compile the 8ernel:
cd ~/beagleboneblack/TI_Android_JB_4.2.2_DevKit_4.1.1/kernel
PATH=$HOME/beagleboneblack/TI_Android_JB_4.2.2_DevKit_4.1.1/prebuilts/gcc/linux-
x86/arm/arm-eabi-4.6/bin:$PATH
make ARCH=arm CROSS_COMPILE=arm-eabi- distclean
make ARCH=arm CROSS_COMPILE=arm-eabi- am335x_evm_android_defconfig
make ARCH=arm CROSS_COMPILE=arm-eabi- uImage
This process can ta'e some of min$tes !epen!ing of (o$r comp$ter.
3B 8ernel image will &e create! in T#>An!roi!>?%>;....>e,8it>;.1.1/'ernel/arch/arm/&oot. File=s
name is @$#mageA. *$t the SCar! in (o$r car! rea!er an! cop( this file into @&ootA partition.
UTN FRA LSL http://www.lslfra.com.ar 4
Android on Beaglebone Black (Rev 2)
T#torial $*& #.C mo!$les. /"ample with L012 temperat$re sensor.
Re9$irements:
A &oar! with an L012 #.C temperat$re sensor.
An!roi! N8 installe! in (o$r comp$ter.
5e are going to config$re #.C port an! we are going to $se it for rea!ing an L012 temperat$re
sensor.
#f we na,igate An!roi! !irector(7 in /!e, we are going to fin! @i.c63A !e,ice. This !e,ice
correspon!s with the pins 1P an! .< from *P connector on the &oar!.
=- 0in > 52" f#nction
1P SCL
.< SA
Steps
1B 5e will connect L012 chip to this port. *ower s$ppl( can &e ta'en from the &oar! from pins
1 an! ;.
.B 5e are going to write a C program for $se #.C !e,ice as a character !e,ice for rea!ing L012.
For that7 we nee! to create a proQect !irector(: @lm12testA. Then we nee! to create the @QniA
!irector( insi!e. #nsi!e Qni fol!er7 we are going to create a @0ain.cA file.
mkdir lm75test
cd lm75test
mkdir jni
cd jni
nano Main.c
3B 5rite the C co!e $sing open7 rea!7 write7 an! ioctl f$nctions:
Mincl$!e Rst!io.hN
Mincl$!e Rst!li&.hN
Mincl$!e Ri.c6!e,.hN
Mincl$!e Rs(s/ioctl.hN
Mincl$!e Rs(s/t(pes.hN
Mincl$!e Rs(s/stat.hN
Mincl$!e Rfcntl.hN
int fileS
char Kfilename E F/!e,/i.c63FS
if JJfile E openJfilename7 +>R5RBB R <B
e"itJ1BS
//1 < < 1 A. A1 A< R/5
int a!!r E <";4S // e,ice a!!ress is <";4
if JioctlJfile7 #.C>SLAH/7 a!!rB R <B
e"itJ1BS
$nsigne! char &$fT1<U E G<IS
ifJwriteJfile7 &$f71B VE 1B
e"itJ1BS
int r E rea!Jfile7&$f7.BS
$nsigne! char tempW E &$fT<US
$nsigne! char tempL E &$fT1US
UTN FRA LSL http://www.lslfra.com.ar P
Android on Beaglebone Black (Rev 2)
$nsigne! short tempS
tempEtempWS
tempEtempRR1S
tempEtempX<"FFF/S
tempLEtempLNN1S
tempLEtempLX<"<<<1S
tempEtempYtempLS
float t E JJfloatBtempB/.S
printfJFTemperat$re:Zf[nF7tBS
;B To compile this co!e we will $se An!roi!6N87 for that reason7 we nee! to create two e"tra
files: @Application.m'A an! @An!roi!.m'A
Application.m':
A**>+*T#0 :E release
A**>*LATF+R0 :E an!roi!612
An!roi!.m':
L+CAL>*ATW :E \Jcall m(6!irB
incl$!e \JCL/AR>HARSB
L+CAL>0+UL/ :E lm12test
L+CAL>SRC>F#L/S :E 0ain.c
incl$!e \J%U#L>/C/CUTA%L/B

2B 5e can compile o$r co!e now7 insi!e Qni !irector( we e"ec$te N8 compiler Jthe path can
change if (o$ are $sing a newer ,ersionB
~/adt-bundle-linux-x86_64-20130219/android-ndk-r8d/ndk-build
:B #f compilation was +87 it will generate the e"ec$ta&le file in: lm12test/li&/armea&i/lm12test
1B Cop( the e"ec$ta&le into %eagle&one=s An!roi! etc !irector(:
./adb push lm75test/lib/armeabi/lm75test /etc/
4B /nter to An!roi! console7 change e"ec$tion permissions for o$r program an! e"ec$te it.
./adb shell
cd etc
chmod 777 lm75test
./lm75test
The program will print the act$al temperat$re rea! from L012.
Consi!erations
#f we want7 an( An!roi! application can access this !e,ice7 we nee! to a!! to the &oot script
we ma!e &efore7 the permissions for the !e,ice:
chmod 777 /dev/i2c-3
UTN FRA LSL http://www.lslfra.com.ar 1<
Android on Beaglebone Black (Rev 2)
T#torial $+& UART1 an! UART. mo!$les.
Re9$irements:
&$s(&o" m$st &e installe!
UART 1 an! . pino$t:
"onnector =-
*#N .; UART1>TC
*#N .: UART1>RC
*#N .1 UART.>TC
*#N .. UART.>RC
UART1 is manage! &( tt(+1 !e,ice J/!e,/tt(+1 B
UART. is manage! &( tt(+1 !e,ice J/!e,/tt(+.B
%( !efa$lt7 pins are in 0+/1 J)*#+B if we want to $se this pins as UARTs we nee! to change
pins m$" config$ration.
Steps
1B 5e can see UART1 pins m$" config$ration with the following comman!:
cat /sys/kernel/debug/omap_mux/uart1_rxd
.B %( !efa$lt7 pin m$" is )*#+7 we nee! to change it to UART1 RC
echo 20 > /sys/kernel/debug/omap_mux/uart1_rxd
Now when we chec' config$ration7 it will &e:
name: uart1_rxd.uart1_rxd (0x44e10980/0x980 = 0x0020), b NA, t NA
mode: OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLDOWN
signals: uart1_rxd | mmc1_sdwp | NA | i2c1_sda | NA | pr1_uart0_rxd_mux1 | NA |
gpio0_14
3B Same wa( we change t" pin config$ration.
echo 0 > /sys/kernel/debug/omap_mux/uart1_txd
;B Now we !o the same for UART.7 in this case pins are calle! spi<>!< an! spi<>scl' in An!roi!
file s(stem.
echo 1 > /sys/kernel/debug/omap_mux/spi0_d0
echo 21 > /sys/kernel/debug/omap_mux/spi0_sclk
2B To test UARTs we are going to $se @microcomA an application incl$!e! in &$s(&o" similar to
@minicomA.
/data/busybox/busybox microcom -s 9600 ttyO1
/data/busybox/busybox microcom -s 9600 ttyO2
N?TE& See steps 1; an! 12 from T$torial <P for &$s(&o" installation.
UTN FRA LSL http://www.lslfra.com.ar 11
Android on Beaglebone Black (Rev 2)
T#torial $,& S*# mo!$le.
Re9$irements:
T#6e,8it m$st &e installe!.
An!roi! 8ernel m$st &e compile!.
S*#< pino$t:
"onnector =-
*#N 11 S*#<>CS<
*#N 14 S*#<>1
*#N .1 S*#<><
*#N .. S*#<>SCL8
S*# is not ena&le! &( !efa$lt7 we nee! to e!it @&oar!6am332"e,m.cA file7 enter in 'ernel =s
men$config options an! ena&le S*#/H an! re6compile An!roi! 'ernel with this feat$res7 other
wa( S*# !e,ice will not appear in /!e, !irector(.

%( !efa$lt7 pins are in 0+/1 J)*#+B if we want to $se these pins as S*# pins7 we nee! to
change pins m$" config$ration.
Steps
1B 5e are going to ena&le S*#< &eca$se S*#1 is $se! &( W0# mo!$le an! it cannot &e $se!.
/!it @&oar!6am332"e,m.cA file in 'ernel=s !irector( @arch/arm/mach6omap./A
nano arch/arm/mach-omap2/board-am335xevm.c
.B Change @am332">spi<>sla,e>infoA str$ct for the follow one:
static str$ct spi>&oar!>info am332">spi<>sla,e>infoTU E G
G
.mo!alias E Fspi!e,F7
.ma">spee!>h- E ;4<<<<<<7 //;4 0&ps
.&$s>n$m E 17
.chip>select E <7
.mo!e E S*#>0+/>17
I7
IS
3B Change @spi<>initA f$nction for the follow one:
static ,oi! spi<>initJint e,m>i!7 int profileB
G
set$p>pin>m$"Jspi<>pin>m$"BS
spi>register>&oar!>infoJam332">spi<>sla,e>info7
ARRAD>S#]/Jam332">spi<>sla,e>infoBBS
ret$rnS
I
;B A!! in the @&eagle&one>&lac'>!e,>cfgTUA arra(7 this line :
Gspi<>init7 /H>+N>%AS/%+AR7 *R+F#L/>N+N/I7
UTN FRA LSL http://www.lslfra.com.ar 1.
Android on Beaglebone Black (Rev 2)
2B %efore compiling 'ernel7 enter in men$config options an! ena&le S*# settings:
cd ~/beagleboneblack/TI_Android_JB_4.2.2_DevKit_4.1.1/kernel
PATH=$HOME/beagleboneblack/TI_Android_JB_4.2.2_DevKit_4.1.1/prebuilts/gcc/linux-
x86/arm/arm-eabi-4.6/bin:$PATH
make ARCH=arm CROSS_COMPILE=arm-eabi- distclean
make ARCH=arm CROSS_COMPILE=arm-eabi- am335x_evm_android_defconfig
make ARCH=arm CROSS_COMPILE=arm-eabi- menuconfig
0a'e s$re @0cS*#A an! @User mo!e S*#A are ena&le!.
e,ice ri,ers 6N
S*# S$pport 6N
TKU 0cS*# !ri,er for +0A*
TKU User mo!e S*# !e,ice !ri,er s$pport
:B Compile 'ernel
make ARCH=arm CROSS_COMPILE=arm-eabi- uImage
1B Cop( 'ernel=s image into S car! an! &oot %eagle&one %lac'. Now !e,ice @spi!e,1.<A
sho$l! appear in /!e, !irector(.
root@android:/dev # ls spi* -la
crw------- root root 153, 0 2000-01-01 00:00 spidev1.0
4B <ARN5N!: #n t$torial <17 we change pin m$" for UART.7 this pins are the same for S*#< cl'
an! !<. 0a'e s$re pins spi<>scl' an! spi<>!< are in 0+/< chec'ing m$" files:
cat /sys/kernel/debug/omap_mux/spi0_sclk
name: spi0_sclk.spi0_sclk (0x44e10950/0x950 = 0x0020), b NA, t NA
mode: OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLDOWN
signals: spi0_sclk | uart2_rxd | i2c2_sda | NA | NA | NA | NA | gpio0_2

cat /sys/kernel/debug/omap_mux/spi0_d0
name: spi0_d0.spi0_d0 (0x44e10954/0x954 = 0x0020), b NA, t NA
mode: OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLDOWN
signals: spi0_d0 | uart2_txd | i2c2_scl | NA | NA | NA | NA | gpio0_3
#f pins are not as the o$tp$t a&o,e7 we nee! to change them writing a @.<A in these files7 also
we nee! to !isa&le p$ll6$p in spi<>!<. N+T/: scl' m$st &e an inp$t &eca$se a 'ernel=s &$g.
echo 20 >> /sys/kernel/debug/omap_mux/spi0_sclk
echo 20 >> /sys/kernel/debug/omap_mux/spi0_d0
PB 5e can chec' S*# mo!$le writing a simple C program an! connecting spi<>!< an! spi<>!1
ph(sicall( with a wire. The program will transmit an! recei,e a few &(tes. Create a n!' proQect:
mkdir spiTestProject
cd spiTestProject
mkdir jni
cd jni
nano spitest.c
UTN FRA LSL http://www.lslfra.com.ar 13
Android on Beaglebone Black (Rev 2)
1<B 5rite hea!er files an! glo&al ,aria&les for spi config$ration.
Mincl$!e Rst!io.hN
Mincl$!e Rst!li&.hN
Mincl$!e Rfcntl.hN
Mincl$!e Rs(s/ioctl.hN
Mincl$!e Rspi!e,.hN
static const char K!e,ice E F/!e,/spi!e,1.<FS
static $int4>t mo!e E S*#>0+/>1S
static $int4>t &its E 4S
static $int3.>t spee! E 1<<<<<S // 1<<8h-
Then we are going to !efine an error f$nction:
static ,oi! pa&ortJconst char KsB
G
perrorJsBS
a&ortJBS
I
Now we write a transfer f$nction for spi test7 this f$nction will recei,e spi!e,=s file !escriptor:
static ,oi! transferJint f!B
G
int retS
$int4>t t"TU E G<"227<"C37<"3C7<"<17<"4<7<"FF7<"<<IS
$int4>t r"Tsi-eofJt"BU E G<IS
str$ct spi>ioc>transfer tr E G
.t">&$f E J$nsigne! longBt"7
.r">&$f E J$nsigne! longBr"7
.len E si-eofJt"B7
.!ela(>$secs E 2<7
.spee!>h- E spee!7
.&its>per>wor! E &its7
.cs>changeE17
IS
ret E ioctlJf!7 S*#>#+C>0/SSA)/J1B7 XtrBS
if Jret R 1B
pa&ortJFcan=t sen! spi messageFBS
printfJFr":FBS
for Jret E <S ret R si-eofJt"BS retLLB
printfJFZ..C F7 r"TretUBS
printfJF[r[nFBS
I

At the en!7 we write the main f$nction7 where we open spi!e, !e,ice an! we config$re it $sing
ioctl f$nction &efore calling @transferA f$nction:
int mainJint argc7 char Karg,TUB
G
int ret E <S
int f!7 co$nterS
f! E openJ!e,ice7 +>R5RBS
if Jf! R <B
pa&ortJFcan=t open !e,iceFBS
// set mo!e
ret E ioctlJf!7 S*#>#+C>5R>0+/7 Xmo!eBS
if Jret EE 61B
pa&ortJFcan=t set spi mo!eFBS
ret E ioctlJf!7 S*#>#+C>R>0+/7 Xmo!eBS
if Jret EE 61B
pa&ortJFcan=t get spi mo!eFBS
UTN FRA LSL http://www.lslfra.com.ar 1;
Android on Beaglebone Black (Rev 2)
// set &its per wor!
ret E ioctlJf!7 S*#>#+C>5R>%#TS>*/R>5+R7 X&itsBS
if Jret EE 61B
pa&ortJFcan=t set &its per wor!FBS
ret E ioctlJf!7 S*#>#+C>R>%#TS>*/R>5+R7 X&itsBS
if Jret EE 61B
pa&ortJFcan=t get &its per wor!FBS

// set ma" spee! h-
ret E ioctlJf!7 S*#>#+C>5R>0AC>S*//>W]7 Xspee!BS
if Jret EE 61B
pa&ortJFcan=t set ma" spee! h-FBS
ret E ioctlJf!7 S*#>#+C>R>0AC>S*//>W]7 Xspee!BS
if Jret EE 61B
pa&ortJFcan=t get ma" spee! h-FBS
// Start Test
printfJFspi mo!e: Z![nF7 mo!eBS
printfJF&its per wor!: Z![nF7 &itsBS
printfJFma" spee!: Z! W- JZ! 8W-B[nF7 spee!7 spee!/1<<<BS
transferJf!BS

closeJf!BS
ret$rn retS
I
11B 5e also nee! to create An!roi!.m' an! Application.m':
An!roi!.m'
L+CAL>*ATW :E \Jcall m(6!irB
incl$!e \JCL/AR>HARSB
L+CAL>LL#%S :E 6llog
L+CAL>0+UL/ :E testSpi
L+CAL>SRC>F#L/S :E spitest.c
incl$!e \J%U#L>/C/CUTA%L/B

Application.m'
A**>+*T#0 :E release
A**>*LATF+R0 :E an!roi!612
1.B Now we can compile this program $sing an!roi!6n!'7 in Qni !irector(7 e"ec$te:
~/adt-bundle-linux-x86_64-20130219/android-ndk-r8d/ndk-build
:B #f compilation was +87 it will generate the e"ec$ta&le file in: spiTest*roQect/li&s/armea&i/
1B Cop( the e"ec$ta&le into %eagle&one=s An!roi! etc !irector(:
./adb push spiTestProject/libs/armeabi/testSpi /etc/
4B /nter to An!roi! console7 change e"ec$tion permissions for o$r program an! e"ec$te it.
./adb shell
cd etc
chmod 777 testSpi
./testSpi
UTN FRA LSL http://www.lslfra.com.ar 12
Android on Beaglebone Black (Rev 2)
T#torial $-& Compiling a c$stom An!roi! !ri,er as a char !e,ice.
Re9$irements:
T#6e,8it m$st &e installe!
An!roi! 8ernel m$st &e compile!
Steps
1B Create a fol!er for the 8ernel 0o!$le proQect
mkdir moduleProject
cd moduleProject
.B Create a C file name! @c$stom0o!$le.cA:
nano customModule.c
3B 5e nee! to write the 'ernel mo!$le7 first of all7 we incl$!e some hea!ers files an! !efines:
Mincl$!e Rlin$"/mo!$le.hN
Mincl$!e Rlin$"/'ernel.hN
Mincl$!e Rlin$"/fs.hN
Mincl$!e Rlin$"/'!e,>t.hN
Mincl$!e Rasm/$access.hN
0+UL/>L#C/NS/JF)*LFBS
0+UL/>AUTW+RJF/rnesto )igliotti Rernestogigliotti^gmail.comNFBS
0+UL/>/SCR#*T#+NJFAn!roi! C$stom ri,erFBS
;B Then7 we !efine some constants an! the file operations str$ct$re7 this str$ct$re will contain
the f$nctions that will &e calle! &( the program $ser when it calls rea!7write7open7ioctl an!
close f$nctions.
M!efine 0+UL/>NA0/ Fc$stom0o!$leF
$nsigne! int mo!$le>maQorS
str$ct file>operations fopsS
2B Now we can write the @init>mo!$leA f$nction7 this f$nction will &e calle! when the mo!$le is
installe!.
int init>mo!$leJ,oi!B G
int res$ltS
// Asign file operation f$nctions
fops.open E open>mo!$leS
fops.release E release>mo!$leS
//fops.rea! E rea!>mo!$leS
//fops.write E write>mo!$leS
//fops.$nloc'e!>ioctl E ioctl>mo!$leS
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// inamic reser,ation for maQor n$m&er
res$ltEregister>chr!e,J<7 0+UL/>NA0/7 XfopsBS
if Jres$lt R <B G
print'J8/RN>5ARN#N) Fan!roi!C$stom0o!$leN Jinit>mo!$leB error o&taining maQor n$m&er[nFBS
ret$rn res$ltS
I
mo!$le>maQor E res$ltS
print'J 8/RN>#NF+ Fan!roi!C$stom0o!$leN Jint>mo!$leB loa!e! +8[nFBS
ret$rn <S
I
UTN FRA LSL http://www.lslfra.com.ar 1:
Android on Beaglebone Black (Rev 2)
:B 5rite @clean$p>mo!$leA f$nction. This f$nction will &e calle! when the mo!$le is $nloa!e!:
,oi! clean$p>mo!$leJ,oi!B
G
$nregister>chr!e,Jmo!$le>maQor7 0+UL/>NA0/BS
print'J 8/RN>#NF+ Fan!roi!C$stom0o!$leN Jclean$p>mo!$leB $nloa!e! +8[nFBS
I
1B 5rite the @open>mo!$leA f$nction. This f$nction will &e calle! when $ser=s program calls
@openA f$nction $sing o$r !e,ice.
int open>mo!$leJstr$ct ino!e Kpino!e7 str$ct file KpfileB
G
int minorE 0#N+RJpino!e6Ni>r!e,BS
print'J8/RN>#NF+ Fan!roi!C$stom0o!$leN JopenB minorEZ! +8[nF7minorBS
ret$rn <S
I
4B 5rite @release>mo!$leA f$nction. This f$nction will &e calle! when $ser=s program calls
@closeA f$nction $sing o$r !e,ice.
int release>mo!$leJstr$ct ino!e Kpino!e7 str$ct file KpfileB
G
int minorE 0#N+RJpino!e6Ni>r!e,BS
print'J8/RN>#NF+ Fan!roi!C$stom0o!$leN JreleaseB minorEZ! +8[nF7minorBS
ret$rn <S
I
PB %efore we write the rea!7write an! ioctl f$nctions7 we are going to compile this 'ernel
mo!$le Q$st with the f$nctions mentione! a&o,e. For that7 we nee! to create a 0a'efile. Create
a file name! @0a'efileA with this content:
0a'efile:
o&Q6m LEc$stom0o!$le.o
8/RN/L#R _E O/&eagle&one&lac'/T#>An!roi!>?%>;....>e,8it>;.1.1/'ernel
*5 :E \Jshell pw!B
CR+SS>C+0*#L/EO/&eagle&one&lac'/T#>An!roi!>?%>;....>e,8it>;.1.1/pre&$ilts/gcc/lin$"6"4:/arm/arm6ea&i6;.:/&in/
arm6ea&i6
ARCWEarm
!efa$lt:
\J0A8/B 6C \J8/RN/L#RB 0E\J*5B ARCWEarm CR+SS>C+0*#L/E\JCR+SS>C+0*#L/B mo!$les
clean:
\J0A8/B 6C \J8/RN/L#RB 0E\J*5B clean
#n this 0a'efile we pass the 'ernel=s path insi!e T#6e,8it. 8ernel m$st &e compile!. Also we
pass the compiler=s path. Change these paths if (o$ ha,e T#6e,8it in another place.
1<B 5rite f$nction protot(pes at the &eginning of the file:
int open>mo!$leJstr$ct ino!e Kpino!e7 str$ct file KpfileBS
int release>mo!$leJstr$ct ino!e Kpino!e7 str$ct file KpfileBS
11B Now we can compile the mo!$le e"ec$ting @ma'eA comman!:
make
File @c$stom0o!$le.'oA will &e generate!.
UTN FRA LSL http://www.lslfra.com.ar 11
Android on Beaglebone Black (Rev 2)
1.B Now we can install o$r mo!$le into the An!roi! +perating S(stem. Cop( the mo!$le &( a!&
an! install it:
./adb push /home/USER/beagleboneblack/moduleProject/customModule.ko /etc
./adb shell
cd /etc
insmod customModule.ko
13B The mo!$le will &e installe! an! we can see 'ernel=s log messages in 'msg file:
cat /proc/kmsg
+$tp$t will &e:
<6>[ 700.884185] androidCustomModule> (int_module) loaded OK
5e can $nloa! the mo!$le with @rmmo!A comman!
1;B Now o$r mo!$le is wor'ing7 we nee! to create one or more !e,ices in /!e, !irector(. 5e
nee! to $se @m'no!A comman! for that7 &$t this comman! is not part of T# An!roi!
!istri&$tion. 5e nee! to install &$s(&o". This application will allow $s to $se a &ig set of
stan!ar! Lin$"=s comman!s on An!roi!7 incl$!e! @m'no!A
ownlo! &$s(&o" from:
https://gforge.ti.com/gf/proQect/omapan!roi!/wi'i/_
pagenameE#nstallingL%$s(&o"Lcomman!LlineLtools
12B 5e nee! to cop( &$s(&o" e"ec$ta&le file into /!ata/&$s(&o" in An!roi! files(stem:
./adb shell
mkdir /data
cd /data
mkdir busybox
CTRL+D (quit from Android console)
./adb push /home/USER/beagleboneblack/busybox /data/busybox/
1:B Now we nee! to create a script for mo!$le=s installation J $sing insmo! an! m'no!
comman!s B this script will install the mo!$le an! it will create the !e,ices in /!e, !irector(:
install0o!$le.sh
MV/s(stem/&in/sh
mo!$leEc$stom0o!$le
!e,iceE/!e,/an!roi!6c$stom6!e,6
permE:::
rmmo! \Gmo!$leI
insmo! \Gmo!$leI.'o
maQorE`cat /proc/!e,ices Y grep \Gmo!$leI Y /!ata/&$s(&o"/&$s(&o" c$t 6!= = 6f1`
rm 6f \G!e,iceIK
/!ata/&$s(&o"/&$s(&o" m'no! \G!e,iceI< c \GmaQorI <
/!ata/&$s(&o"/&$s(&o" m'no! \G!e,iceI1 c \GmaQorI 1
chmo! \GpermI \G!e,iceI_
#n this script we !elete the mo!$le7 then we install it an! we get the maQor n$m&er generate!.
Then the script !eletes c$rrent !e,ices7 an! creates the new ones with the maQor n$m&er
o&taine! &efore.
UTN FRA LSL http://www.lslfra.com.ar 14
Android on Beaglebone Black (Rev 2)
11B Cop( c$stom0o!$le.'o an! install0o!$le.sh into /etc on An!roi! &( a!&:
./adb push /home/USER/beagleboneblack/moduleProject/customModule.ko /etc
./adb push /home/USER/beagleboneblack/moduleProject/installModule.sh /etc
14B /nter to An!roi! console an! e"ec$te the script:
./adb shell
cd /etc
chmod 777 installModule.sh
./installModule
#f installation is +87 we will &e a&le to see two new !e,ices in /!e,
/!e,/an!roi!6c$stom6!e,6<
/!e,/an!roi!6c$stom6!e,61
1PB Now the mo!$le is wor'ing7 we are going to complete the mo!$le C program with
write7rea! an! ioctl f$nctions. +pen again c$stom0o!$le.c an! a!! rea! f$nction:
First the protot(pe at the &egining:
static ssi-e>t rea!>mo!$leJstr$ct file Kfilp7char K&$ffer7si-e>t length7loff>t KoffsetBS
Then the f$nction:
static ssi-e>t rea!>mo!$leJstr$ct file Kfilp7
char K&$ffer7 /K The &$ffer to fill with !ata K/
si-e>t length7 /K The length of the &$ffer K/
loff>t KoffsetB /K +$r offset in the file K/
G
int &(tes>rea! E <S
int minorE 0#N+RJfilp6Nf>!entr(6N!>ino!e6Ni>r!e,BS
print'J8/RN>#NF+ Fan!roi!C$stom0o!$leN Jrea!B minor: Zi [nF7minorBS
char messageT:;UEFWello from mo!$le[<FS
char K msg>*tr E messageS
while JlengthN<BG
/K p$t>$ser copies !ata from
K the 'ernel !ata segment to the $ser !ata segment. K/
p$t>$serJKJmsg>*trB7 &$fferLLBS
length66S
&(tes>rea!LLS
ifJKJmsg>*trBEE<B
&rea'S
msg>*trLLS
I
ret$rn &(tes>rea!S
I

#n this mo!$le7 we are sim$lating a !e,ice which we can rea! the message @Wello from !e,iceA
@p$t>$serA f$nction is $se! to cop( !ata from 'ernel space to $ser space.
o not forget $ncomment fops assignment in init>mo!$le f$nction.
UTN FRA LSL http://www.lslfra.com.ar 1P
Android on Beaglebone Black (Rev 2)
.<B 5rite the @writeA f$nction an! its protot(pe:
*rotot(pe:
static ssi-e>t write>mo!$leJstr$ct file Kpfile7 const char K&$f7 si-e>t si-e>&$f7 loff>t Kf>posBS

F$nction:
static ssi-e>t write>mo!$leJstr$ct file Kpfile7 const char K&$f7 si-e>t si-e>&$f7 loff>t Kf>posB G
$nsigne! long not>copie!S
int menorE 0#N+RJpfile6Nf>!entr(6N!>ino!e6Ni>r!e,BS
print'J8/RN>#NF+ Fan!roi!C$stom0o!$leN JwriteB minor: Zi [nF7menorBS
char msg#nT:;US
not>copie!E>>cop(>from>$serJmsg#n7&$f7si-e>&$fBS // cop( from $ser space to 'ernel space
if Jnot>copie!N<B G
print'J8/RN>5ARN#N) Fan!roi!C$stom0o!$leN JwriteB error cop(ing !ata from $ser[nFBS
ret$rnJ6/FAULTBS
I
print'J8/RN>#NF+ Fan!roi!C$stom0o!$leN JwriteB msg:Zs [nF7msg#nBS
JKf>posBLEsi-e>&$fS
ret$rnJsi-e>&$fBS
I
#n this case7 this f$nction prints &( 'ernel log the message that it recei,es for writing.
.1B The last f$nction we are going to write is @ioctlA this f$nction will allow $s to config$re o$r
!e,ice thro$gh comman!s. 5e nee! to create o$r hea!er file calle! @c$stom0o!$le.hA
c$stom0o!$le.h:
M!efine CUST+0>0+UL/>#+C>N0A)#C =c=
M!efine CUST+0>0+UL/>#+C>C0>< >#+JCUST+0>0+UL/>#+C>N0A)#C7 1B
M!efine CUST+0>0+UL/>#+C>C0>1 >#+JCUST+0>0+UL/>#+C>N0A)#C7 .B
M!efine CUST+0>0+UL/>#+C>C0>. >#+JCUST+0>0+UL/>#+C>N0A)#C7 3B
M!efine CUST+0>0+UL/>#+C>C0>3 >#+JCUST+0>0+UL/>#+C>N0A)#C7 ;B
M!efine CUST+0>0+UL/>#+C>C0>; >#+5JCUST+0>0+UL/>#+C>N0A)#C7 27 1B
#n o$r hea!er file we !efine a @magic n$m&erA for the !ri,er an! comman!s for !e,ice
config$ration. User will call ioctl passing this comman!s to the !ri,er.
#octl f$nction:
long ioctl>mo!$leJstr$ct file Kpfile7 $nsigne! int cm!7 $nsigne! long argsB G
int minorE 0#N+RJpfile6Nf>!entr(6N!>ino!e6Ni>r!e,BS
print'J8/RN>#NF+ Fan!roi!C$stom0o!$leN JioctlB minor: Zi [nF7minorBS
if J>#+C>TD*/Jcm!B VE CUST+0>0+UL/>#+C>N0A)#CB
ret$rn 6/#NHALS
if J>#+C>NRJcm!B NE 2B // we ha,e onl( 2 comman!s
ret$rn 6/#NHALS
print'J8/RN>#NF+ Fan!roi!C$stom0o!$leN JioctlB C0: Z! [nF7 >#+C>NRJcm!BBS
switchJcm!B G
case CUST+0>0+UL/>#+C>C0><:
// ...
&rea'S
// +ther comman!s
//...
!efa$lt:
ret$rn 6/#NHALS
I
ret$rn <S
I
UTN FRA LSL http://www.lslfra.com.ar .<
Android on Beaglebone Black (Rev 2)
..B Compile the mo!$le again an! cop( it into %eagle%one=s An!roi!. Now we are going to
create a Test program for o$r !e,ice. Create a @!e,iceTest*roQectA !irector(7 a Qni fol!er insi!e7
cop( the mo!$le hea!er file insi!e Qni fol!er an! create test.c file.
mkdir deviceTestProject
cd deviceTestProject
mkdir jni
cd jni
cp ~/beagleboneblack/moduleProject/customModule.h .
nano test.c
.3B 5rite a test program $sing open7 rea!7 write an! ioctl f$nctions on o$r !e,ice:
test.c:
Mincl$!e Rs(s/ioctl.hN
Mincl$!e Rs(s/t(pes.hN
Mincl$!e Rs(s/stat.hN
Mincl$!e Rfcntl.hN
Mincl$!e R$nist!.hN
Mincl$!e Rst!io.hN
Mincl$!e Fc$stom0o!$le.hF
int mainJB G
int file<7 res$ltS
printfJFri,er Test[nFBS
file<EopenJF/!e,/an!roi!6c$stom6!e,6<F7+>R5RBS
if Jfile<EE61B ret$rnJ61BS
char msgT:;US
int r E rea!Jfile<7msg7:;BS
printfJFRea! msg: Zs [nF7msgBS
char &$fferT:;UEF0essage from $ser[<FS
writeJfile<7&$ffer7:;BS
res$ltEioctlJfile<7 CUST+0>0+UL/>#+C>C0><7NULLBS
if Jres$ltEE<B
printfJFioctl +8[nFBS
else
printfJFioctl /RR+R[nFBS
closeJfile<BS
ret$rn <S
.;B Compile this test program $sing N8. o not forget create Application.m' an! An!roi!.m'
files first:
Application.m':
A**>+*T#0 :E release
A**>*LATF+R0 :E an!roi!612
An!roi!.m':
L+CAL>*ATW :E \Jcall m(6!irB
incl$!e \JCL/AR>HARSB
L+CAL>0+UL/ :E !e,iceTest
L+CAL>SRC>F#L/S :E test.c
incl$!e \J%U#L>/C/CUTA%L/B
)o to Qni fol!er an! compile the program $sing N8:
~/adt-bundle-linux-x86_64-20130219/android-ndk-r8d/ndk-build
UTN FRA LSL http://www.lslfra.com.ar .1
Android on Beaglebone Black (Rev 2)
.2B Cop( e"ec$ta&le file in /li&s/armea&i into %eagle%oar!=s An!roi! &( a!&:
./adb push
/home/USER/beagleboneblack/deviceTestProject/libs/armeabi/deviceTest /etc/
.:B )o to An!roi! console an! e"ec$te !e,iceTest program:
./ a!& shell
c! etc
chmo! 111 !e,iceTest
./!e,iceTest
*rogram=s +$tp$t will &e:
Driver Test
Read msg: Hello from module
ioctl OK
8ernel log=s +$tp$t will &e:
<6>[ 5295.389801] androidCustomModule> (int_module) loaded OK
<6>[ 5309.067596] androidCustomModule> (open) minor=0 OK
<6>[ 5309.074859] androidCustomModule> (read) minor: 0
<6>[ 5309.080596] androidCustomModule> (write) minor: 0
<6>[ 5309.085845] androidCustomModule> (write) msg:Message from user
<6>[ 5309.092895] androidCustomModule> (ioctl) minor: 0
<6>[ 5309.098052] androidCustomModule> (ioctl) CMD: 1
<6>[ 5309.103607] androidCustomModule> (release) minor=0 OK
Consi!erations
#f we nee! o$t c$stom !e,ices alwa(s a,aila&le7 we nee! to call @install0o!$le.shA script when
An!roi! is &ooting7 this is possi&le a!!ing it to the &oot script we alrea!( ma!e.

UTN FRA LSL http://www.lslfra.com.ar ..
Android on Beaglebone Black (Rev 2)
T#torial %$& Accessing to har!ware from c$stom An!roi! !ri,er.
Re9$irements:
C$stom !ri,er m$st alrea!( wor'.
Until now7 o$r !ri,er Q$st can manage a local ram memor( portion witho$t interaction with
har!ware7 if we want to rea!/write processor=s registers for controlling har!ware mo!$les we
can not !o this !irectl(7 we nee! to $se f$nctions to con,ert ph(sical a!!resses to ,irt$al
a!!resses.
Steps
1B Use @re9$est>mem>regionA f$nction to reser,e ph(sical a!!resses for accessing. This
reser,ation sho$l! &e !one in mo!$le=s init f$nction.
str$ct reso$rce Kres E re9$est>mem>regionJ*WDS>AR7;7Farea>nameFBS
ifJresVENULLB
G
// Reser,ation +8
I
#n this e"ample7 we are reser,ing ; &(tes starting from a!!ress @*WDS>ARA an! we are
assigning to this area the name @area>nameA
5hen memor( area is reser,e!7 we can chec' that $sing:
cat /proc/iomem
.B Same wa(7 we sho$l! release this memor( area in mo!$le=s close f$nction:
release>mem>regionJ*WDS>AR7;BS
3B Now we can o&tain a pointer for rea!/write $sing @ioremap>nocacheA f$nction
$nsigne! int K a!!r E J$nsigne! int KBioremap>nocacheJ*WDS>AR7;BS
;B Using iorea!3. an! iowrite3. we can rea!/write this memor( a!!ress:
$nsigne! int ,al$e E iorea!3.Ja!!rBS
,al$eE,al$e Y J1RR.1BS
iowrite3.J,al$e7a!!rBS
2B Release the pointer:
io$nmapJa!!rBS
This wa( we can rea!/write ph(sical a!!resses in o$r !ri,er an! $se processor=s har!ware.
This hea!ers files m$st &e incl$!e!:
Mincl$!e Rlin$"/ioport.hN
Mincl$!e Rasm/io.hN
UTN FRA LSL http://www.lslfra.com.ar .3
Android on Beaglebone Black (Rev 2)
T#torial %%& Compiling 'ernel 3.4 with !e,ice tree s$pport for An!roi!.
8ernel 3.. !oes not ha,e e,ice Tree s$pport7 we cannot $se *50 mo!$le or AC if we !o not
initiali-e these mo!$les $sing e,ice Tree7 &eca$se of this7 we are going to left T# 'ernel an!
files(stem asi!e7 an! we are going to $se row&oat proQect to compile An!roi! an! Ro&ert
Nelson=s 'ernel 3.4.
Steps
1B Fetch row&oat=s An!roi! proQect for %%%:
mkdir RobertNelsonKernel
cd RobertNelsonKernel
repo init -u git://gitorious.org/rowboat/manifest.git -m rowboat-jb-am335x.xml
repo sync
.B Fetch an! compile Ro&ert Nelson 8ernel
git clone https://github.com/RobertCNelson/bb-kernel.git
cd linux-dev
git checkout origin/am33x-v3.8 -b tmp
./build_kernel.sh
8ernel compilation will start an! we will ha,e to a!! some feat$res in 'ernel=s men$config:
e,ice ri,ers 6N
TKU Staging !ri,ers 6N
An!roi! 6N
RKN An!roi! log !ri,er
3B Now we are going to fetch An!roi!=s &ootloa!er @U6%ootA. #n Ro&ertNelson8ernel !irector(:
git clone git://git.denx.de/u-boot.git
cd u-boot/
git checkout v2013.04 -b tmp
wget
https://raw.github.com/eewiki/u-boot-patches/master/v2013.04/0001-am335x_evm-uEn
v.txt-bootz-n-fixes.patch
patch -p1 < 0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
;B 5e compile U6&oot with the following comman!s:
make ARCH=arm
CROSS_COMPILE=~/RobertNelsonKernel/linux-dev/dl/gcc-linaro-arm-linux-gnueabihf-4
.7-2013.04-20130415_linux/bin/arm-linux-gnueabihf- distclean
make ARCH=arm
CROSS_COMPILE=~/RobertNelsonKernel/linux-dev/dl/gcc-linaro-arm-linux-gnueabihf-4
.7-2013.04-20130415_linux/bin/arm-linux-gnueabihf- am335x_evm_config
make ARCH=arm
CROSS_COMPILE=~/RobertNelsonKernel/linux-dev/dl/gcc-linaro-arm-linux-gnueabihf-4
.7-2013.04-20130415_linux/bin/arm-linux-gnueabihf-
UTN FRA LSL http://www.lslfra.com.ar .;
Android on Beaglebone Black (Rev 2)
2B Now we nee! to compile An!roi! Files(stem $sing o$r new 8ernel 3.47 for that reason we
nee! to change 'ernel lin' in row&oat proQect:
cd rowboat-android
mv kernel kernel.backup
ln -s ~/RobertNelsonKernel/linux-dev/KERNEL kernel
An! we nee! to !o some mo!ifications in ma'efile:
chmod 644 Makefile
5e nee! to locate the following line:
e"port *ATW :E\J*ATWB:\JANR+#>#NSTALL>#RB/pre&$ilts/gcc/lin$"6"4:/arm/arm6ea&i6;.:/&in
Comment o$t that line an! replace it with the following:
export
PATH :
=~/RobertNelsonKernel/linux-dev/dl/gcc-linaro-ar-linux-gnueabi!"-#$%-&'()$'#-&
'()'#(*+linux/bin:,-PATH.
export //+PR0123 := ar-linux-gnueabi!"-
Now locate this line:
\J0A8/B 6C har!ware/ti/wlan/mac4<.11/compat>wl14"" ANR+#>R++T>#RE\
JANR+#>#NSTALL>#RB CR+SS>C+0*#L/Earm6ea&i6 ARCWEarm install
An! we nee! to replace it for:
\J0A8/B 6C har!ware/ti/wlan/mac4<.11/compat>wl14"" ANR+#>R++T>#RE\
JANR+#>#NSTALL>#RB CR+SS>C+0*#L/E\JCC>*R/F#CB ARCWEarm install
Now we can compile An!roi!=s files(stem7 (o$ can a!! =6Q.= or =6Q;= if (o$ ha,e man( cores in
(o$r comp$ter7 this will acelerate the process.
make TARGET_PRODUCT=beagleboneblack OMAPES=4.x droid
:B #n this step we are going to create the root files(stem. #n row&oat6an!roi! !irector(:
cd out/target/product/beagleboneblack
mkdir android_rootfs
cp -r root/* android_rootfs
cp -r system android_rootfs
cd android_rootfs/system
tar -xvzf ~/RobertNelsonKernel/linux-dev/deploy/*modules.tar.gz
Ass$ming that we are still in the o$t/target/pro!$ct/&eagle&one&lac' !irector(7 we nee! to
&ac'$p the file an!roi!>rootfs/init3rc an! then open it in a te"t e!itor7 we are going to to
change init.rc file:
#n the line:
import /init.\Gro.har!wareI.rc
UTN FRA LSL http://www.lslfra.com.ar .2
Android on Beaglebone Black (Rev 2)
we are going to change it &(:
import /init.am332"e,m.rc
Then7 we nee! to change the file an!roi!>rootfs/ftab3a/'').ev/7 the first line is:
/!e,/&loc'/platform/omap/omap>hsmmc.</mmc&l'<p3
an! we will change it &(:
/!e,/&loc'/mmc&l'<p3
Now we nee! to !isa&le graphical aceleration in file an!roi!>rootfs/s(stem/b#ild30ro0 &eca$se
this is not a,aila&le in 3.4 'ernel.
!e&$g.egl.hwE<
video$accelerate$!4='
Finall(7 in the o$t/target/pro!$ct/&eagle&one&lac' !irector(7 we e"ec$te:
../../../../build/tools/mktarball.sh ../../../host/linux-x86/bin/fs_get_stats
android_rootfs . rootfs rootfs.tar.bz2
The rootfs.tar.&-. file will &e create!. This is the An!roi!=s files(stem we are going to $se.
1B Now we are going to create an @imageA !irector( an! gather all necessar( files there:
cd ~/RobertNelsonKernel
mkdir image
cp rowboat-android/external/ti_android_utilities/am335x/mk-mmc/* image
cp rowboat-android/out/target/product/beagleboneblack/rootfs.tar.bz2 image
cp u-boot/MLO image
cp u-boot/u-boot.img image
cp linux-dev/KERNEL/arch/arm/boot/zImage image
cp linux-dev/KERNEL/arch/arm/boot/dts/am335x-boneblack.dtb image
4B 5e nee! to create $6&oot config$ration file $/n,.t"t in image !irector( with the following
content:
'ernel>fileE-#mage
console=tt56'7((*&''n8
croot=/dev/cbl9'p& r4
croot"st5pe=ext# root4ait
load9ernel=load c ,:cdev;:,:cpart; 'x8'&''''' ,:9ernel+"ile;
load"dt=load c ,:cdev;:,:cpart; 'x8(*"'''' ,:"dt"ile;
boot+"td=run load9ernel< run load"dt
cargs=setenv bootargs consoleblan9=' console=,:console;
androidboot$console=tt56' e=*(&= root=,:croot; root"st5pe=,:croot"st5pe;
init=/init ip=o"" video=%&'x#8'-(>?>' @eu=( vt$global+cursor+de"ault='
uenvcd=run boot+"td< run cargs< bootA 'x8'&''''' - 'x8(*"''''
UTN FRA LSL http://www.lslfra.com.ar .:
Android on Beaglebone Black (Rev 2)
PB 5e can create o$t $S car! now. First we nee! to 'now what s!C o$r s! car! is. Then we are
going to r$n the script m'mmc6an!roi!.sh
cd image
./mkmmc-android.sh [YOUR DEVICE FILE FOR THE MICROSD CARD] MLO u-boot.img zImage
uEnv.txt rootfs.tar.bz2
1<B Now we mo$nt @&ootA partition of o$r s! car! an! we !o these changes:
cd /media/boot
sudo mv uImage zImage
sudo cp ~/RobertNelsonKernel/image/am335x-boneblack.dtb .
sync
5e a!!e! !e,ice tree file an! we change! $#mage for -#mage.
Now o$r $S car! is rea!( to r$n An!roi! with 'ernel 3.4 an! !e,ice tree s$pport.
N?TE& a!& !oes not wor' &( US%7 we nee! to connect %eagle&one %lac' $sing /thernet
connector.
UTN FRA LSL http://www.lslfra.com.ar .1
Android on Beaglebone Black (Rev 2)
T#torial %2& Using *50 mo!$les.
Re9$irements:
Ro&ert Nelson 3.4 8ernel compile!.
An!roi! r$nning with Ro&ert Nelson 3.4 8ernel an! e,ice Tree
5e nee! An!roi! r$nning with 'ernel 3.4 for $sing *50 mo!$les &eca$se of we are going to
ena&le *50 $sing !e,ice tree.
5e ha,e 4 *50 o$ts:
=5N =<@ n#/ber
*P 6 .. *50<
*P 6 .1 *501
*P 6 ;. *50.
*P 6 1; *503
*P 6 1: *50;
*4 6 1P *502
*4 6 13 *50:
*P 6 .4 *501
Steps
1B First of all we nee! to install the pwm 'ernel mo!$le $sing @insmo!A comman!. This mo!$le
is in /s(stem/li&/mo!$les/3.4.136&one;<.1/'ernel/!ri,ers/pwm/ an! it is calle! @pwm>test.'oA.
insmod /system/lib/modules/3.8.13-bone40.1/kernel/drivers/pwm/pwm_test.ko
.B Using !e,ice tree now we can ena&le *50 s$pport:
echo am33xx_pwm > /sys/devices/bone_capemgr.9/slots
3B *50 mo!$le is rea!( to $se. Now we can e"port *50 o$ts as we !i! with )*#+s. #f we want
to ena&le *50: we nee! to write:
echo 6 > /sys/class/pwm/export
echo bone_pwm_P8_13 > /sys/devices/bone_capemgr.*/slots
5here @:A is for *50: an! @&one>pwm>*4>13A is &eca$se of *50: correspon!s with *4>13.
;B Now @pwm:A !irector( will appear7 we will fin! there fo$r important files:
0eriod8n: Were we set pwm=s perio! in nanosecon!s.
d#t68n: Were we set pwm=s !$t( in nanosecon!s.
0olarit6: Were we set pwm=s polarit(..
r#n: 5hen we write @1A *50 starts r$nning7 an! when we write @<A *50 stops.
UTN FRA LSL http://www.lslfra.com.ar .4
Android on Beaglebone Black (Rev 2)
2B Finall(7 we change files=s permissions to :::7 in this wa( we can write these files $sing a C
program or &( &ash console.
chmod 666 pwm/pwm6/period_ns
chmod 666 pwm/pwm6/duty_ns
chmod 666 pwm/pwm6/polarity
chmod 666 pwm/pwm6/run
The follow &ash script installs pwm mo!$le an! ena&les all *50 o$ts7 we can r$n it on
An!roi!=s initiali-ation.
MV/s(stem/&in/sh
M#!entif( &one ,ersion
mo!$leE\Jecho /s(stem/li&/mo!$les/3.4.136&oneK/'ernel/!ri,ers/pwm/pwm>test.'o Y /!ata/&$s(&o"/&$s(&o" aw'
=Gprint \1I=B
Mloa! pwm mo!$le
insmo! \mo!$le
M #!entif( cape6manager slots
slotE\Jecho /s(s/!e,ices/&one>capemgr.K/slots Y /!ata/&$s(&o"/&$s(&o" aw' =Gprint \1I=B
pwmE/s(s/class/pwm/
M Loa! *50 mo!$le
if T \Jcat \slot Y grep am33"">pwm 6cB 6gt < US then
echo am33"">pwm alrea!( loa!e!7 not loa!ing againS
else
echo /na&ling *50 !ri,er am33"">pwm
echo am33"">pwm N \slot
fiS
M Safe pins that won=t interfere with one another
MportsEJ*P>.. *P>;. *P>1: *4>13 *P>.4BS
Mportn$m&ersEJ< . ; : 1BS
MF$ll correspon!ence from pwm<6pwm1
portsEJ*P>.. *P>.1 *P>;. *P>1; *P>1: *4>1P *4>13 *P>.4BS
portn$m&ersEJ< 1 . 3 ; 2 : 1BS
M /na&le *50 pins
M The( m$st &e e"porte! at this stage7 &efore the !e,ice tree
M o,erla( for that pin is ena&le!.
cE<
while T c 6lt \GMportsTKUI U
!o
if T V 6! \pwm/pwm\Gportn$m&ersT\cUI US then
echo /"porting *50 \Gportn$m&ersT\cUI [J\GportsT\cUI[B
echo \Gportn$m&ersT\cUI N \pwm/e"port
chmo! ::: \pwm/pwm\Gportn$m&ersT\cUI/perio!>ns
chmo! ::: \pwm/pwm\Gportn$m&ersT\cUI/!$t(>ns
chmo! ::: \pwm/pwm\Gportn$m&ersT\cUI/polarit(
chmo! ::: \pwm/pwm\Gportn$m&ersT\cUI/r$n
else
echo *50 \Gportn$m&ersT\cUI alrea!( ena&le!
fiS
if T \Jcat \slot Y grep \GportsT\cUI 6cB 6gt < US then
echo *50 pin \GportsT\cUI alrea!( ena&le!7 not ena&ling again
else
Jecho &one>pwm>\GportsT\cUI N \slotB 1NX. NN /!e,/n$ll
fiS
cE\JJcL1BB
!one
5e can change which *50 mo!$les we want to initiali-e
UTN FRA LSL http://www.lslfra.com.ar .P
Android on Beaglebone Black (Rev 2)
T#torial %'& Using AC mo!$le.
Re9$irements:
Ro&ert Nelson 3.4 8ernel compile!.
An!roi! r$nning with Ro&ert Nelson 3.4 8ernel an! e,ice Tree
%eagle&one &lac' has 1 analog inp$ts7 we nee! to ena&le them if we want to $se them. Analog
inp$ts !ri,er is similar to )*#+ !ri,er7 we will rea! a file where the analog ,al$e is. 5e will ha,e
a file for each inp$t7 the ,al$e is a n$m&er &etween < an! ;<P2 J1. &it resol$tionB.
5e ha,e 1 Analog inp$ts:
=5N Analog n#/ber
*P 6 3P A#N<
*P 6 ;< A#N1
*P 6 31 A#N.
*P 6 34 A#N3
*P 6 33 A#N;
*P 6 3: A#N2
*P 6 32 A#N:
Steps
1B /na&le analog inp$ts $sing !e,ice tree:
echo BB-ADC > /sys/devices/bone_capemgr.*/slots
.B Now we will fin! 1 files in @/s(s/&$s/platform/!ri,ers/&one6iio6helper/helper.12A A#N< to A#N:.
#f we want to rea! Analog < inp$t we can $se @catA comman!:
cd /sys/bus/platform/drivers/bone-iio-helper/helper.15
cat AIN0

UTN FRA LSL http://www.lslfra.com.ar 3<
Android on Beaglebone Black (Rev 2)
Bibliogra016
Te"as #nstr$ments An!roi! images
http://!ownloa!s.ti.com/sitara>an!roi!/es!/T#>An!roi!>e,8it/T#>An!roi!>?%>;>.>.>
e,8it>;>1>1/in!e">FS.html
Te"as #nstr$ments An!roi! e,8it )$i!e
http://processors.wi'i.ti.com/in!e".php/A0332C>/H06S8>An!roi!>e,'it>)$i!e
/na&le S*#/H:
http://comm$nistco!e.co.$'/&log/&log*ost.php_&log*ost#E1
Config$re UARTS:
http://www.gigamega&log.com/.<1./<1/../&eagle&one6co!ing61<16$sing6the6serial6a
n!6analog6pins/
Create 'ernel mo!$le
http://www.it.$c3m.es/alcortes/!ocs/ap$ntes>lao/lao/no!e:4.html
@%eagle%one %lac' S(stem . Reference 0an$alA 6 )eral! Cole(7 +cto&er .<13.
@A0332" AR0a Corte"T06A4 0icroprocessors. Technical Reference 0an$alA 6 Te"as
#nstr$ments7 +cto&er .<11.
Compile 'ernel 3.4 for An!roi!
http://icc$l$s.org/Ohen!ersa/an!roi!/
*50 &onecape manager $sage
https://gith$&.com/s-moore/0CTC3;.</wi'i/SoftwareZ3A6*506Control
UTN FRA LSL http://www.lslfra.com.ar 31

You might also like