License Thesis document submitted at the Technical University of Cluj-Napoca, Computer Science Department, in July 2018. Short summary: The main goal is to implement an embedded image proce...Full description
Audi List
Descripción: Do it Yourself
Descripción completa
Cipovanje automobilaDescrição completa
chip formationFull description
Descripción: Caso de Chip Supreme
Descripción: chemical engineering physical property handbook.
chemical engineering physical property handbook.
Telangana
chemical engineering physical property handbook.Full description
Descrição completa
Bob Pease on Analog
Como hacer cambios que parecen imposibles
Full description
Descripción completa
Page 1
Table of Contents Introduction – The CHIP Book..................................................................................................................9 The CHIP story.........................................................................................................................................10 Introducing the CHIP...............................................................................................................................10 Physical architecture............................................................................................................................10 CPU.....................................................................................................................................................12 The storage subsyste.........................................................................................................................12 The !o"er syste................................................................................................................................12 #ideo out!ut........................................................................................................................................1$ %udio out!ut........................................................................................................................................1$ &eyboard in!ut....................................................................................................................................1$ Co!arison against 'as!berry Pi (ero...............................................................................................1) *etting +tarted.........................................................................................................................................1, -lashing ne" sot"are.........................................................................................................................1, Installing !ackages...................................................................................................................................2/ Installation tools..................................................................................................................................2/ a!tcache.........................................................................................................................................2 a!tile.............................................................................................................................................2$ a!tget.............................................................................................................................................2$ a!t...................................................................................................................................................2) d!kg................................................................................................................................................2) syna!tic...........................................................................................................................................2) %ailable a!!lications.........................................................................................................................2) 3ice suites – "ord !rocessors4 s!readsheets4 !resentation !ackages...........................................2) P5- ie"ers...................................................................................................................................29 *ra!hics........................................................................................................................................../0 6ail clients.................................................................................................................................../2 7eb Bro"sers.................................................................................................................................// The CHIP 8inu enironent................................................................................................................../ The shell............................................................................................................................................../ The ile syste..................................................................................................................................../$ :ounted ile systes....................................................................................................................../$ -ile !erissions............................................................................................................................../) #isuali;ing the -ile syste............................................................................................................./) Processes.............................................................................................................................................0 &ernel ode s User ode.................................................................................................................2 'oot !riileges and running a!!lications............................................................................................/ :eory anageent.......................................................................................................................... The syss ile syste...........................................................................................................................$ 3!en ile descri!tors...........................................................................................................................$ +yste a!!lications.............................................................................................................................< 7riting your o"n units...................................................................................................................$0 The systedui................................................................................................................................$2 +torage.....................................................................................................................................................$/ Page 2
=et"orking.......................................................... ....................................................... ..............................$ =et"ork:anager.................................................................. ....................................................... ........$) ........ $) =et"orking tools............................................................................... ........................................... ................................... ............... .......$, $, iconig net"ork coand.............................................................................................................$, i! net"ork coand......................................................................................................................$, i"conig net"ork coand...........................................................................................................$< i"list net"ork coand.................................................................................................................$< i"conig net"ork coand...........................................................................................................$< ncli...............................................................................................................................................$< "!a>cli............................................................................................................................................$9 "aeon net"ork coand..........................................................................................................$9 'eote login.......................................................................................................................................)0 5oain =ae +erice.........................................................................................................................)0 5=+ +erice 5iscoery and :ulticast 5=+.......................................................................................)2 %ccessing your CHIP ro the Internet.........................................................................................) +haring 7indo"s iles.........................................................................................................................) Creating an access !oint......................................................................................................................), =et"ork -ile +yste ?=-+@................................................................................. .............................. ..................... ..........)9 .)9 +ockets %PI !rograing...................................................................................................................,1 -inding an IP address ro a hostnae..........................................................................................,1 Creating a socket client...................................................................................................................,2 Creating a socket serer..................................................................................................................,2 +ending data through a socket........................................................................................................,/ 'eceiing data through a socket.....................................................................................................,/ Closing a socket.............................................................................................................................., U5P !rograing.........................................................................................................................., Aaa+cri!t socket.io.............................................................................................................................,$ +ending an eail.................................................................................................................................,$ :TT..................................................................................................................................................,) :TT Protocol..............................................................................................................................,< :osuitto :TT...........................................................................................................................,9 Building osuitto ro source................................................................................................<0 Installing on 7indo"s...............................................................................................................<1 7riting :TT clients....................................................................................................................< 6cli!se !aho...............................................................................................................................< C – :osuitto client library.......................................................................................................< =ode.Ds Aaa+cri!t – :TT............................................................... ............................... ...................... ................. ........ <) Bro"ser Aaa+cri!t – :TT.....................................................................................................<, 6thernet...............................................................................................................................................90 E7indo"s..............................................................................................................................................90 Using ing on a 7indo"s PC..........................................................................................................91 Using obaEter on a 7indo"s PC..................................................................................................9 Building E a!!lications.......................................................................................................................9, Custoi;ing the E deskto!.................................................................................................................9, 'unning Headless..................................................................................................................................10/ Using your PC as a gra!hical CHIP deskto!.....................................................................................10/ Connecting to CHIP using a serial connection..................................................................................10 Page /
-reuency +!ectru %naly;er..........................................................................................................1, The libsndile library.........................................................................................................................19 +!eech out!ut....................................................................................................................................1$1 8ogging..................................................................................................................................................1$1 Perorance...........................................................................................................................................1$ 'esource Utili;ation..........................................................................................................................1$ :eory Utili;ation......................................................................................................................1$ Perorance Coands...................................................................................................................1$$ Perorance characteristics o dierent !rograing languages....................................................1$9 Hard"are Interacing.............................................................................................................................1)0 Terinal connections.........................................................................................................................1)0 *PI3 interacing...............................................................................................................................1)2 *PI3 theory..................................................................................................................................1)/ *PI3 on CHIP..............................................................................................................................1)/ *PI3 using libsoc....................................................................................................................1) *PI3 using =ode.Ds.................................................................................................................1)$ I2C.....................................................................................................................................................1)) I2C theory.....................................................................................................................................1)) I2C on CHIP.................................................................................................................................1)9 I2C "ith libsoc.........................................................................................................................1,1 I2C "ith =ode.Ds......................................................................................................................1,2 P7:.................................................................................................................................................1,2 P7: theory.................................................................................................................................1,2 P7: on CHIP..............................................................................................................................1,/ U%'T ?+erial@ Interace....................................................................................................................1,/ U%'T theory................................................................................................................................1,/ U%'T on CHIP.............................................................................................................................1,/ U+B...................................................................................................................................................1, Bluetooth...........................................................................................................................................1,$ Bluetooth s!eciication.................................................................................................................1,$ Bluetooth *%TT.......................................................................................................................1,< +erice 5iscoery Protocol......................................................................................................1,9 Bluetooth C Prograing............................................................................................................1,9 hci>get>route............................................................................................................................1<0 hci>o!en>de...........................................................................................................................1<0 hci>inuiry...............................................................................................................................1<0 hci>read>reote>nae............................................................................................................1<1 str2ba........................................................................................................................................1<1 ba2str.................................................................. ....................................................... ...............1<1 .............. .1<1 Bluetooth %udio............................................................................................................................1<2 Bluetooth '-C3::....................................................................................................................1<2 Bluetooth tools..............................................................................................................................1< l2!ing.......................................................................................................................................1< rco.....................................................................................................................................1< bluetoothctl............................................................... ............................................. ..................................... ................ ................. ..........1<$ .1<$ hciconig..................................................................................................................................1<) hcitool......................................................................................................................................1<) Page $
gatttool.....................................................................................................................................1<) :icro +5...........................................................................................................................................1<< Hard"are interacing ea!les..............................................................................................................1<< +i!le *PI3 3ut!ut change.............................................................................................................1<9 +i!le *PI3 In!ut change................................................................................................................192 *PI3 etenders.................................................................................................................................19 PC-<$,.......................................................................................................................................19 :CP2/01,....................................................................................................................................19, =eoPiels................................................................... ........................................................ ................200 =eoPiel theory.............................................................. ............................................ .................................................... ................ ..........200 ..200 =eoPiels on CHIP............................................................... .................................................. ........................................................20/ ......20/ =eoPiels through the %rduino................................................... %rduino................................................... ................................... ........................... ................ .............. ......20/ 20/ =eoPiels through =ode.DsFAohnny-ieF%rduino I2C back!ack........................... ................ ........ ............. .....209 209 8C5 dot atri dis!lay – H5,<0.................................................................................................212 PC-<$, odule..........................................................................................................................21< *P+....................................................................................................................................................220 The g!sd !ackage.........................................................................................................................222 *P+ ro your cell !hone............................................................................................................22, #ideo F 7ebcas...............................................................................................................................22< +treaing a "ebca ideo...........................................................................................................2/1 'ecording a "ebca iage or a !eriod o tie..........................................................................2/1 'ecording a ideo.........................................................................................................................2/2 Playing ideo................................................................................................................................2/2 Barcode and ' Code scanning...................................................................................................2// 3!enC# – 7ebca !rograing................................................................................................2// %nalog to 5igital conersion – %5C02........................................................................................2/ %nalog to 5igital conersion – %5+101$.........................................................................................2/< Using Aaa+cri!t......................................................................................................................21 %cceleroeter and *yrosco!e – :PU)0$0 ?aka *G$21@.............................................................22 The ath o %cceleroeters.........................................................................................................29 #isuali;ing orientation..................................................................................................................2$0 Co!ass – H:C$<8 ?aka *G2,1@ *G2,1@ ?aka CA:9@.................................................... ...................2$0 ................... 2$0 Using 7iringCHIP........................................................................................................................2$$ Using Aohnny-ie........................................................................................................................2$) Tilt co!ensation o the co!ass................................................................................................2$, Using the shell..............................................................................................................................2$< Te!erature and !ressure – B:P1<0...............................................................................................2$< :otion detectors – Passie Inrared +ensor ?PI'@............................................................................2$9 Ultrasonics – HC+'0.....................................................................................................................2)0 n'-2801 net"orking......................................................................................................................2)2 Using the %rduino %PIs................................................................................................................2)/ *ra!hic 6uali;er..............................................................................................................................2)) :icro!hone in!uts.............................................................................................................................2), -: 'adio...........................................................................................................................................2), 865 ,+egent dis!lays...................................................................................................................2)9 3!to isolators F 3!to cou!lers...........................................................................................................2,0 C50$1 – 5igital s"itches................................................................................................................2,2 Page )
+ot"are 5eined 'adio – 5#BT 'eceier.....................................................................................2,/ %5+B 5ecoding..........................................................................................................................2, Bluetooth tracker – iTag....................................................................................................................2,, 'eal tie clocks................................................................................................................................2,9 %rduino I56 on CHIP.......................................................................................................................2<2 6lectronics..............................................................................................................................................2 %ttaching your Chi! to circuit boards...............................................................................................2< 5ra"ing circuits and breadboards – -rit;ing....................................................................................2< 5ra"ing +cheatics – 5igi&ey +cheeit.....................................................................................2<$ 5ra"ing +cheatics and PCBs – Circuit:aker +ot"are................................................................2<) Using a logic analy;er.......................................................................................................................2<) 3ercoing tre!idation o using Integrated Circuits........................................................................2<, 8ogic 8eel +hiting..........................................................................................................................2<< Transistors as s"itches......................................................................................................................290 Po"er in!uts......................................................................................................................................291 Current and #oltage eters...............................................................................................................29/ 7eb !rograing..................................................................................................................................29 Bro"ser security................................................................................................................................29 '6+T reuests...................................................................................................................................29$ A+3= !rocessing in C...................................................................................................................29$ Using !ostan or testing.............................................................................................................29) 7riting a '6+T reuest using C...................................................................................................29) 7riting a '6+T reuest using =ode.Ds.........................................................................................29) 7riting an %!! that listens or '6+T reuests.............................................................................29, 8istening or '6+T reuests using =ode.Ds.............................................................................29, 7eb+ocket.........................................................................................................................................29< % 7eb+ocket bro"ser hosted a!!lication....................................................................................299 CHIP as a 7eb+ocket serer......................................................................................................../00 7eb+ocket +erer or C using lib"ebsocket.........................................................................../01 7eb+ocket +erer or C using noPoll....................................................................................../0 7eb+ocket +erer in Aaa+cri!t............................................................................................../0$ =ode.Ds as a 7eb +erer.................................................... ................................................................/0) =ode.Ds and 6!ress................................................................... .................................................../0) 6!ress iddle"are................................................................................................................./0) 6!ress routing......................................................................................................................../0) 6!ress 7eb+ocket su!!ort...................................................................................................../0, 6!ress as an htt!s serer......................................................................................................../0< Duery – Aaa+cri!t rae"ork............................................................................... ........................../0< Using Duery................................................................................................................................./0< :aking '6+T reuests using Duery.........................................................................................../0< Using Bo"er....................................................................................................................................../09 'obotics................................................................................................................................................./09 Heading in a direction......................................................................................................................./10 ProDects.................................................................................................................................................../11 7iringCHIP....................................................................................................................................../11 #isuali;ing :PU)0$0 orientation...................................................................................................../11 Building libsoc.................................................................................................................................../11 Page ,
Introduction – The CHIP Book Howdy Folks, I've been working in the software business for over 30 years but until recently, hadn't been playing directly with Micro Processors !hen I bought a "aspberry Pi and then an #rduino, I'$ afraid I got hooked In $y house I a$ surrounded by co$puters of all shapes, si%es and capacities & any one of the$ with orders of $agnitude $ore power than any of these s$all devices & however, I still found $yself fascinated #s the nu$ber of available single board co$puters continues to grow, HIP caught $y attention #s one of the cheapest on the $arketplace yet re$aining full featured I had to take a look and I liked what I found #s I studied the devices, I started to $ake notes and $y pages of notes continued to grow and grow (his book is $y collated and polished version of those notes "ather than keep the$ to $yself, I offer the$ to all of us in the HIP co$$unity in the hope that they will be of so$e value My plan is to continue to update this work as we all learn $ore and share what we find in the co$$unity foru$s #s such, I will re)release the work at regular intervals so please check back at the book's ho$e page for the latest I do not plan on ever calling this book *finished* as there will always be $ore to add +ecause of the breadth and depth of $aterial that we want to cover, it is unlikely that you will want to read the book linearly fro$ cover to cover Instead, I reco$$end that you fa$iliari%e yourself with the table of contents and co$e back to it as and when you need infor$ation #s you read, $ake sure that you fully understand that there are undoubtedly inaccuracies, errors in $y understanding and errors in $y writing nly by feedback and ti$e will we be able to correct those Please forgive the gra$$atical errors and spelling $istakes that $y spell checker hasn't caught (he ho$e page for the book ishttps-..leanpubco$. chip Please don't e$ail $e directly with technical /uestions Instead, let us use the foru$ and ask and answer the /uestions as a great co$$unity of HIP $inded enthusiasts, hobbyists and professionals
Neil Kolban Texas, USA
Page 9
The CHIP story In May 012, a s$all co$pany called e4t (hing o launched a 5ickstarter pro6ect for a new M7 $odule which they called HIP 8which in this book I 6ust call HIP9 (he goal was to produce a credit)card si%ed :inu4 co$puter for ;< (heir initial ask was ;20,000 to get the pro6ect going (hey received ;,0=1,<=>>> (he 5ickstarter was successfully funded in ?une 012 with 3<,2@0 backers & and fro$ there the challenge was on 5ickstarter backers had to have their early orders fulfilled and pre)orders beyond the 5ickstarter ca$paign were taken I sub$itted an order for instances of HIP during the first week of ?anuary 01@ and received the$ $id)?uly It is taking a little ti$e, but with patience and perseverance and with the volu$e of HIPs being $ade, it is hoped that their availability should increase (he details of HIP, and how to get the $ost fro$ it is the sub6ect of this book
Introducing the CHIP (he central processing unit 8P79 of the HIP is a 1AH% #llwinner "B processor (here is an on)board 21M+ of "#M and CA+ytes of flash to hold progra$s Fro$ a co$$unications perspective, HIP supports both !iFi and +luetooth C0 Dideo output is supplied in the for$ of co$posite video and hence can be plugged directly into a (D or $onitor that accepts that input for$
(he operating syste$ running on HIP is based on the :inu4 Eebian distribution
Physical architecture (he following i$ages are reproduced fro$ the HIP docu$entation pages (hey illustrate the $a6or co$ponent of the physical structure of the device
Page 10
(he HIP architecture is open source che$atics for HIP can be found on AitHubhttps-..githubco$.e4t(hingo.HIP)Hardware (hird party vendors have build cases for HIP (he following is fro$ C:abs-
e4t(hingo also $ake a ; cover for the rear of the HIP I reco$$end so$e case over the circuitry ooner or later you will put your HIP down on so$ething either wet or $etallic and be disappointed that you shorted so$ething out 8perhaps even da$age the device9
ee also•
Page 11
Gebra HIP ase
CPU (he heart of any co$puter is its P7 HIP uses an #llwinner "B processor running at 1AH% (he architecture of the chip is #r$ orte4)#B ee also•
#ll!inner "B
•
#llwinner "B Eatasheet
•
#llwinner "B 7ser Manual
The storage subsystem HIP co$es with C A+ytes of flash $e$ory for storing data including the operating syste$, your own applications and any data needed by those applications Euring boot, console $essages are written and these can be shown after boot using the * dmesg* co$$and If you were to read through the logs, you would find $ultiple $essages such asBad eraseblock 2034 at 0x0001fcbfc000
(his sounds troubling It see$s to indicate that the storage has errors and this is indeed true Flash $e$ory checks the integrity of data re)flashed and validates that what was written was what was e4pected !hen errors are found, the blocks of storage used to hold data are flagged as invalid and beco$e no longer available for use, thus reducing the overall storage si%e In the current technology available to us, blocks can and do beco$e 8or initially so$e are9 invalid (his is the nature of the high density storage $echanis$s in play (o deter$ine how $any blocks are available and how $any are bad, one can e4a$ine the output of d$esg looking for *bad P+s* For e4a$ple$ dmesg | grep -i "bad PEBs" ubi0 good PEBs 201! bad PEBs 2# corrupted PEBs 0
In the above, we see there are < blocks flagged as *bad* which is about 1C ee also•
The power system HIP is powered at 2D and draws about 200$# during boot and other $a4i$al operations with a resting consu$ption of about B0$# (he reco$$endation is to power the device with a 2D supply capable of delivering <00$# or $ore # chip called the #JP0< handles power $anage$ent including the ability to be powered fro$ and charge a :iPo battery n the header ter$inals, we find a variety of power sources include 2D, 33D and 1BD (he $a4i$u$ current draws on these are #, =00$# and 20$# respectively (here is a s$all button on the front of HIP that can be used to switch it on and off If HIP Page 12
is off, then holding the button down for a second will power it on If the HIP is on, then holding the button down for 10 seconds will power it down & however, try and avoid that $ethod (he correct way to shutdown HIP is to run the *sutdo%&* co$$and If we re$ove power fro$ the HIP either by literally re$oving the power or holding the power off button down, then we run the risk of corrupting our device as any files that $ay be in the process of being updates $ay not co$plete and we will end up with corrupt files If we need to supply power to HIP fro$ an e4ternal source 8as opposed to through the 7+9 then we should apply the 2D voltage to the header ter$inals $arked AH)I 8713)9 and AE 8713)1 or 713)C9 (his input arrives at a power regulator If we power the HIP through HA)I, the :Es $ay flash briefly once when power is applied but the HIP not appear to boot (his is as it should be Hold down the power button for 10 seconds and then the :Es will light and HIP boot (he #JP0< is an I device found on I bus 0 at device address 0x34 HIP has two on)board :Es ne is called P'( and is connected directly to a 33D source (his :E is $agenta in color (his $eans that when power is active through the #JP0< 8ie HIP is on9 then the :E will be lit (here is no control over this :E (he second :E is called )*+* and is connected to one of the four API lines 8API9 of the #JP0< (hat $eans that it can be controlled fro$ software (he #JP0< register that controls the signal on API is 0x#3 (his :E is white in color (o switch off the :E, the following I co$$and can be used$ sudo i2cset -f -, 0 0x34 0x#3 0x00
(o switch it back on, we can use$ sudo i2cset -f -, 0 0x34 0x#3 0x01
(he battery connector is a ?()PH connector +e sure and connect power the right way around Kve is to the right with the 71C header to the left I failed to get this right and i$$ediately fried a precious HIP It $ade $e very sad & please don't $ake the sa$e $istake
able for ?()PH can be purchase very cheaply
Page 1/
:iPo batteries with the correct plugs can also be found
(he #JP0< also has an internal te$perature sensor (he data is available via I by reading registers 0x!E and 0x! fro$ the #JP0< device (he first register is the low order C bits of the result while the second byte is the ne4t B bits & giving us 1 bits in total (o interpret the result, the data is in steps of 01 with a base of )1CC= #s such, our calculation will be.../alue.0x!e 0x0f | ../alue.0x!f 0xff 410 14456
(he values of the registers can be read through$ sudo i2cget -, f 0 0x34 0x!e $ sudo i2cget -, f 0 0x34 0x!f
# script is supplied with :inu4 i$age called *batterysh* !hen run as root, it returns a wealth of infor$ation about the battery subsyste$$ sudo batter,5s B+*7)*+*8)90 :;+(<7=>?91 B+*7E@=)*91 :;+(
Batter, carge curre&t 9 1115!m+ =&ter&al temperature 9 !!52c
HIP $ight be corrupted if we power it down without first shutting down :inu4 #n elegant progra$ is available on AitHub called *blink* that runs as a service at boot ti$e (his progra$ can 8a$ong other things9 detect the button press and cause a clean shutdown to occur eehttps-..githubco$.fordsfords.blink ee also•
#JP0< Eatasheet
Video output # 6ack socket is found on HIP into which a supplied cable can be plugged (he cable ter$inates in co$posite video output of audio left, audio right and video
udio output (he 6ack socket used for co$posite video output can also be used for stereo output # standard 32$$ audio plug such as those for headphones or a$plifier input can be inserted
!eyboard input # 7+ keyboard can be plugged into the 7+ socket (hese can be picked up very cheaply (hinking of the s$all for$ factor of HIP, one of $y favorites is the hand)held wireless keyboards that are available for about ;10);12
(hese devices use a CAH% dongle that plugs into the 7+ port ot only does one get a hand held keyboard, but the $ouse pad at the top works surprisingly well "unning the CC 5ernel i$age, I was delighted to find that it worked first ti$e out of the bo4 with no tweaks or other configurations needed ote that this is not a bluetooth keyboard and hence the dongle needs to be inserted into the 7+ socket onnection to the dongle can be validated by running *lsusb* and looking for the 7+ IE of the dongle$ lsusb Bus 002 ?e/ice 002 =? 2!a60601 Page 1$
Comparison against "aspberry Pi #ero !hen HIP was first $entioned, the closest e/uivalent on the $arket was the ;32 "aspberry Pi #t over 3 ti$es the price of the proposed HIP and without networking, it see$ed that they would be addressing different $arkets however, in ctober 012, the "aspberry foundation $ade a fantastic announce$ent L the "aspberry Pi Gero (his is also a :inu4 co$puter which is physically s$aller than a credit card with the astonishingly low price of only ;2 I'$ a great fan of choice and co$petition while at the sa$e ti$e not a fan of redundant duplication I saw the arrival of two very si$ilar devices in a $i4ed light I don't hold a bias on HIP vs "aspberry Pi Gero 8I've written books for both9 :et us try and do as factual a co$parison as possible between the twoConcept
CHIP
Raspberry Pi Zero
Price
9
$
%ailability
Poor ?Auly 201)@
Constrained ?Auly 201)@
Processor
1*H;
1*H;
'%:
$12:B
$12:B
+torage
*Byte lash
:icro +5
7i-i
yes
no
Bluetooth
yes
no
U+B
yes ?Ty!e %@
yes ?:icro@
#ideo
Co!osite
H5:I
*PU su!!ort
=o
Ges
I2C
yes
yes
+PI
no
yes
+erial
yes
yes
%5C
no
no
P7:
no
yes
Caera bus
no
yes
Battery charging
yes
no
3+
8inu
8inu
Counity
-ledgling
:ature
If we co$pare e4clusively on price, obviously ;< is $ore than ;2 but let us not forget that in order to get a Pi Gero running, you will need a Micro E card If you want to network, you will also need a !iFi dongle and since the 7+ port on the Pi Gero is $icro 7+ and the !iFi dongles are 7+ (ype # plugs, you will need an adapter !hile none of these are particularly e4pensive, the additions start to bring the prices in line with each other ee also•
Page 1)
HIP vs Pi Gero- !hich ub);10 o$puter Is +etter
$etting %tarted (o boot up the HIP, we $erely need to supply power to the $icro 7+ power socket HIP will boot and be running HIP co$es supplied with a cable that outputs co$posite video that can be plugged into a (D or $onitors with co$patible inputs Euring booting we will see the :inu4 boot output scrolling by #t the end, we will be presented with a graphical environ$ent with which we can interact #nd now things start to get interesting !e need a $ouse and a keyboard to be connected to allow us to interact ow & this is i$portant & before you start custo$i%ing your HIP you need to ask yourself the /uestion about upgrading the software that is currently on it as shipped fro$ the factory It is likely that what is on the HIP is not the latest and greatest low)level kernels and applications 7nfortunately, we can't yet do an in)place upgrade and $ust re)install the whole i$age in order to get to the latest !hen we do this re)install, #:: configuration changes, applications and data that you place on the HIP is lost If you think you $ight want to go to the latest level, see the section called Flashing new software& before going too $uch further !hen you have started HIP, try hard not to si$ply power it off by re$oving power (hat can corrupt the storage Instead issue the co$$and *sudo sutdo%& &o%* (his will cleanly end the run of the device and after the co$$and has shutdown the device, then you can safely re$ove power fro$ it If you need to restart the device, you can run the co$$and *sudo reboot* (he device will shutdown and then restart Nour HIP doesn't know where in the world it is It will be able to get the universal ti$e fro$ a ti$e server over the internet, but without knowing where in the world you are, it doesn't know your local ti$e %one (o set this up, run the co$$and$ sudo dpkg-reco&figure tCdata
Fro$ there you will be presented with a series of $enus to help you setup your local ti$e%one
&lashing new software (he storage device on HIP is a C A+yte flash $e$ory chip (his is not a re$ovable or replaceable co$ponent !hen new releases of the 5ernel are $ade available, we can install these through a process known as *flashing* It is i$portant to reali%e that flashing the storage results in the co$plete replace$ent of what was there previously +eing very e4plicit, when you flash the HIP, all custo$i%ations, progra$s and data that $ay have been present will be lost and you will be at an e/uivalent of a factory reset to the version of the i$age that you flash (here is no recovery of data that was present before the flashing so $ake sure you copy off any files you $ay want or need to save
Page 1,
(o start understanding how to flash the HIP, visit the website called http-..flashgetchipco$ using a copy of the Aoogle hro$e +rowser (he reason for using hro$e is that the flasher application used to install the new i$age runs within the hro$e environ$ent nce there, you will see a page si$ilar to the following-
licking the *+?? *D :;(DE* button pops up a confir$ation-
nce added, the page will now show the i$ages that can be flashed onto the HIP-
Page 1<
(he reco$$endation is now to use the *cloud* icon in the upper right of each i$age (his will download the corresponding i$age file (hese files end in *5cp* nce an i$age file has been downloaded, we can find the following i$age to flash this file to the HIP-
(he first ti$e we want to flash, we will see the following dialog-
Page 19
ow we install the driver licking the *I(#:: (H E"ID"* button, downloads an e4ecutable called *=&stall?ri/er25exe* !hen we run this, we get a$ installation wi%ard-
#s we progress through the wi%ard, the ne4t page seen is-
ow we are ready to flash (o do this, we add a wire fro$ the *EA* ter$inal to a ground Page 20
ter$inal
e4t we plug in HIP to a 7+ port on the P
Page 21
7nfortunately, in $y e4perience, it wasn't that si$ple !hen I plugged it in directly and then followed the later steps, I ended up with failure #fter using a powered 7+ hub, it i$$ediately started working
Page 22
Nou can deter$ine your new currently installed version by running the co$$and$ u&ame -a" Ai&ux cip 454511-&tc F1 )P )at a, 2G 002606 8*: 201H arm/6l <>8Ai&ux
Installing packages nly a subset of the possible available applications are pre)installed on HIP If you want to install $ore, you can (he tools that are available for that are * apt-get* +efore adding new progra$s run apt)get with the * update* flag to refresh the catalog of available applications$ sudo apt-get update
(o upgrade any installed packages, we can use$ sudo apt-get upgrade
(his will deter$ine what you have installed and perfor$ the upgrades to get you to the latest levels of these installed packages Perfor$ing an upgrade can take so$e ti$e so be sure that you are available to leave the HIP running un)attended for a while
Installation tools !hen we think of a :inu4 operating syste$, we will find that the state of a syste$ is governed by the e4istence and versions of files on the file syste$ If we consider a *package* to be a collection of files necessary to perfor$ so$e discrete operation, then we can also think of the files on the :inu4 file syste$ as being $e$bers of so$e package or another 8with the obvious Page 2/
e4ception of application files that you create9 If we wish to install a package, we $ust obtain a copy of all the files associated with that package and place the$ in the correct directories where they are e4pected to be found If we were atte$pt to do this by hand, we would end up in all sorts of troubles ot least of which would be the potentially of $aking $istakes with $anual copies In addition, so$e packages are not self contained but instead have prere/uisites which are the$selves packages !hat we need is so$e registry $echanis$ where we can learn what packages are installed and a repository where packages can be found and downloaded (his is e4actly what the apt technology does for us (he apt technology is a suite of related applications which coordinate together to perfor$ package $anage$ent functions (o begin with, the apt syste$ needs a list of sources fro$ which packages can be found (his is specified in a file called etcaptsources5list It is fro$ this list of sources that new packages and updates to e4isting packages can be found # typical entry in the sources5list file looks likedeb ttpftp5us5debia&5orgdebia& Iessie mai& co&trib &o&-free deb-src ttpftp5us5debia&5orgdebia& Iessie mai& co&trib &o&-free deb ttpsecurit,5debia&5org Iessieupdates mai& co&trib &o&-free deb-src ttpsecurit,5debia&5org Iessieupdates mai& co&trib &o&-free deb ttpttp5debia&5&etdebia& Iessie-backports mai& co&trib &o&-free deb-src ttpttp5debia&5&etdebia& Iessie-backports mai& co&trib &o&-free deb ttpope&source5&extti&g5cocipdebia&repo Iessie mai&deb
It is i$portant to note that a package that is downloaded and installed fro$ the repository $ay not be the very latest version of that package available In fact, e4perience is showing that so$e packages downloaded fro$ the repository are very old indeed e4t we will look at so$e of the pri$ary co$$ands for working with packages (he $ost i$portant of these is apt-get !e will be using apt-get e4tensively to install new packages that aren't present in a default distribution ee also•
apt)rp$org
apt-cache :ist available packages $ apt-cace pkg&ames
how statistics on the cache Pri$arily what we see here is disk space consu$ed by the cache as well as counts of the known packages $ apt-cace stats *otal package &ames !!#11 .111G k *otal package structures !!#1H .2HG4 k Page 2
apt-file (he apt-file tool allows one to find which package $ight contain a specific file ote that apt-file needs to be installed with the following co$$and$ sudo apt-get i&stall apt-file
nce installed, we need to run $ apt-file update
to retrieve the database of packages and the files they contains (o find which package contains a file$ apt-file searc file&ameJ
(o list files contained in a package$ apt-file list package&ameJ
apt-get (he apt)get co$$and is a co$$and line interface to the #dvanced Packaging (ool 8#P(9 library It is by far the $ost co$$only used of the package $anage$ent tools (o install a package we can run$ sudo apt-get i&stall pkg&ameJ
(o un)install a package run$ sudo apt-get purge pkg&ameJ
(o download the package without installing it run$ apt-get do%&load pkg&ameJ
(he downloaded package will end in * 5deb* !e can then install that package using* Page 2$
$ sudo dpkg --i&stall file>ame5debJ
If we 6ust wish to see the effect of perfor$ing a co$$and without actually co$$it to run it, we can add the --simulate option (o refresh our list of packages, we can run$ apt-get update
(o upgrade our installed packages to the latest levels, we can run$ apt-get upgrade
ee also•
$an8B9 L apt)get
•
2 7seful +asic o$$ands of #P()A( and #P()#H for Package Manage$ent
•
:inu4 and 7ni4 apt)get co$$and
apt (o see which packages are installed, run $ apt --i&stalled list
dpkg (he dpkg co$$and is the base co$$and for package installation If we have a local *deb* file which contains a package, we can install it using$ sudo dpkg -i file&ame5debJ
synaptic (here is also a A7I interface to package $anage$ent called *synaptic* (his can be installed through$ sudo apt-get i&stall s,&aptic
ee also•
!ikipedia L ynaptic
'ailable applications (here are hundreds 8thousands9 of installable applications available for HIP Office suites – word processors, spreadsheets, presentation packages #n e4cellent open source pro6ect called *:ibreffice* is available for HIP :ibreffice is a full function office suite including a word processor, spreadsheet and presentation engine It can Page 2)
be installed through$ sudo apt-get libreoffice
It's a big package and takes a bit of ti$e to install, so be patient and grab a coffee #fter installation you will find the tools in the *ffice* $enu-
#t the ti$e of writing the version that is available is *C33* (he word processor provider by :ibreffice is called *!riter* (his book was written on !riter 8on a !indows 10 P I'$ afraid9 Here is what writer looks like-
Page 2,
Dery intuitive and easy to learn (he spreadsheet is called alc and looks like-
Page 2<
#gain, if you are fa$iliar with other spreadsheets, you will find this one /uick to learn too ee also•
:ibreffice
PDF viewers I often find $yself wanting to read PEF docu$ents on $y HIP # good tool for PEF reading is kular It can be installed with$ sudo apt-get i&stall oklular
(here is /uite a bit to it so it $ay take so$e ti$e to install nce installed, we run$ okular
and open any PEF files we $ay have #s we can see in the following screen shot, a pretty co$prehensive PEF viewer-
Page 29
ee also•
kular ho$e page
Graphics (he A7 I$age Manipulation Progra$ or as it is $ore co$$only called *AIMP* (his can be installed with$ sudo apt-get i&stall gimp
#fter installation it can be found in the *Araphics* $enu-
Page /0
nce launched, it provides a rich assort$ent of tools for drawing and i$age $anipulation-
Page /1
ee also•
AIMP
Email clients IceEove is a version of the popular Mo%illa (hunderbird e$ail client It can be installed with$ sudo apt-get i&stall icedo/e
IceEove has all the usual features including calendaring and newsfeed support nce installed it can be found under the Internet category-
!hen launched, it looks as follows-
Page /2
e! "rowsers (he popular FireFo4 browser is available
It provides the $a6ority of functions one e4pects fro$ a browser but you will be dissapointed with the perfor$ance co$pared to a P desktop However, that doesn't stop us using it for a variety of purposes including as a kiosk or as a host for browser based applications Page //
The CHIP (inu) en'ironment (he operating syste$ of HIP is :inu4 based on the Eebian distribution (here are $any e4cellent books, web pages and foru$s covering :inu4 so it is not $y atte$pt to try and recreate any of those Instead, here is a very short su$$ary to give you so$e of the core co$$ands and concepts you will find useful and use these as a springboard into further study as needed ee also•
!iki pedia L :inu4
The shell !ithout e4ception, an environ$ent on HIP that you will be working with is the shell (he shell is a co$$and interpreter that takes the co$$ands you enter at the keyboard and e4ecutes the$ !hether you use the *ss* progra$ to re$otely login or start a ter$inal e$ulator on the graphical desktop, both present you with an instance of the shell !hen you enter a co$$and, the co$$and is looked for in each of the directories specified Page /
by the P+*; environ$ent variable (he first directory which contains a file with the na$e of your co$$and is the one that is e4ecuted Nou can see a history of your previous co$$ands by entering * istor,* # list of co$$ands prefi4ed by a nu$ber is displayed ntering *K&umJ* will cause that co$$and to be re)e4ecuted
The file system (he HIP file syste$ is a standard :inu4 file syste$ hosted in flash $e$ory (his is a hierarchical file)syste$ co$prised of files and directories It supports all the standard :inu4 co$$ands for file $anipulation-
•
cp L copy files
•
m/ L $ove files
•
rm L re$ove files
•
ls L list files
•
l& L link files
•
mkdir L $ake a directory
•
rmdir L re$ove a directory
•
cmod L change file and directory per$issions
•
mou&t L $ount a file syste$ for use
•
umou&t L un)$ount a previously $ounted file syste$
ee also•
$an819 L ln
#ounted file systems HIP supports the standard 7ni4 *mou&t* co$$and for $ounting file syste$s onto the file structure #n especially useful co$$and is called *fi&dm&t* that displays a visuali%ation of what is $ounted and where
ee also•
Page /$
$an8B9 ) find$nt
File permissions n a :inu4 , files and directories have per$issions associated with the$ +y and large there are three per$issions a file can have which are *read*, *write* and *e4ecute* (hese declare whether a file can be read fro$, written to or be e4ecuted # file also has the concept of an owner and a group !hen we talk about per$issions, we further categori%e the per$issions into those that are allowed for the owner of the file, those that are allowed for $e$bers of the group associated with the file and those that are allowed for everyone else 8ie neither the owner nor a $e$ber of the group9
!e thus end up with nine specific per$issions-
•
owner L read . write . e4ecute
•
group $e$ber L read . write . e4ecute
•
others L read . write . e4ecute
#n encoding sche$e has been used for visuali%ing and describing per$issions for files using the octal nu$bering syste$ 8base B9 If we i$agine that the three per$issions were described in 3 bit binary with an order of read . write . e4ecute then we would have per$issions of *r%x* & or O1.0O1.0O1.0 o in binary, per$issions of 101 would say we have per$ission to read and e4ecute but not write If we translate this binary into octal, it would be written as CK0K1 Q 2 (hus we can represent a set of read . write . e4ecute per$issions as a single octal digit 80)=9 o$bining this with the notion that we have three sets of per$issions 8user, group and other9, we can co$pletely describe all the per$issions on a file with three octal digits For e4a$ple =22 would be a value of = for user 8read . write . e4ecute9 and 2 for both group and other 8read . e4ecute9 (he :inu4 co$$and called cmod can be used to set the per$issions For e4a$plecmod 6!! m,ile
Eoes this sound co$plicated Nes it does & however it is how 7ni4 has been handled since its inception (here are other $echanis$s should you not wish to re$e$ber these encodings and those can be read about in the $an pages for cmod
$isuali%ing the File system For those who don't want to navigate through the file syste$ fro$ the shell, there is an attractive A7I navigator supplied by the tool called *(hunar*
Page /)
(his can be started fro$ the desktop conte4t $enu by running * ile a&ager* (he feel of this is si$ilar to the Microsoft !indows 4plorer environ$ent I'll assu$e that $ost of us are fa$iliar with navigating a file $anager like this but here are so$e of the $ore interesting features #nother popular file $anager is called *autilus* (his is also provided on HIP It looks as follows-
# third file $anager is called *PManFM* however this is not installed by default !e can install it using$ sudo apt-get-i&stall pcma&fm Page /,
(his is the file $anager used by default on the "aspberry Pi "aspbian operating syste$ so if you are $oving fro$ a Pi environ$ent to HIP, this $ay be an attractive choice (his can be started fro$ the co$$and line tool * pcma&fm* or fro$ the icon in the task bar (he feel of this is si$ilar to the !indows 4plorer environ$ent I'll assu$e that $ost of us are fa$iliar with navigating a file $anager like this but here are so$e of the $ore interesting features First there is a dual pane $ode 8Diew J Eual Pane Mode . F39 (he screen splits into two parallel views where you can look at two distinct folders Fro$ here you can drag and drop files between the$
o$eti$es the large icon view is distracting and you can switch to a detail view 8Diew Folder Diew Mode J Eetailed :ist Diew9-
Page /<
J
r you can go so$ewhere in between with the co$pact view-
Nou can open $ultiple tabs where each tab is its own folder view 8File
J ew
(ab . (":K(9
Possibly one of the $ost i$portant functions is the ability to open a shell window at the current folder !e can do this fro$ (ools J pen urrent Folder in (er$inal . FC #n especially elegant feature in this package is the ability to *book$ark* fre/uently used folders nce book$arked, it appears on the list on the length and provides a /uick Page /9
navigation to that folder when needed (he choice of which one you use is purely personal preference (o choose the default in use, open up the *)etti&gs a&ager* and select *Preferred +pplicatio&s*-
In the 7tilities section, we will find an entry called * ile a&ager* where we can specify which of the available File Manager packages we want to use-
#n alternative to the graphic environ$ent is the tool called * tree* which visuali%es a directory structure as an #II tree layout (his progra$ is not installed by default and one $ust install using$ sudo apt-get i&stall tree
ee also•
!ikipedia L (hunar
•
!ikipedia L autulius 8AM Files9
•
PManFM L File $anager
Processes # process is the na$e we give to a running instance of a progra$ !hen we start a progra$ it runs within its own conte4t separate fro$ the conte4t of other progra$s (he process Page 0
$anages that conte4t and includes the files that progra$ opened, the e4ecutable running, the environ$ent variables, the user running the progra$ and $ore ach process is uni/ue identified with an integer identifier call the Process IE or PIE (o see which processes are running on our HIP we can issue the * ps* co$$and (his has a ferocious nu$ber of options and deep reading of the $anual page would be re/uired to gain full appreciation In its basic for$, when we run it it will show the PIE and co$$and associated with that pid For e4a$ple$ ps P=? **L 6232 pts1 66!6 pts1
*=E :? 000000 bas 000000 ps
otice that we get to see the PIE colu$n #nother co$$and available to us is called *pidof* (his takes the na$e of a co$$and and returns us the PIEs for all instances of that co$$and For e4a$ple$ pidof gea&, 4G23
nce we know the PIE of a running progra$, we can ter$inate it by sending it a * kill* signal (hese are asynchronously trans$itted signals that indicate to the process that so$e e4ternal event has happened (o see the list of possible signals run$ bi&kill -A 1 ;8P 2 =>* G PE # N=AA 1! *E( 1H )*NA* 22 **D8 23 8(< 2# PDAA 30 P'(
3 10 16 24 31
M8=* 8)(1 :;A? @:P8 )L)
4 11 1G 2!
=AA )E< :D>* @)O
! 12 1# 2H
*(+P 8)(2 )*DP *+A(
H 13 20 26
+B(* P=PE *)*P P(D
6 14 21 2G
B8) +A( **=> '=>:;
(o send a signal we can use one of the following two synta4 for$atskill -&umberJ P=?J
or kill -&ameJ P=?
For e4a$plekill -1 4G23
and kill -;8P 4G23
are identical ach signal can be trapped by the process that receives it allowing the process to deter$ine how it wishes to handle its arrival (he one e4ception is .# N=AA & which is un)trapable and causes the i$$ediate ter$ination of the process (he way that a new process is created is through a techni/ue called *forking* (here is a low level syste$ call na$ed fork. that, when e4ecuted, causes a brand new instance of the original process to be created (he new instance shares everything fro$ the first one including open files, variable values, environ$ent variables & everything (he difference between the$ is that the return code fro$ fork. call for the original process is the process id for the new process while the new process receives a value of 0 In the new forked Page 1
process, it is then very co$$on for a second syste$ call to be $ade called exec. !hat this does is load a new e4ecutable into the address space of the e4isting process 8the forked copy9 and begin its e4ecution If this feels a trifle convoluted, I can't argue with that & however it does provide a $echanis$ for a newly started process to inherit the environ$ent of the starter which can include aspects such as current userid, group $e$bership, open files and $ore #nd that is a desirable situation !hen we run a new shell co$$and, that also causes a new process to run (he shell starts the process and then waits for it to co$plete If we don't wish to wait, we can run it in the background by adding an ** to the end of the co$$and For e4a$ple, running$ gea&, m,file5c
causes the geany editor to open.create a file and i$$ediately detaches it fro$ the starting ter$inal allowing us to run additional co$$ands in that ter$inal Fro$ within a progra$, we can also start another process by using the s,stem. call (his takes the file syste$ path of an e4ecutable and starts it while waiting for it to co$plete (his is a /uick way of perfor$ing work by letting sub)progra$s do co$ple4 6obs for us For e4a$ple, should we wish to play a sound, we can call apla,. to play the sound through the s,stem. call ee also•
$an819 L ps
!ernel mode 's User mode (he :inu4 operating syste$ is designed to support both $ultiple users and $ultiple processes si$ultaneously ne of the i$plications of this is that a badly written or $alfunctioning application should not be able to negatively i$pact the activities of either other users or other processes (he way this is achieved is through the separation of kernel level functions and user code level functions ach process runs in its own address space with isolation fro$ each of the others (his $eans that it is difficult for one application to da$age the $e$ory of another However, I. operations are co$$on between applications Most have to read and write fro$ files for e4a$ple o$ewhere in the operating syste$ there has to be code that interacts at a low level with the disks If the disks could be accessed fro$ user application code, then that could da$age the$ or co$pro$ise security #s such, access to I. is considered a privileged operation and should only be perfor$ed by trusted code #nd this is where the 5ernel co$es into play ode running on a :inu4 $achine can *run within the 5ernel* (his $eans that it is trusted code that runs with the $ost privileges It also has full access to all the internal data structures that are used to $aintain the operating syste$ as a whole 5ernel code can also run at higher level priorities than other code In nor$al HIP progra$$ing, you will be unlikely to be writing any new code that will be e4ecuting within the 5ernel however you will be leveraging $any functions that interface with HIP hardware and access to these will be through HIP specific 5ernel $odules that have been supplied Page 2
"oot pri'ileges and running applications :inu4 is a $ulti)user operating syste$ (his $eans that $ultiple distinct users can si$ultaneously login to a single syste$ and run applications concurrently with each other It is not desirable for one user to be able to read the files fro$ another and hence there are per$ission capabilities associated with each individual user However, there is a special user in a :inu4 syste$ that is called *root* (his user is also know as the *superuser* "oot is not constrained by nor$al security constraints "oot can ter$inate any process and read.write to any file #s such, root is nor$ally given only to the $ost trusted syste$ ad$inistrators and ordinary users run with their ordinary userids However, on the HIP, there are ti$es when we wish to access hardware or run powerful co$$ands 8anything that affects the syste$ as a whole is usually considered to be under this category9 # special co$$and is supplied called *sudo* that takes as a para$eter another co$$and to run (hat second co$$and is then e4ecuted with root per$issions ffectively, it escalates the privileges of the co$$and to root 6ust for the duration of that process # /uestion that arises fro$ ti$e to ti$e is that we know that the default userid is * cip* with a password of *cip*, what then is the default password for * root* (he answer is that there is none and by that we $ean that login as root is disabled If you want to beco$e root, then run$ sudo -i
n occasion there is discussion in the foru$s on the correctness of having to run so$e user written HIP applications as root n a production, $ulti)user operating syste$, I wouldn't /uestion that notion but I $aintain that the HIP is not that ince I can't i$agine a HIP user not knowing the root password or being allowed to run sudo, the HIP is already co$pro$ised fro$ a $ulti)user perspective Fro$ a syste$ stability point of view, any progra$ that runs as root can potentially destroy the syste$ #s such, take back)ups of your Page /
syste$ as needed so that you have a restore point In $y e4perience, I have yet to $ake such a serious accidental error that $y syste$ has been destroyed (he sudo co$$and is governed by a * etcsudoers* file which lists the users that are authori%ed to elevate their per$issions via sudo (o add a user to the set of sudo authori%ed users, we can runadduser user&ameJ sudo
(his will add the user to the * sudo* group and $e$bers of that group are authori%ed to run sudo #fter the change, the user $ust logout and log back in again for the change to take effect ee also•
ecurity and userids
*emory management In a :inu4 environ$ent, each application sees its own address as a virtual address space (hey believe that they are alone in $e$ory and the operating syste$ takes care of $apping the application addresses to the real $e$ory addresses ince HIP has a 21M+ytes of "#M, this would see$ to i$ply that the $a4i$u$ nu$ber of progra$s that HIP can run is constrained (he operating syste$ and related co$ponents use so$e "#M and then there is the cost for running each of your own applications in parallel In $ost :inu4 syste$s, there is the concept of swap space on disk !hat that $eans is that should we start to run low on available "#M, applications that haven't touched $e$ory in a while can have so$e or all of their allocationw written to disk (his is called paging (he data that was in "#M isn't lost its safely stored on disk and hence can be recovered however the space used by what is now on disk is available for re)use hould the original application need the $e$ory again, the operating syste$ will re)load the $e$ory, swapping it out with so$e other progra$s allocation if needed ow we need to re$e$ber that there isn't actually a disk on HIP, instead we have flash $e$ory !hile in principle, we could swap $e$ory to flash, that is a really bad practice !hen the operating syste$ is perfor$ing swap operations, it is potentially reading and writing lots and lots data !hile flash is great, it does *wear* and the a$ount of data being $oved for swapping would 6ust cause it to wear that $uch faster (o list the processes sorted by their $e$ory usage, we can use$ ps aux% sort9-/sC
or $ ps aux% sort9-mem
ee also•
Page
Me$ory 7tili%ation
The sysfs file system In the :inu4 world, a guiding principle is that everything can be considered a file on the file syste$ If we look in the de/ directory we will see entries for ter$inals, serial ports, printers and video input devices Most of these have physical counterparts and access is /uite si$ple we read and write and are done +ut what of $ore subtle interactions such as I, P!M, or API :inu4 has added a concept that is a virtual file syste$ called *sysfs* (his file syste$ is i$ple$ented in the kernel and provides a bridge fro$ user applications 8applications that run in *user space*9 to the drivers in the kernel for the co$ponents in /uestion n HIP, the file syste$ is auto$atically $ounted at s,s #t the highest level we haves,s |-|-|-|-|-|-|-|-|-Q--
block bus class de/ de/ices firm%are fs ker&el module po%er
(he structure is not arbitrary and the locations and na$es of the files and directories have $eanings
•
block L ntries for block oriented devices
•
bus L ntries for data buses (his includes I and PI For each entry in bus, that directory itself contains two directories called * de/ices* and *dri/ers*◦ de/ices L #n entry for each device connected to that bus ◦ dri/ers L Erivers associated with the bus
•
class L ntries for devices by class
•
de/ices L ntries for each known device
ee also•
!ikipedia L sysfs
•
(he sysfs Filesyste$
•
API on HIP
+pen file descriptors #l$ost everything in :inu4 is based around the notion of a file !hether that files is a real file Page $
on the file syste$ or a si$ply a file descriptor of an opened physical device, fro$ the "aspbian process perspective, it is a file descriptor ince these are owned and $anaged by the kernel itself, there is the possibility of using a tool to show us what file descriptors a process has open or, conversely, look at a device or file and ask what processes have it open (he tool in /uestion is called * lsof* It is not installed by default so it $ust be $anually installed fro$ the * lsof* package$ sudo apt-get i&stall lsof
(his co$$and has a deep richness of options and great study of the $an page would be needed to understand all the possibilities However, there are so$e co$$on recipes that one can use without knowing too $uch additional details Here is a recipe that shows which processes have a particular file open $ sudo lsof :D+>? P=? agett, H34 agett, H34 agett, H34
(his co$$and is particularly useful is you are writing server applications and so$e other process already has the port you want to listen upon open Nou can use *lsof* to deter$ine which process that $ight be (o filter the results we can use the * -ifilter specJ* where the filter specification isS4HTSprotocolTSVost&ame|V=P +ddressTSser/ice|portT
•
4H L ither C for (P.IP vC or @ for (P.IP v@
•
Vost&ame L (he hostna$e of the partner
•
V=P +ddress L (he IP address of the partner
•
ser/ice L (he (P.IP service na$e
•
port L (he (P.IP port nu$ber
For e4a$ple, to see what processes are using the web server port$ lsof -iG0 :D+>? P=? 8)E( apace2 H41 root apace2 342H %%%-data apace2 3426 %%%-data
%ystem applications !hen :inu4 starts, it needs to know which services it needs to also start 4a$ples of Page <
services would be de$ons such as web servers, F servers and $ore (he package called s,stemd provides $anage$ent of such re/uests (o see the list of units defined we can run$ s,stemctl list-u&its
(his not only shows the defined units but their status (he colu$ns shown include-
•
7I( L (he na$e of the unit
•
:#E
• #(ID •
7+
•
E"IP(I L # description of the unit
!e can /ualify the list-u&its co$$and with a --t,pe9t,peJ flag to filter on 6ust specific types of units For e4a$ple$ s,stemctl list-u&its --t,pe9ser/ice
:ists all the units that are services If we want to see a graph of the units that are enabled we can run$ s,stemctl status
(o see the status of a specific service we can add the service na$e$ s,stemctl status ser/ice &ameJ
(his last co$$and will also show the script used to start the service (o start a service we can run$ sudo s,stemctl start ser/ice &ameJ
(o stop a service we can run$ sudo s,stemctl stop ser/ice &ameJ
and to restart a service we can run$ sudo s,stemctl restart ser/ice &ameJ
o$e services allow us to reload their configurations with$ sudo s,stemctl reload ser/ice &ameJ
(he details of what a particular unit is going to do when started or stopped can be found by running$ s,stemctl cat ser/ice &ameJ
(his will log the content of the unit configuration file ee also•
syste$d yste$ and ervice Manager
•
yste$d ssentials- !orking with ervices, 7nits, and the ?ournal
Page 9
•
7nderstanding and 7sing yste$d
•
Nou(ube- (utorial L syste$d +asics
riting your own units ince s,stemd runs against units and we can write our own units to control our own applications, let us start on that 6ourney (he core locations for units are etcs,temds,stem and usrlibs,stemds,stem
:et us take apart an e4isting unit so that we $ay see what it looks like !ithin etcs,stemds,stem we will find a file called * ssd5ser/ice* If we look within we will find the followingS8&itT ?escriptio&9Dpe&B)? )ecure )ell ser/er +fter9&et%ork5target auditd5ser/ice :o&ditio&PatExists9Ketcssssd7&ot7to7be7ru& S)er/iceT E&/iro&me&tile9-etcdefaultss Exec)tart9usrsbi&ssd -? $));?7DP*) Exec(eload9bi&kill -;8P $+=>P=? Nillode9process (estart9o&-failure S=&stallT 'a&tedB,9multi-user5target +lias9ssd5ser/ice
#t a high level, a configuration file is co$posed of a series of sections with the section na$e in s/uare brackets Following those are a series of &ame9/alue properties for the corresponding section #$ongst the sections we have-
•
O7nit
•
Oervice
•
OInstall
For the S8&itT section we will invariably wish to include a Eescription line that provides an nglish description of what the unit $eans For e4a$pleS8&itT ?escriptio&9, ser/ice tat does @LO
In the S)er/iceT section, here we describe how to start a particular service (here are $any possible options here and we will touch on 6ust a few (he first is the *,pe line (his describes how the service will be started (he value of simple $eans that s,stemd will si$ply fork. and exec. the service (his is co$$only 6ust what we want # value of forki&g $eans that again s,stemd will fork. and exec. the service but that service will itself fork. and exec. other instances e4t we have the Exec)tart line (his is Page $0
vital (his specifies the path and para$eters that will be used to start the service (he 'orki&g?irector, line 8if present9 specifies the directory that will be the working directory for the newly started service (he 8ser line is used to na$e a local :inu4 user that the service will run as #fter having edited a unit file, we $ust run s,stemctl daemo&-reload to cause s,stemd to re)scan its configuration files and unit files $ sudo s,stemctl daemo&-reload
For e4a$ple if we create etcs,stemds,stemtest)er/ice5ser/ice containingS)er/iceT *,pe9simple 8ser9pi 'orki&g?irector,9omepisrcproIectstest)er/ice Exec)tart9usrlocalbi&&ode test)er/ice5Is
ow when we wish to start the service, we can issue$ sudo s,stemctl start test)er/ice
!hich will cause the service to be started Hopefully now you $ay get an RahaS $o$ent !hat this $eans is that for each service defined, we as ad$inistrators of our HIP :inu4 no longer have to re$e$ber $echanics of how to start dae$ons #ll we need to know is their logical service na$e and issue a start co$$and +ut what if we want to stop a service i$ply issuing$ sudo s,stemctl stop test)er/ice
will stop it +y default, the way that s,stemd perfor$s that task is to e4ecute a kill against the previously re$e$bered process id of the start re/uest If we have an alternate shutdown procedure, we can define another state$ent in our S)er/iceT section called Exec)top (his co$$and should stop the previously started service in whatever clean $anner is possible # special variable called $+=>P=? is $ade available to the co$$and which is the process Id of the previously started service !e have now touched upon what it takes to start and stop a service $anually, but what if we want the service to start auto$atically !e can again do this with s,stemd but it takes a little $ore consideration (he first thing to reali%e is that services typically depend on each other For e4a$ple, there is no point in starting the e)$ail processing service until and unless the network services have already been started !e can define relationships between units with additional state$ents in the S8&itT section (he first one we will touch upon is the (eUuires state$ent (his na$es additional units which should also be started when the current unit is started !e also have the state$ents Before and +fter (hese define the relative order in which $ultiple 7nits should be started For e4a$ple if we haveS8&itT (eUuires9x,C5ser/ice +fter9x,C5ser/ice
then we have declared that when this current unit is started we had better also start the x,C5ser/ice but it $ust be started after x,C5ser/ice has in fact started Page $1
For e4a$ple, if we wish our service to start but only after we have networking available, we $ight codeS8&itT +fter9&et%ork-o&li&e5target
(here are other state$ents that are si$ilar to (eUuires but with slightly altered se$antics (eUuires states that if a dependent unit fails to start then so do we (he 'a&ts state$ent again lists units to be started but should they fail, then our unit will still be allowed to start If we wish to auto$ate the start)up of a service, in the 7nit file for that service we should add an S=&stallT section (his will include a * 'a&tedB,* entry which will list the unit that, if it is started will also start our new unit # good e4a$ple would be * multi-user5target* For e4a$ple, S=&stallT 'a&tedB,9multi-user5target
ee also•
$an L syste$dservice
&he systemd-ui # graphical user interface is available for s,stemd operations It can be installed fro$ the s,stemd-ui package using$ sudo apt-get i&stall s,stemd-ui
(he launcher co$$and is$ sudo -E s,stemadm
Page $2
%torage Nour HIP uses flash $e$ory for storing data (he HIP has a CA+yte flash chip built in (his storage holds the operating syste$, your installed applications and data that your applications need ow CA+ytes see$s like a lot but co$pared to a P which $ight have hundreds of A+ytes 8or even a terabyte or $ore9, it isn't huge However it is $ore than sufficient for the $a6ority of tasks we will need to perfor$ +efore you start working on your HIP and creating new files, so$e words of caution and so$e suggestions ince the HIP storage is physically wired flash $e$ory as opposed to a re$ovable storage $ediu$ such as $icro E $e$ory cards, if your HIP device beco$es da$aged or broken, you $ay never be able to retrieve your data fro$ the device (hink about that for a $o$ent I$agine you have spent weeks or $onths writing an application to run on HIP and the source code to your app resides on the file syste$ contained in the flash $e$ory of the HIP ow you find that your HIP no longer boots and a sinking feeling co$es over you bviously, good practice is to take backups regularly however, few of us do $ake those backups as often as we should If we weren't using HIP but using a single board co$puter with re$ovable storage 8eg a "aspberry PI9, we could also get ourselves a new device and re$ove the storage fro$ the now defunct syste$ and place it in the new syste$ and we are back up and running !e can't do that with HIP I do a lot of progra$$ing and if I were to lose $y data I'd be very unhappy !hat I do instead is have e4ternal network attached storage that can be network *$ounted* onto $y HIP (his could be an F e4port fro$ a :inu4 based P or an e4port fro$ a dedicated network back) up syste$ such as the !estern Eigital *My loud* devices (hese can be plugged into your :# without a dedicated P and e4pose a few gigabytes of shared storage (o deter$ine how $uch space is available, run the co$$and * df -k*$ df -k iles,stem ubi0rootfs de/tmpfs tmpfs tmpfs tmpfs tmpfs tmpfs
(he result shows the different file syste$s using the storage and how $uch is used and re$ains (he file syste$ of $ost interest to us is the one $ounted at *.* which is called *ubi0rootfs* If we look at this e4a$ple output, we see that its si%e is 3===1C 15 blocks (hinking in ter$s of 15 blocks isn't that useful and fortunately there are other flags For e4a$ple$ df -kB iles,stem ubi0rootfs Page $/