TuxIsAlive

20
OpenWrt from scratch Installare OpenWrt Espandere OpenWrt Ricompilare OpenWrt da zero Applicazioni con OpenWrt Autore: Claudio Mignanti c.mignanti<at>gmail.com

description

TuxIsAlive was a workshop presented at AcmeSystems that introduce the use of OpenWrt on Acme devices.

Transcript of TuxIsAlive

Page 1: TuxIsAlive

OpenWrt from scratch

Installare OpenWrtEspandere OpenWrt

Ricompilare OpenWrt da zeroApplicazioni con OpenWrt

Autore: Claudio Mignanti c.mignanti<at>gmail.com

Page 2: TuxIsAlive

Perche OpenWrt

● Sistema integrato di sviluppo● Distribuzione pensata per dispositivi embedded (nasce per i router)● Boot in meno di 10 secondi● Utilizzo ottimizzato elle risorse● uClibc/glibc/eglibc

Page 3: TuxIsAlive

3

Partizionare la SDCard

● Aprire Gparted; Sistema → Amministrazione → Gparted

● Selezionare la periferica;

● Aggiungere le due partizioni. La prima FAT32 (anche con pochi MB) la seconda EXT2

Page 4: TuxIsAlive

4

Copiare il filesystem

Attualmente:wget http://downloads.openwrt.org/snapshots/trunk/at91/openwrt-at91-uImagewget http://downloads.openwrt.org/snapshots/trunk/at91/openwrt-at91-rootfs.tar.gzmv openwrt-at91-uImage /media/<fat32>/sudo tar xvzf openwrt-at91-rootfs.tar.gz -C /media/<ext2>umount /media/<fat32>umount /media/<ext2>

In futuro probabilmente:wget http://downloads.openwrt.org/snapshots/trunk/at91/openwrt-at91-rootfs.tar.gzsudo tar xvzf openwrt-at91-rootfs.tar.gz -C /media/<ext2>umount /media/<ext2>

Page 5: TuxIsAlive

5

Incontro ravvicinato

$ sudo ifconfig eth0 192.168.1.2 && telnet 192.168.1.1

BusyBox v1.16.2 (2010­07­15 14:32:26 CEST) built­in shell (ash)Enter 'help' for a list of built­in commands.

  _______                     ________        __ |       |.­­­­­.­­­­­.­­­­­.|  |  |  |.­­­­.|  |_ |   ­   ||  _  |  ­__|     ||  |  |  ||   _||   _| |_______||   __|_____|__|__||________||__|  |____|          |__| W I R E L E S S   F R E E D O M KAMIKAZE (bleeding edge, r22176) ­­­­­­­­­­­­­­­­­­  * 10 oz Vodka       Shake well with ice and strain  * 10 oz Triple sec  mixture into 10 shot glasses.  * 10 oz lime juice  Salute! ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­root@OpenWrt:~# 

Il numero di revisione (r22176 nell'esempio) è molto utile per debug!

Page 6: TuxIsAlive

6

Opkg

opkg update – aggiorna i pacchetti dai repository definiti in /etc/opkg.conf

opkg list – visualizza la lista dei pacchetti installabiliopkg install <nome|link|file>

opkg install pyserial ← Installa dal feedopkg install ftp://myurl.it/pkg/python-mini_2.6.4-3_at91.ipk.opkg install /tmp/zlib_1.2.3-5_at91.ipk ← installa file locale

opkg flag hold <nome> - blocca la versione corrente del pacchetto <nome>

opkg upgrade – usate a vostro rischio !!!

Page 7: TuxIsAlive

7

Opkgroot@OpenWrt:~# opkg updateDownloading http://downloads.openwrt.org/snapshots/trunk/at91/packages/Packages.gz.Inflating http://downloads.openwrt.org/snapshots/trunk/at91/packages/Packages.gz.Updated list of available packages in /var/opkg­lists/snapshots.root@OpenWrt:~# opkg install python Installing python (2.6.4­3) to root...Downloading http://downloads.openwrt.org/snapshots/trunk/at91/packages/python_2.6.4­3_at91.ipk.Installing libpthread (0.9.30.1­50) to root...Downloading http://downloads.openwrt.org/snapshots/trunk/at91/packages/libpthread_0.9.30.1­50_at91.ipk.Installing librt (0.9.30.1­50) to root...Downloading http://downloads.openwrt.org/snapshots/trunk/at91/packages/librt_0.9.30.1­50_at91.ipk.Installing zlib (1.2.3­5) to root...Downloading http://downloads.openwrt.org/snapshots/trunk/at91/packages/zlib_1.2.3­5_at91.ipk.Installing libffi (3.0.9­1) to root...Downloading http://downloads.openwrt.org/snapshots/trunk/at91/packages/libffi_3.0.9­1_at91.ipk.Installing python­mini (2.6.4­3) to root...Downloading http://downloads.openwrt.org/snapshots/trunk/at91/packages/python­mini_2.6.4­3_at91.ipk.Configuring librt.Configuring libpthread.Configuring zlib.Configuring libffi.Configuring python­mini.Configuring python.root@OpenWrt:~# 

Page 8: TuxIsAlive

8

Ricominciamo da zero...Sviluppare con OpenWrt

Page 9: TuxIsAlive

9

Scaricare l'SDK

OpenWrt è una distribuzione linux unica nel suo genere.L'SDK è un ambiente di sviluppo nel quale TUTTI i componenti necessari confluiscono per creare l'ambiente finale.

● Host tools● toolchain● kernel linux● rootfs

Page 10: TuxIsAlive

10

SDK Introsvn co svn://svn.openwrt.org/openwrt/trunk openwrt

scarica l'sdk

make menuconfig configura l'sdk

make kernel_menuconfig configura il kernel per l'architettura selezionata

svn up----------------------------------------------------------------------------------- Espandere l'SDKAggiungi/modifica feed in feeds.conf

./scripts/feeds install -a

./scripts/feeds update -a

Page 11: TuxIsAlive

11

Compilare

makecompila l'intero firmware

make cleanripulisci l'sdk (host tools, toolchain, e configurazioni escluse)

make target/linux/{compile|clean}compila/ripulisci il kernel

make <path>/<nome_pkg>/{compile|clean}compila/ripulisci il pacchetto <nome_pkg>

Page 12: TuxIsAlive

12

Compilare 2

Il processo di compilazione dentro openwrt passa per i seguenti stadi:

Prepare (del codice sorgente)1. Download del sorgente dal web (http, ftp, svn, git, hg)2. Si copia il contenuto della directory files all'interno della

directory di compilazione (solo per il kernel)Patch

Si applicano le patch al sorgenteCompile (no comment)Install (del pacchetto)

Si realizza il pacchetto ipkg

Page 13: TuxIsAlive

13

Compilare 3

Esempi:https://dev.openwrt.org/browser/packages/admin/sudo

Download sorgenti dal web, configurazione, installhttps://dev.openwrt.org/browser/trunk/package/opkg/Makefile

Download sorgenti dal web, configurazione, install e installdevhttp://sourceforge.net/apps/trac/acme-dev/browser/packages/zz-acmeconf

Meta-pacchetto, notare le dipendenzehttp://sourceforge.net/apps/trac/acme-dev/browser/packages/at91-adc/Makefile

Kernel module

Page 14: TuxIsAlive

14

Kernel

Il punto forte di OpenWrt è senza dubbio la gestione del kernel.

https://dev.openwrt.org/browser/trunk/target/linux

Page 15: TuxIsAlive

15

Modificare il kernel

make target/linux/cleanmodificare target/linux/generic/{patches|files}o target/linux/at91/{patches|files}make target/linux/install

Esempio: https://dev.openwrt.org/changeset/21800

Page 16: TuxIsAlive

16

GPIO usando SYSFSecho 82 > /sys/class/gpio/exportecho out > /sys/class/gpio/gpio82/direction

echo 1 > /sys/class/gpio/gpio82/valuesleep 1echo 0 > /sys/class/gpio/gpio82/value

Page 17: TuxIsAlive

17

#include <stdio.h>#include <gpio_dev.h>

int main (void) {fd = open (“/dev/gpio”);ioctl (fd, GPIO_REQUEST, 82);ioctl (fd, GPIO_DIR_OUT);ioctl (fd, GPIO_SET, 1);sleep(1);ioctl (fd, GPIO_SET, 0);

}

GPIO usando il C

trunk/target/linux/generic/files/include/linux/gpi_dev.h

Page 18: TuxIsAlive

18

GPIO e stepper motor

CPU

GPIO APISTEPPER DRIVER

PYTHON CLASS STEPPER

USER SPACE PROGRAM

/DEV/GPIO SYSFS

PWM

/DEV/MOTORn

http://sourceforge.net/apps/trac/acme-dev/browser/kernel-stuff/stepper-driver/stepper-drv.c

Page 19: TuxIsAlive

19

Seguite lo sviluppo su

http://sourceforge.net/apps/trac/acme-dev/timeline

https://dev.openwrt.org/search?q=claudio

Page 20: TuxIsAlive

20

EOF

Claudio Mignanti c.mignanti<at>gmail.com- OpenWrt Developer - Hardware designer -

pub 1024D/0DFD7CBB C94D 759A 2EF0 172F 9673 65E4 C4C1 8627 0DFD 7CBB

?