1. OpenWrt from scratch
Installare OpenWrt
Espandere OpenWrt
Ricompilare OpenWrt da zero
Applicazioni con OpenWrt
Autore: Claudio Mignanti c.mignanti<at>gmail.com
2. 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
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
3
4. Copiare il filesystem
Attualmente:
wget http://downloads.openwrt.org/snapshots/trunk/at91/openwrt-at91-uImage
wget http://downloads.openwrt.org/snapshots/trunk/at91/openwrt-at91-rootfs.tar.gz
mv 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.gz
sudo tar xvzf openwrt-at91-rootfs.tar.gz -C /media/<ext2>
umount /media/<ext2>
4
6. Opkg
opkg update – aggiorna i pacchetti dai repository definiti in
/etc/opkg.conf
opkg list – visualizza la lista dei pacchetti installabili
opkg install <nome|link|file>
opkg install pyserial ← Installa dal feed
opkg 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 !!!
6
7. root@OpenWrt:~# opkg update Opkg
Downloading 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/opkglists/snapshots.
root@OpenWrt:~# opkg install python
Installing python (2.6.43) to root...
Downloading http://downloads.openwrt.org/snapshots/trunk/at91/packages/python_2.6.4
3_at91.ipk.
Installing libpthread (0.9.30.150) to root...
Downloading
http://downloads.openwrt.org/snapshots/trunk/at91/packages/libpthread_0.9.30.1
50_at91.ipk.
Installing librt (0.9.30.150) to root...
Downloading http://downloads.openwrt.org/snapshots/trunk/at91/packages/librt_0.9.30.1
50_at91.ipk.
Installing zlib (1.2.35) to root...
Downloading http://downloads.openwrt.org/snapshots/trunk/at91/packages/zlib_1.2.3
5_at91.ipk.
Installing libffi (3.0.91) to root...
Downloading http://downloads.openwrt.org/snapshots/trunk/at91/packages/libffi_3.0.9
1_at91.ipk.
Installing pythonmini (2.6.43) to root...
Downloading http://downloads.openwrt.org/snapshots/trunk/at91/packages/pythonmini_2.6.4
3_at91.ipk.
Configuring librt.
Configuring libpthread.
Configuring zlib.
Configuring libffi.
Configuring pythonmini.
7
Configuring python.
root@OpenWrt:~#
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
9
10. SDK Intro
svn 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'SDK
Aggiungi/modifica feed in feeds.conf
./scripts/feeds install -a
./scripts/feeds update -a
10
11. Compilare
make
compila l'intero firmware
make clean
ripulisci 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>
11
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 sorgente
Compile (no comment)
Install (del pacchetto)
Si realizza il pacchetto ipkg
12
13. Compilare 3
Esempi:
https://dev.openwrt.org/browser/packages/admin/sudo
Download sorgenti dal web, configurazione, install
https://dev.openwrt.org/browser/trunk/package/opkg/Makefile
Download sorgenti dal web, configurazione, install e installdev
http://sourceforge.net/apps/trac/acme-dev/browser/packages/zz-acmeconf
Meta-pacchetto, notare le dipendenze
http://sourceforge.net/apps/trac/acme-dev/browser/packages/at91-adc/Makefile
Kernel module
13
14. Kernel
Il punto forte di OpenWrt è senza dubbio la
gestione del kernel.
https://dev.openwrt.org/browser/trunk/target/linux
14
15. Modificare il kernel
make target/linux/clean
modificare target/linux/generic/{patches|files}
o target/linux/at91/{patches|files}
make target/linux/install
Esempio: https://dev.openwrt.org/changeset/21800
15
17. GPIO usando il C
#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);
}
17
trunk/target/linux/generic/files/include/linux/gpi_dev.h
18. GPIO e stepper motor
PYTHON CLASS USER SPACE
STEPPER PROGRAM
/DEV/GPIO SYSFS /DEV/MOTORn
STEPPER DRIVER
GPIO API
PWM
CPU
18
http://sourceforge.net/apps/trac/acme-dev/browser/kernel-stuff/stepper-driver/stepper-drv.c
19. Seguite lo sviluppo su
http://sourceforge.net/apps/trac/acme-dev/timelin
https://dev.openwrt.org/search?q=claudio
19