Sistemi ad agenti Principi di programmazione di sistema
Transcript
Sistemi ad agenti Principi di programmazione di sistema
Sistemi ad agenti Principi di programmazione di sistema Vittoria Cozza Modulo 6 Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema Why would anyone want to hack or write opensource project for embedded system, when you already have a very powerful and relatively cheap PC? lower power much more quiet fast boot sometimes more convenient to run certain applications on these systems and not on a PC Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema FOX Board LX 100MIPS, 1 Watt, Linux embedded board runs a real Linux operating system in just 66 x 72 mm (2.6 x 2.8 inches). The main field applications are: Stand alone micro web servers Macro component for OEM projects to reduce the design time to build internet ready embedded devices. Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema ST Microelectronics STB7109 Set-top-box (STB) decoder chip designed for low-cost high-definition (HD) applications. It is based on 300MHz SH4-202 (ST40-202) CPU core with integrated MPEG video decoder, audio decoder, Ethernet, SATA and USB 2.0 host controller. STB7109E-REF (mb448) reference board also includes 2x64MB DDR1 RAM (one DDR bank is used by the decoder and another by the OS), 8MB flash and various video output interfaces, including HDMI. Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema Realtek 8186 The RTL8186/RTL8186P is a highly integrated System-on-a-Chip with a high-performance 32-bit RISC micro-controller, two Ethernet MACs, and a WLAN controller embedded onto a single chip with a space-saving total package size of 17mm x 17mm. It is a cost-effective solution for wireless LAN access points, wireless SOHO routers, wireless multimedia appliance, etc. Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema Software Software stack typically consists of ”standard” embedded Linux (such as Das U-Boot) or vendor proprietary bootloader Linux kernel (uClinux in case of MMU-less processors) uClibc library (as glibc memory requirements are not suited for embedded systems) busybox a set of specific drivers and applications (es. mplayer, iptables, ssh, gps drivers). Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema Software cnt Poky Linux http://www.pokylinux.org/ sdk Realtek scratchbox http://www.scratchbox.org/ buildroot http://buildroot.uclibc.org/ Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema Embedded web servers In the case of routers, access point and so on, the user interact with the embedded system by a web server. Popular embedded web server are Boa http://www.boa.org/ Goahead http://www.goahead.com/products/webserver/default.aspx microhttpd http://www.acme.com/software/micro httpd/ Embedded web server features are: Small memory footprint Strong support for dynamic generation of Web pages Easy device integration Support for devices without a file system Portable to new platforms and CPU architectures Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema Getting the shell prompt The way is by serial port RS232 so you can: to see all kinds of error messages, including kernel panic to interact with the bootloader, which in some cases may be the only way to program a new firmware image to flash. Most embedded systems have UART controllers used for debug and development. UART pins are connected to a RS-232 interface through a voltage level converter chip, which will translate logic UART levels to the external RS-232 levels: MAXIM (http://www.maxim-ic.com) MAX232. Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema Getting the shell prompt: Minicom On Windows: start> programmi > comunicazioni > > accessori >HyperTerminal Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema Trivial File Transfer Protocol Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema Escape sequences to change cursor position \033[<L>;<C>H to line L and column C \033[<N>A down N lines \033[<N>B up N lines \033[<N>C forward N columns \033[<N>D backward N columns \033[s save position \033[u resume position Example: echo -en "\033[9A" Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema Shell command to analyze source code and crosscompiler look at 081007-devel.pdf http://www.gnudd.com/pub/srt-2008/ Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema Example: crosscompiling dropbear wget http://matt.ucc.asn.au/dropbear/ /releases/dropbear-0.51.tar.bz2 tar xjf dropbear-0.51.tar.bz2 export USING_CROSS_COMPILER=y export CROSS_COMPILER_PREFIX="mips-uclibc-" export CC=mips-linux-uclibc-gcc-3.3.3 export STRIP=mips-linux-uclibc-strip #use the following if you want statically compile #export CFLAGS="-Os -static -Wall" #export LDFLAGS="-static" Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema Example: crosscompiling dropbear CNT ./configure CC=mips-linux-uclibc-gcc-3.3.3 --host=mips-linux-uclibc --build=i686-linux CFLAGS=-O2 --disable-zlib --disable-lastlog --disable-largefile make programs="dropbear dbclient dropbearkey dropbearconvert scp" strip MULTI=1; We have an unique binary a la busybox: -rwxr-xr-x 1 root root 265K Dec 4 23:06 dropbearmulti Project page: http://matt.ucc.asn.au/dropbear/dropbear.html Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema Example: adding dropbear in the file system cd $RAMFSDIR/dev/ ln -s urandom $RAMFSDIR/dev/random mkdir -p $RAMFSDIR/etc/dropbear cd ../../ cp ./dropbear-0.51/dropbearmulti $RAMFSDIR/sbin/dropbearmulti touch $RAMFSDIR/var/log/lastlog touch $RAMFSDIR/var/log/wtmp cd $RAMFSDIR/sbin ln -s dropbearmulti $RAMFSDIR/sbin/dropbear ln -s dropbearmulti $RAMFSDIR/sbin/scp ln -s dropbearmulti $RAMFSDIR/sbin/dropbearkey ln -s dropbearmulti $RAMFSDIR/sbin/dropbearconvert ln -s dropbearmulti $RAMFSDIR/sbin/dbclient ln -s dropbearmulti $RAMFSDIR/sbin/ssh Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema Example: adding dropbear in the file system CNT mips-linux-ldd dropbearmulti libutil.so.0 => mips-linux-uclibc/lib/libutil.so.0 (0x00000000) libcrypt.so.0 =>mips-linux-uclibc/lib/libcrypt.so.0 (0x00000000) libc.so.0 => mips-linux-uclibc/lib/libc.so.0 (0x00000000) /lib/ld-uClibc.so.0 => /lib/ld-uClibc.so.0 (0x00000000) In the target file system: cp $UCLIBCDIR/libcrypt-0.9.26.so $RAMFSDIR/lib/libcrypt.so.0 cp $UCLIBCDIR/libutil-0.9.26.so $RAMFSDIR/lib/libutil.so.0 Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema Example: starting ssh /sbin/dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key /sbin/dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key OPTIONS="> /dev/null 2>&1" echo "Stopping dropbear..." pid=‘pidof dropbear‘ if [ "$pid" != "" ]; then kill $pid fi echo "Starting dropbear..." /sbin/dropbear $OPTIONS Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema Example: testing ssh On the WRT54G: cat proc/net/tcp DEMO Vittoria Cozza Sistemi ad agenti Principi di programmazione di sistema