<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ldlabs.org - Blog</title>
	<atom:link href="http://www.ldlabs.org/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ldlabs.org/blog</link>
	<description>Linux Tips &#38; c.</description>
	<lastBuildDate>Sun, 22 Apr 2012 08:19:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Read and write RAM physical addresses by Linux user space</title>
		<link>http://www.ldlabs.org/blog/2012/04/22/read-and-write-a-ram-physical-address-in-linux/</link>
		<comments>http://www.ldlabs.org/blog/2012/04/22/read-and-write-a-ram-physical-address-in-linux/#comments</comments>
		<pubDate>Sun, 22 Apr 2012 07:42:46 +0000</pubDate>
		<dc:creator>Francesco Apollonio</dc:creator>
				<category><![CDATA[ARM]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[code tips]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mmap]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[qemu]]></category>
		<category><![CDATA[syscall]]></category>

		<guid isPermaLink="false">http://www.ldlabs.org/blog/?p=946</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
Ok, this is another trick I learned working on my project. I&#8217;ve a QEMU arm machine and a simulation outside them. QEMU shares his RAM (in the future I&#8217;ll write about this) with the simulator so I want to unlock the simulation (that is waiting for a 1 at the address 0x0FF8000) writing the specified [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
<p>Ok, this is another trick I learned working on my project.</p>
<p>I&#8217;ve a <strong>QEMU</strong> arm machine and a <strong>simulation</strong> outside them. QEMU shares his RAM (in the future I&#8217;ll write about this) with the simulator so I want to unlock the simulation (that is waiting for a 1 at the address 0x0FF8000) writing the specified value on that address using an application in user space inside the VM.</p>
<p><span id="more-946"></span></p>
<p>Ok I&#8217;ve found <a href="http://designsomething.org/leopardboard/f/23/t/77.aspx" target="_blank">here</a> a source code that do exactly this operation.</p>
<p>It uses the device <em>/dev/mem</em>. It is a special file ﻿that provides access to the physical memory of the computer.</p>
<pre>if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) FATAL;</pre>
<p>It opens <em>/dev/mem</em> in RW.</p>
<pre>map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target &amp; ~MAP_MASK);</pre>
<p>This is the key line of the program. The function mmap maps something in the virtual address space of the process who call them. To map the content of a file, <strong>mmap</strong> starts to read from the <em>offset</em> parameter (the last one) to the <em>length</em> parameter (the second one). <em>MAP_SIZE</em> is 4096 (the size of a memory page), the <em>offset</em> must be ﻿multiple of the page size, so<em> target &amp; ~MAP_MASK</em> calculates what is the nearest multiple for our address.</p>
<pre>virt_addr = map_base + (target &amp; MAP_MASK);</pre>
<p>Now we can add, to the <em>map_base</em> address returned by mmap, the offset deleted before when calculating the multiple of the page size, now we have a physical address that is mapped in a virtual address, and we can write or read directly from it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ldlabs.org/blog/2012/04/22/read-and-write-a-ram-physical-address-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ library in a C application</title>
		<link>http://www.ldlabs.org/blog/2012/04/10/c-library-in-a-c-application/</link>
		<comments>http://www.ldlabs.org/blog/2012/04/10/c-library-in-a-c-application/#comments</comments>
		<pubDate>Tue, 10 Apr 2012 07:21:36 +0000</pubDate>
		<dc:creator>Francesco Apollonio</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[code tips]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[linker]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[makefile]]></category>
		<category><![CDATA[qemu]]></category>
		<category><![CDATA[systemc]]></category>
		<category><![CDATA[varie]]></category>

		<guid isPermaLink="false">http://www.ldlabs.org/blog/?p=942</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
This is the second part of the integration of a SystemC module into Qemu. SystemC is C++ so I&#8217;ve had lots of problems trying to link my library (that is a multiprocessor simulator written in SystemC) with Qemu, because this is written in pure C. The first rule that you have to remember when you [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
<p>This is the second part of the integration of a SystemC module into Qemu. SystemC is <strong>C++</strong> so I&#8217;ve had lots of problems trying to link my library (that is a multiprocessor simulator written in SystemC) with Qemu, because this is written in pure <strong>C</strong>.<span id="more-942"></span></p>
<p>The <strong>first rule</strong> that you have to remember when you want to link a C++ library with a C application is to wrap the functions that you want to export with the construct &#8220;<em>extern C</em>&#8221; . This tells to the C++ compiler to use the standard C name mangling for a function or a group of functions. You can use it in the following way:</p>
<pre>extern "C" void function1(int a);
void function1(int a) { /* my function code */ }</pre>
<p>In this example <em>function1</em> can be used in a C application even if it is C++ code. Note that the object for this file must be created using a C++ compiler.</p>
<p>After you can use function1 in any functions written in C (remember to create and to include an header or to use &#8220;extern void function1&#8243; in your C code).</p>
<p>The<strong> last important rule</strong> is to create the binary linking all different object files using a C++ linker.</p>
<p>In my project I&#8217;ve added another C++ file in Qemu with something like the function1 explained before, and I&#8217;ve to edit Qemu&#8217;s Makefile to compile the new C++ file and create the final executable using C++ linker and not a C one.</p>
<p>Now I can use my C++ code in a C application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ldlabs.org/blog/2012/04/10/c-library-in-a-c-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QEMU and SystemC &#8211; Resolve linking problems with gcc (ld)</title>
		<link>http://www.ldlabs.org/blog/2012/04/08/resolve-linking-problem-gcc/</link>
		<comments>http://www.ldlabs.org/blog/2012/04/08/resolve-linking-problem-gcc/#comments</comments>
		<pubDate>Sun, 08 Apr 2012 09:50:19 +0000</pubDate>
		<dc:creator>Francesco Apollonio</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[code tips]]></category>
		<category><![CDATA[en]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[ld]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[makefile]]></category>
		<category><![CDATA[problems]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[qemu]]></category>
		<category><![CDATA[systemc]]></category>

		<guid isPermaLink="false">http://www.ldlabs.org/blog/?p=925</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
I&#8217;m currently working on a university project where I need to merge Qemu and a multi-processor simulator written in SystemC, and I want to share with you all my problems and how I resolved them. First of all, I need to convert the simulator in a library because of I need to create a multi-threaded [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
<p>I&#8217;m currently working on a university project where I need to merge <strong>Qemu </strong>and a multi-processor simulator written in <strong>SystemC</strong>, and I want to share with you all my problems and how I resolved them.<span id="more-925"></span></p>
<p>First of all, I need to convert the simulator in a library because of I need to create a multi-threaded application to execute Qemu on a thread and the simulator on another. To do it I modified SystemC <em>sc_main.cpp</em> changing the name of the <em>main</em> function in <em>init_systemc_main</em> and recompiling the library.</p>
<p>After I got a lot of linking problem because there is a <em>circular dependence</em> between the simulator and SystemC. The solution was to edit the Makefile of the simulator adding to the linker&#8217;s options the &#8220;<em>&#8211;start-group</em>&#8221; and the &#8220;<em>&#8211;end-group</em>&#8221; parameter.<br />
To do that you need to add to the command line the following string:</p>
<pre>-Wl,--start-group systemc.a mylib.a -Wl,--end-group</pre>
<p>The <strong>-Wl</strong> parameter tells to the compiler that the following parameters have to be parsed by the linker. Libraries that are inside the group created by <strong>&#8211;start-group</strong> and <strong>&#8211;end-group</strong> parameters are searched repeatedly until no new undefined references are created. We need to use these parameters because normally a library is searched only once in  the order that it is specified on the command line.<br />
After this, the program has been compiled and I could start to work on Qemu, but I&#8217;ll talk to you of this when I&#8217;ll take some steps forward.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ldlabs.org/blog/2012/04/08/resolve-linking-problem-gcc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New features in Virtualbricks</title>
		<link>http://www.ldlabs.org/blog/2012/04/02/new-features-in-virtualbricks/</link>
		<comments>http://www.ldlabs.org/blog/2012/04/02/new-features-in-virtualbricks/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 20:06:15 +0000</pubDate>
		<dc:creator>Francesco Apollonio</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[KVM]]></category>
		<category><![CDATA[VDE]]></category>
		<category><![CDATA[Virtualbricks]]></category>
		<category><![CDATA[Virtualizzazione]]></category>
		<category><![CDATA[annunci]]></category>
		<category><![CDATA[guida virtualbricks]]></category>
		<category><![CDATA[kvm]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[virtual]]></category>
		<category><![CDATA[virtualbricks]]></category>

		<guid isPermaLink="false">http://www.ldlabs.org/blog/?p=922</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
After an entire day of working, now Virtualbricks is able to manager remote virtual machines. You can configure these machines using a local instance of the software. All the features work on a remote machine except for the interconnections between the bricks. Image disks must be located in the same subdirectory and must have the [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
<p>After an entire day of working, now <a href="http://www.virtualbricks.eu" target="_blank">Virtualbricks</a> is able to manager remote virtual machines.</p>
<p>You can configure these machines using a local instance of the software. All the features work on a remote machine except for the interconnections between the bricks. Image disks must be located in the same subdirectory and must have the same name. For example if we want to use a disk disk1.qcow2 and your image directory is /home/noob/VM, another image file called disk1.qcow2 must be in the /root/VM directory.</p>
<p>We are still working on other new features and, most important, we are working to remote networks configuration.</p>
<p>Download source from <a href="http://launchpad.net/virtualbrick" target="_blank">launchpad</a> and try the software, and please report every bug that you find or additional feature that you want.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ldlabs.org/blog/2012/04/02/new-features-in-virtualbricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebForAll Week-End: Giorno 1</title>
		<link>http://www.ldlabs.org/blog/2012/03/24/webforall-week-end-giorno-1/</link>
		<comments>http://www.ldlabs.org/blog/2012/03/24/webforall-week-end-giorno-1/#comments</comments>
		<pubDate>Sat, 24 Mar 2012 20:25:01 +0000</pubDate>
		<dc:creator>Francesco Apollonio</dc:creator>
				<category><![CDATA[Life]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[annunci]]></category>
		<category><![CDATA[internet]]></category>

		<guid isPermaLink="false">http://www.ldlabs.org/blog/?p=918</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
Oggi è stato il primo giorno del primo WebForAll Week End. WebForAll è una associazione senza fini di lucro per la realizzazione di servizi digitali e web per soggetti non profit che si impegnano nel sociale. Il progetto a cui sono stato assegnato riguardava la realizzazione di un sito web per l&#8217;associazione Borgo Alice. La [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
<p>Oggi è stato il primo giorno del primo <a href="http://webforall-project.it/content/webforall-weekend" target="_blank">WebForAll Week End</a>.</p>
<p><img class="aligncenter colorbox-918" title="WebForAll Logo" src="http://webforall-project.it/sites/default/files/w4all-cube-160px.png" alt="" width="160" height="158" /></p>
<p><a href="http://www.webforall-project.it/" target="_blank">WebForAll</a> è una associazione senza fini di lucro per la realizzazione di servizi digitali e web per soggetti non profit che si impegnano nel sociale.</p>
<p>Il progetto a cui sono stato assegnato riguardava la realizzazione di un sito web per l&#8217;associazione <strong>Borgo Alice</strong>. La cosa più importante della giornata di oggi è stata vedere quanto impegno, quanto lavoro e quante persone sono dentro queste associazioni, che anche se piccole, lavorano pieni di voglia di aiutare, di farsi sentire e di far capire quanto importante sia la propria causa!</p>
<p>Ecco perché è importante questo progetto e perché ho deciso di contribuire!</p>
<p>Vedrete domani quale sarà il risultato di questa fantastica iniziativa!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ldlabs.org/blog/2012/03/24/webforall-week-end-giorno-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creazione di una rete di controllo per macchine virtuali,che permetta di raggiungerle dall&#8217;host con il loro hostname</title>
		<link>http://www.ldlabs.org/blog/2012/01/19/creazione-di-una-rete-di-controllo-per-macchine-virtuali/</link>
		<comments>http://www.ldlabs.org/blog/2012/01/19/creazione-di-una-rete-di-controllo-per-macchine-virtuali/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 23:52:46 +0000</pubDate>
		<dc:creator>Francesco Apollonio</dc:creator>
				<category><![CDATA[Guide]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[KVM]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[VDE]]></category>
		<category><![CDATA[Virtualbricks]]></category>
		<category><![CDATA[Virtualizzazione]]></category>
		<category><![CDATA[code tips]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[guida virtualbricks]]></category>
		<category><![CDATA[kvm]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[utility]]></category>
		<category><![CDATA[varie]]></category>
		<category><![CDATA[vde]]></category>
		<category><![CDATA[virtual]]></category>
		<category><![CDATA[virtualbricks]]></category>

		<guid isPermaLink="false">http://www.ldlabs.org/blog/?p=894</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
Dovendo gestire più di un testbed formato da macchine virtuali di numero, tipologia e topologie diverse, mi sono imbattuto in alcuni problemi. I sistemi che utilizzo sono macchine virtuali KVM e VDE per gestire la rete. Per gestirli ovviamente utilizzo Virtualbricks poiché mi semplifica, e non di poco, la vita. Il problema Il problema che [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
<p>Dovendo gestire più di un testbed formato da macchine virtuali di numero, tipologia e topologie diverse, mi sono imbattuto in alcuni problemi. I sistemi che utilizzo sono macchine virtuali KVM e VDE per gestire la rete. Per gestirli ovviamente utilizzo Virtualbricks poiché mi semplifica, e non di poco, la vita.</p>
<p><strong>Il problema</strong></p>
<p>Il problema che voglio affrontare in questo articolo è un problema di semplificazione all&#8217;accesso da remoto alle varie macchine virtuali, ovvero: come fare ad accedere, utilizzando SSH, alle varie macchine virtuali utilizzando come nome degli host i nomi delle macchine virtuali che ho impostato su Virtualbricks? E soprattutto questo meccanismo può essere automatizzato, in modo che ogni macchina virtuale, appena viene lanciata, istruisca la macchina host su quale è la combinazione hostname &#8211; IP corretta per comunicare con essa?</p>
<p><strong><span id="more-894"></span>Il primo passo: l&#8217;assegnamento degli indirizzi IP</strong></p>
<p>Data la dinamicità della topologia, impostare indirizzi IP statici è di poca utilità, occorre quindi utilizzare un server DHCP per assegnare gli indirizzi, il che vuol dire che i SO delle macchine virtuali devono essere configurati per prendere l&#8217;IP automaticamente via DHCP al boot, e questo è il primo passo.</p>
<p><strong>Secondo passo: il server DHCP</strong></p>
<p>Il secondo passo è l&#8217;installazione del server DHCP sulla macchina host. La scelta è caduta su dnsmasq che, tra le altre cose, permette anche di associare uno script che viene lanciato subito dopo la ricezione di una richiesta DHCP al server, il che ci sarà molto utile più avanti. Per quanto riguarda il file di configurazione, esso sarà molto semplice:</p>
<p>interface=tap0<br />
dhcp-range=10.0.0.100,10.0.0.200,255.255.255.0,12h<br />
dhcp-script=/bin/add_hosts.sh</p>
<p>La prima riga specifica su che interfaccia si vuole restare in ascolto, il perché essa sia &#8220;tap0&#8243; verrà spiegato più avanti. La seconda è il range di indirizzi IP e la netmask che si vuole utilizzare. Infine viene specificato lo script che deve essere lanciato.</p>
<p><strong>Terzo passo: la topologia</strong></p>
<p style="text-align: center;">&nbsp;</p>
<div class="mceTemp mceIEcenter" style="text-align: left;">
<dl id="attachment_898" class="wp-caption aligncenter" style="width: 608px;">
<dt class="wp-caption-dt"><a href="http://www.ldlabs.org/blog/wp-content/uploads/2012/01/topologia.png"><img class="size-full wp-image-898  colorbox-894" title="topologia" src="http://www.ldlabs.org/blog/wp-content/uploads/2012/01/topologia.png" alt="Topologia da realizzare" width="598" height="298" /></a></dt>
<dd class="wp-caption-dd">Topologia da Realizzare</dd>
</dl>
</div>
<p style="text-align: left;">Come indicato dalla figura, la topologia è composta da 5 componenti: tre VM, un VDE Switch e una interfaccia di tap. Quest&#8217;ultima in particolare è una interfaccia di rete simulata che funziona come punto di interconnessione tra la rete virtuale e la macchina host. Utilzzandola e assegnandole un indirizzo IP (come se fosse una normale scheda di rete) la macchina host diverrà parte integrante della rete e sarà connessa direttamente alle macchine virtuali. L&#8217;interfaccia di tap (e di conseguenza la macchina host nella rete) in questo esempio ha indirizzo 10.0.0.1.</p>
<p style="text-align: left;"><strong>Quarto passo: dove salvare le informazioni su come raggiungere le macchine virtuali?</strong></p>
<p style="text-align: left;">Le informazioni che devo salvare sono due: hostname e indirizzo IP. Qual&#8217;è il posto migliore per salvare questo tipo di informazioni, in modo che siano prioritarie rispetto ai DNS? Ovviamente la risposta è il file <em>/etc/hosts</em>.</p>
<p style="text-align: left;"><strong>Quinto passo: che parametri vengono passati allo script dal server DHCP?</strong></p>
<p style="text-align: left;">I parametri che il server DHCP invia allo script che è stato configurato per essere eseguito all&#8217;arrivo di una richiesta sono 4: il comando (add se è arrivata una richiesta di assegnazione, old se la richiesta per il dato mac address è già stata servita una volta, del per il release), il mac address, l&#8217;indirizzo IP assegnato ed l&#8217;hostname. Quest&#8217;ultimo purtroppo non è sempre inviato da tutti i client DHCP, per questo ho trovato un modo alternativo per recuperare l&#8217;hostname nei casi in cui non sia fornito.</p>
<p style="text-align: left;"><strong>Sesto passo: script per il salvataggio delle informazioni</strong></p>
<p style="text-align: left;">E questa è la parte un po&#8217; più complicata. Ecco a voi lo script che aggiunge automaticamente al file hosts le coppie hostname &#8211; indirizzo IP delle varie VM:<strong><br />
</strong></p>

<div class="wp_codebox"><table><tr id="p8942"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
</pre></td><td class="code" id="p894code2"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #808080; font-style: italic;"># script created by Francesco Apollonio and released under GNU General Public License version 2</span>
<span style="color: #808080; font-style: italic;"># http://www.ldlabs.org/</span>
<span style="color: #808080; font-style: italic;"># script that add a VM who requests an IP address using the dhcpd to local hosts file</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">subprocess</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">string</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
&nbsp;
debug_file=<span style="color: #483d8b;">&quot;/var/log/add_hosts.log&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> debug<span style="color: black;">&#40;</span>message<span style="color: black;">&#41;</span>:
   message = <span style="color: #dc143c;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%d %b %Y %H:%M:%S&quot;</span><span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot; &quot;</span> + message
   <span style="color: #ff7700;font-weight:bold;">print</span> message
   fd = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>debug_file, <span style="color: #483d8b;">&quot;a&quot;</span><span style="color: black;">&#41;</span>
   fd.<span style="color: black;">write</span><span style="color: black;">&#40;</span>message + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
   fd.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
text=<span style="color: #483d8b;">&quot;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> arg <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span>:
   text = text +<span style="color: #483d8b;">&quot; &quot;</span>+arg
debug<span style="color: black;">&#40;</span>text<span style="color: black;">&#41;</span>   
&nbsp;
action=<span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
ip=<span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span>
mac=<span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>
hosts=<span style="color: #483d8b;">&quot;/etc/hosts&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># if del action is called exit from this script</span>
<span style="color: #ff7700;font-weight:bold;">if</span> action == <span style="color: #483d8b;">&quot;del&quot;</span>:
   fd=<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>hosts, <span style="color: #483d8b;">&quot;r&quot;</span><span style="color: black;">&#41;</span>
   hosts_lines=fd.<span style="color: black;">readlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
   fd.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
   fd=<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>hosts, <span style="color: #483d8b;">&quot;w&quot;</span><span style="color: black;">&#41;</span>
   <span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> hosts_lines:
      <span style="color: #ff7700;font-weight:bold;">if</span> ip <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #ff7700;font-weight:bold;">in</span> line:
         fd.<span style="color: black;">write</span><span style="color: black;">&#40;</span>line<span style="color: black;">&#41;</span>
&nbsp;
   debug<span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;Ok, %s deleted from %s file&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>name, hosts<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
   <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>      
&nbsp;
<span style="color: #808080; font-style: italic;"># add address to local hosts file</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span> == <span style="color: #ff4500;">5</span>:
   name = <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">4</span><span style="color: black;">&#93;</span>
   debug<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;host name from parameters: &quot;</span>+name<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
   command = <span style="color: #483d8b;">&quot;ps ax | grep /usr/bin/kvm&quot;</span>
   process = <span style="color: #dc143c;">subprocess</span>.<span style="color: black;">Popen</span><span style="color: black;">&#40;</span>command, stdout=<span style="color: #dc143c;">subprocess</span>.<span style="color: black;">PIPE</span>, shell=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
   found = <span style="color: #008000;">None</span>
   <span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> process.<span style="color: black;">stdout</span>.<span style="color: black;">readlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
      pid=line.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot; &quot;</span><span style="color: black;">&#41;</span>
      pid = pid<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
      fd_c = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;/proc/&quot;</span>+pid+<span style="color: #483d8b;">&quot;/cmdline&quot;</span>, <span style="color: #483d8b;">&quot;r&quot;</span><span style="color: black;">&#41;</span>
      lines=fd_c.<span style="color: black;">readlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
      fd_c.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>lines<span style="color: black;">&#41;</span><span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;</span><span style="color: #ff4500;">0</span>:
         line=lines<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
         line=<span style="color: #dc143c;">string</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span>line, <span style="color: #483d8b;">&quot;-&quot;</span>, <span style="color: #483d8b;">&quot; -&quot;</span><span style="color: black;">&#41;</span>
         line=<span style="color: #dc143c;">string</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span>line, <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>00&quot;</span>, <span style="color: #483d8b;">&quot; &quot;</span><span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">else</span>:
         <span style="color: #ff7700;font-weight:bold;">continue</span>
      <span style="color: #ff7700;font-weight:bold;">if</span> mac <span style="color: #ff7700;font-weight:bold;">in</span> line <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #483d8b;">&quot;add_host&quot;</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #ff7700;font-weight:bold;">in</span> line:
         found = line
         <span style="color: #ff7700;font-weight:bold;">break</span>
   <span style="color: #ff7700;font-weight:bold;">if</span> found <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #008000;">None</span>:
      debug<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Ops, no VM with %s found&quot;</span> <span style="color: #66cc66;">%</span> mac<span style="color: black;">&#41;</span>
      <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
   parms = found.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot; -&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span>
   name=<span style="color: #008000;">False</span>
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">for</span> par <span style="color: #ff7700;font-weight:bold;">in</span> parms:
      <span style="color: #ff7700;font-weight:bold;">if</span> par.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">startswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;name&quot;</span><span style="color: black;">&#41;</span>:
         name = par.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot; &quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> name <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #008000;">False</span>:
   debug<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Ops, VM name not found&quot;</span><span style="color: black;">&#41;</span>
   <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>
&nbsp;
fd=<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>hosts, <span style="color: #483d8b;">&quot;r&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
hosts_lines=fd.<span style="color: black;">readlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
fd.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
already=<span style="color: #008000;">False</span>
<span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> hosts_lines:
   <span style="color: #ff7700;font-weight:bold;">if</span> name <span style="color: #ff7700;font-weight:bold;">in</span> line:
      already=line
      <span style="color: #ff7700;font-weight:bold;">break</span>
change=<span style="color: #008000;">False</span>
<span style="color: #ff7700;font-weight:bold;">if</span> already <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">False</span>:
   <span style="color: #ff7700;font-weight:bold;">if</span> ip <span style="color: #ff7700;font-weight:bold;">in</span> line:
      debug<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Ok, VM already in hosts file&quot;</span><span style="color: black;">&#41;</span>
      <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
   <span style="color: #ff7700;font-weight:bold;">else</span>:
      change=<span style="color: #008000;">True</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> change <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #008000;">False</span>:
   fd=<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>hosts, <span style="color: #483d8b;">&quot;a&quot;</span><span style="color: black;">&#41;</span>
   fd.<span style="color: black;">write</span><span style="color: black;">&#40;</span>ip + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> + name +<span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
   fd=<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>hosts, <span style="color: #483d8b;">&quot;w&quot;</span><span style="color: black;">&#41;</span>
   <span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> hosts_lines:
      <span style="color: #ff7700;font-weight:bold;">if</span> name <span style="color: #ff7700;font-weight:bold;">in</span> line:
         line = ip + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> + name + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
      fd.<span style="color: black;">write</span><span style="color: black;">&#40;</span>line<span style="color: black;">&#41;</span>
&nbsp;
fd.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
debug<span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;Ok, %s added to %s file&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>name, hosts<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p style="text-align: left;">Il funzionamento è abbastanza semplice. In caso di comando &#8220;add&#8221; o &#8220;old&#8221; ricevuto dal server DHCP, lo script prima controlla se l&#8217;hostname è stato fornito dalla richiesta DHCP,  e in questo caso procede direttamente al salvataggio. Se invece l&#8217;hostname non è stato fornito, lo script scansiona la lista dei processi KVM che sono in esecuzione. Poi si procura la command line completa con le quali le macchine virtuali sono state eseguite leggendola dall&#8217;apposito file nella cartella /proc (in una prima versione usavo direttamente l&#8217;output di <em>ps</em> per ottenere queste informazioni, ma, in determinate circostanze, la command line veniva tagliata, rendendo inutilizzabile lo script, per questo ho optato per recuperare le informazioni da /proc). Una volta ottenuta la command line il gioco è fatto: estraggo il nome della macchina virtuale impostato in Virtualbricks, apro il file hosts controllo che non ci sia già una voce per la macchina virtuale che ha richiesto l&#8217;indirizzo; se esiste allora semplicemente aggiorno l&#8217;indirizzo IP, se invece non esiste aggiungo una nuova voce.<br />
Per quanto riguarda &#8220;del&#8221;, invece, apro il file hosts e se vi è l&#8217;indirizzo ip specificato, elimino la linea che lo contiene.</p>
<p style="text-align: left;"><strong>Parte sette: conclusioni e sviluppi futuri<br />
</strong></p>
<p style="text-align: left;">Bene l&#8217;architettura funziona più che bene (la utilizzo quotidianamente). Questa è ovviamente solo una applicazione per poter creare una &#8220;rete di controllo&#8221; che permetta una più semplice gestione di un numero variabile di macchine virtuali. Per i prossimi sviluppi restate in ascolto <img src='http://www.ldlabs.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley colorbox-894' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.ldlabs.org/blog/2012/01/19/creazione-di-una-rete-di-controllo-per-macchine-virtuali/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Virtualbricks in debian sid!</title>
		<link>http://www.ldlabs.org/blog/2012/01/18/virtualbricks-in-debian-sid/</link>
		<comments>http://www.ldlabs.org/blog/2012/01/18/virtualbricks-in-debian-sid/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 12:19:38 +0000</pubDate>
		<dc:creator>Francesco Apollonio</dc:creator>
				<category><![CDATA[news]]></category>
		<category><![CDATA[Virtualbricks]]></category>
		<category><![CDATA[annunci]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[guida virtualbricks]]></category>
		<category><![CDATA[kvm]]></category>
		<category><![CDATA[qemu]]></category>
		<category><![CDATA[utility]]></category>
		<category><![CDATA[varie]]></category>
		<category><![CDATA[vde]]></category>
		<category><![CDATA[virtual]]></category>
		<category><![CDATA[virtualbricks]]></category>

		<guid isPermaLink="false">http://www.ldlabs.org/blog/?p=885</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
Ultimamente non scrivo molto per mancanza di tempo, ma questa notizia, visto che mi riguarda da vicino, andava pubblicizzata. Virtualbricks è ora disponibile nei repository ufficiali di debian sid! Per chi non lo sapesse Virtualbricks è un software per la gestione di macchine virtuali Qemu/KVM, che permette anche la crezione di topologie complesse composte da [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
<p>Ultimamente non scrivo molto per mancanza di tempo, ma questa notizia, visto che mi riguarda da vicino, andava pubblicizzata.</p>
<p><img class="aligncenter colorbox-885" title="Virtualbricks Logo" src="http://www.virtualbricks.eu/templates/qemulator/images/Logo140.png" alt="" width="130" height="140" /></p>
<h1 style="text-align: center;"><strong>Virtualbricks è ora disponibile nei repository ufficiali di debian sid!</strong></h1>
<p style="text-align: left;">Per chi non lo sapesse Virtualbricks è un software per la gestione di macchine virtuali Qemu/KVM, che permette anche la crezione di topologie complesse composte da più macchine virtuali interconnesse dai componenti VDE, creazione di reti ibride (macchine virtuali e reali nella stessa rete LAN) e distribuite (utilizzando cioè più di una macchina host).<strong> </strong></p>
<p style="text-align: left;">Il sito ufficiale è <a href="http://www.virtualbricks.eu/" target="_blank">http://www.virtualbricks.eu/</a>, nel wiki è disponibile un po&#8217; di documentazione (dobbiamo ancora continuare a lavorarci per ampliarla).<strong> </strong></p>
<p style="text-align: left;">Per scaricare l&#8217;ultima versione l&#8217;indirizzo è <a href="http://www.virtualbricks.eu/download.php?latest" target="_blank">http://www.virtualbricks.eu/download.php?latest</a> oppure dalla pagina Launchpad del progetto <a href="http://launchpad.net/virtualbrick" target="_blank">http://launchpad.net/virtualbrick</a>, a meno che non usiate Debian sid, li ovviamente il comando è:</p>
<p style="text-align: left;">apt-get install virtualbricks</p>
<p style="text-align: left;">A presto!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ldlabs.org/blog/2012/01/18/virtualbricks-in-debian-sid/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>VNC &amp; HTML5: Visualizzare il desktop remoto tramite un web browser con Guacamole</title>
		<link>http://www.ldlabs.org/blog/2011/07/12/vnc-html5-visualizzare-il-desktop-remoto-tramite-un-web-browser-con-guacamole/</link>
		<comments>http://www.ldlabs.org/blog/2011/07/12/vnc-html5-visualizzare-il-desktop-remoto-tramite-un-web-browser-con-guacamole/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 09:47:47 +0000</pubDate>
		<dc:creator>Francesco Apollonio</dc:creator>
				<category><![CDATA[Guide]]></category>
		<category><![CDATA[recensione]]></category>
		<category><![CDATA[annunci]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[tomcat]]></category>
		<category><![CDATA[utility]]></category>
		<category><![CDATA[varie]]></category>
		<category><![CDATA[vnc]]></category>

		<guid isPermaLink="false">http://www.ldlabs.org/blog/?p=872</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
Utilizzando macchine (virtuali e non) remote, mi capita spesso di dover utilizzare VNC per avere accesso al desktop, talvolta serve anche un ambiente grafico. Sono venuto a conoscenza qualche giorno fa di Guacamole, programma che permette di accedere al desktop VNC attraverso un normalissimo browser web che supporti però il tag canvas di HTML5. Il [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
<p style="text-align: left;">Utilizzando macchine (virtuali e non) remote, mi capita spesso di dover utilizzare VNC per avere accesso al desktop, talvolta serve anche un ambiente grafico. Sono venuto a conoscenza qualche giorno fa di <a href="http://guacamole.sourceforge.net/" target="_blank">Guacamole</a>, programma che permette di accedere al desktop VNC attraverso un normalissimo browser web che supporti però il tag canvas di HTML5.</p>
<div id="attachment_874" class="wp-caption aligncenter" style="width: 533px"><a href="http://www.ldlabs.org/blog/wp-content/uploads/2011/07/screenshot2.jpeg"><img class="size-large wp-image-874  colorbox-872" title="Guacamole_browser" src="http://www.ldlabs.org/blog/wp-content/uploads/2011/07/screenshot2-1024x539.jpg" alt="" width="523" height="275" /></a><p class="wp-caption-text">Desktop remoto con Guacamole nel browser</p></div>
<p><span id="more-872"></span>Il programma funziona benissimo e velocemente, l&#8217;unica cosa un po&#8217; complicata è l&#8217;installazione. Per prima cosa occorre installare <strong>Tomcat6. </strong>Infatti il cuore che permette il tutto è un applicazione in Java che invia al browser le informazioni per poter visualizzare il desktop. Eseguiamo l&#8217;installazione:</p>
<pre># apt-get install tomcat6 libvncserver0</pre>
<p>Ora che il web server è installato, occorre scaricare il programma da <a href="http://sourceforge.net/projects/guacamole/files/guacamole-0.2.6.tar.gz/download?use_mirror=mesh" target="_blank">questo link</a>. Dopo aver scompattato l&#8217;archivio, quello che ci troviamo davanti sono alcuni file xml (file di configurazione) ed un war (archivio contenente l&#8217;applicazione vera e propria). Questa è la procedura d&#8217;installazione:</p>
<pre># cp guacamole-users.xml /etc/tomcat6/
# mkdir -p /var/lib/guacamole
# cp guacamole.war /var/lib/guacamole/
# cp guacamole.xml /etc/tomcat6/Catalina/localhost/</pre>
<p>I file sono ora installati nel webserver ma occorre configurarli. In particolare in <strong>/etc/tomcat6/guacamole-users.xml </strong>troviamo la coppia <em>user:password</em> che ci viene chiesta all&#8217;apertura dell&#8217;applicazione, non si tratta della password di VNC ma di una <span style="text-decoration: underline;">password propria dell&#8217;applicazione</span>. Nel file<strong> /etc/tomcat6/Catalina/localhost/guacamole.xml</strong> invece sono contenute l&#8217;informazioni del server VNC:</p>
<pre>&lt;Parameter name="host" value="localhost"/&gt;
&lt;Parameter name="port" value="5901"/&gt;
&lt;Parameter name="password" value="PASSWORD"/&gt;</pre>
<p>I parametri che ci interessano sono questi tre elencati sopra, e vanno riempiti con i dati del server VNC. In particolare per calcolare la porta, occorre ottenere il numero desktop virtuale avviato (:1 ad esempio) e sommarlo a 5900. In questo caso quindi il server a cui ci connettiamo è :1. Per avviare un nuovo server VNC ovviamente digitiamo il comando:</p>
<pre>$ vncserver
New 'X' desktop is home:1</pre>
<p>Se è la prima volta che avviamo un server VNC, ci verrà chiesta la password per l&#8217;accesso (non è obbligatorio inserirla), quella che deve essere inclusa nel file <em>guacamole.xml</em>. Ora riavviamo il server web:</p>
<p># service tomcat6 restart</p>
<p>e colleghiamoci all&#8217;applicazione tramite il nostro browser (occhio ad utilizzare uno compatibile con il tag CANVAS di HTML5, chromium/chrome o Firefox 5 vanno benissimo) utilizzando il link:</p>
<pre>http://localhost:8080/guacamole/</pre>
<p>ci verrà prima richiesto di effettuare l&#8217;autenticazione del programma. Se non avete cambiato <em>guacamole-users.xml</em> l&#8217;username è &#8216;<em>guacamole</em>&#8216; e la password &#8216;<em>changeme</em>&#8216;, ovviamente è fortemente consigliato cambiarla. Dopo aver inserito anche la password del server VNC (se ovviamente è stata impostata):</p>
<p style="text-align: center;">&nbsp;</p>
<div class="mceTemp mceIEcenter" style="text-align: left;">
<dl id="attachment_873" class="wp-caption aligncenter" style="width: 584px;">
<dt class="wp-caption-dt"><a href="http://www.ldlabs.org/blog/wp-content/uploads/2011/07/screenshot1.jpeg"><img class="size-large wp-image-873   colorbox-872" title="screenshot1" src="http://www.ldlabs.org/blog/wp-content/uploads/2011/07/screenshot1-1024x576.jpg" alt="Guacamole in azione" width="574" height="322" /></a></dt>
<dd class="wp-caption-dd">Guacamole in azione</dd>
</dl>
</div>
<p style="text-align: left;">Ecco fatto ora accedere al vostro server VNC sarà molto più semplice, infatti impostando ad esempio come porta di Tomcat la 80, potrete accedere al desktop remoto in tranquillità anche in presenza di proxy non troppo permissivi!</p>
<p style="text-align: left;">Buon lavoro!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ldlabs.org/blog/2011/07/12/vnc-html5-visualizzare-il-desktop-remoto-tramite-un-web-browser-con-guacamole/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jquery AjaxForm Plugin: Upload di un file con AJAX</title>
		<link>http://www.ldlabs.org/blog/2011/07/05/jquery-ajaxform-plugin-upload-di-un-file-con-ajax/</link>
		<comments>http://www.ldlabs.org/blog/2011/07/05/jquery-ajaxform-plugin-upload-di-un-file-con-ajax/#comments</comments>
		<pubDate>Tue, 05 Jul 2011 10:45:23 +0000</pubDate>
		<dc:creator>Francesco Apollonio</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[recensione]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[code tips]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[utility]]></category>
		<category><![CDATA[varie]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.ldlabs.org/blog/?p=826</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
Sviluppano spesso siti web di vario genere, mi sono trovato a dover gestire un form html con Ajax. Il problema non è stato tanto per i dati testuali normali, quanto principalmente perchè dovevo trasferire un file via AJAX. Lo strumento che ho utilizzato è JQuery Form Plugin. Tre parole per descriverlo? Semplice, rapido e funzionante! [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
<p>Sviluppano spesso siti web di vario genere, mi sono trovato a dover gestire un form html con Ajax. Il problema non è stato tanto per i dati testuali normali, quanto principalmente perchè dovevo <strong>trasferire un file via AJAX</strong>.</p>
<p>Lo strumento che ho utilizzato è <a href="http://jquery.malsup.com/form/" target="_blank">JQuery Form Plugin</a>. Tre parole per descriverlo? Semplice, rapido e funzionante!<br />
<span id="more-826"></span><br />
Per prima cosa vediamo la pagina <strong>HTML</strong> (con l&#8217;annesso form per l&#8217;upload):</p>
<pre>&lt;html&gt;
	&lt;head&gt;

		&lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"&gt;
		&lt;script type="text/javascript" src="jquery-1.5.1.min.js" &gt;&lt;/script&gt;
		&lt;script type="text/javascript" src="jquery.form.js" &gt;&lt;/script&gt;
		&lt;script type="text/javascript" src="scripts.js" &gt;&lt;/script&gt;
		&lt;/script&gt;
		&lt;title&gt;Pagina di prova&lt;/title&gt;

	&lt;/head&gt;
	&lt;body&gt;

		&lt;form action="file_upload.php" method="post"
			enctype="multipart/form-data" id="upload"&gt;

			&lt;label for="file"&gt;Filename:&lt;/label&gt;
			&lt;input type="file" name="file" id="file" /&gt;&lt;br /&gt;
			&lt;input type="submit" id="send_file" value="Aggiungi" /&gt;

		&lt;/form&gt;

	&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Ovviamente, come si può vedere analizzando l&#8217;html, occorrono altri due file. Il primo è il file javascript che ci permetterà di gestire l&#8217;invio lato client. Il secondo è il file in PHP che ci permette di gestire l&#8217;upload dal lato server. Analizziamo il file <strong>javascript</strong> (<em>script.js</em>):</p>

<div class="wp_codebox"><table><tr id="p8265"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p826code5"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#upload&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ajaxForm</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>resp<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>resp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Come si può facilmente capire il funzionamento è semplice. Basta associare l&#8217;AjaxForm all&#8217;id del form html ed il gioco è fatto. Ovviamente nella funzione di risposta si può effettuare qualsiasi operazione, utilizzando la variabile <em>resp</em> che contiene l&#8217;output della pagina che si occupa dell&#8217;upload lato server. Ecco il codice <strong>PHP</strong> (<em>file_upload.php</em>):</p>

<div class="wp_codebox"><table><tr id="p8266"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p826code6"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// CONTROLLO DEI PARAMETRI!</span>
<span style="color: #000088;">$path</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;PERCORSO_DOVE_SALVARE_IL_FILE/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;file&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;error&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;ERROR&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/file_exists"><span style="color: #990000;">file_exists</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;file&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;File already exists.&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<a href="http://www.php.net/move_uploaded_file"><span style="color: #990000;">move_uploaded_file</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;file&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;tmp_name&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$path</span> <span style="color: #339933;">.</span>  <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;file&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;OK. File uploaded.&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>che semplicemente salva il file nella directory specificata e ritorna un messaggio che indica se l&#8217;operazione è andata a buon fine. Ricordatevi ovviamente, se utilizzate lo script in PHP per il vostro sito, di eseguire le operazioni di controllo dei parametri in ingresso via POST.</p>
<p>Come potete vedere è veramente una passeggiata, buon lavoro!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ldlabs.org/blog/2011/07/05/jquery-ajaxform-plugin-upload-di-un-file-con-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programmare ARM &#8211; Compilare il bin da caricare sulla Board LPC-P1343</title>
		<link>http://www.ldlabs.org/blog/2011/07/04/programmare-arm-compilare-il-bin-da-caricare-sulla-board-lpc-p1343/</link>
		<comments>http://www.ldlabs.org/blog/2011/07/04/programmare-arm-compilare-il-bin-da-caricare-sulla-board-lpc-p1343/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 17:34:32 +0000</pubDate>
		<dc:creator>Francesco Apollonio</dc:creator>
				<category><![CDATA[ARM]]></category>
		<category><![CDATA[Embedded]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[arm]]></category>
		<category><![CDATA[cortex-m3]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[lpc-1343]]></category>
		<category><![CDATA[LPC-P1343]]></category>
		<category><![CDATA[lpc1343]]></category>
		<category><![CDATA[mtools]]></category>
		<category><![CDATA[uart]]></category>

		<guid isPermaLink="false">http://www.ldlabs.org/blog/?p=807</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
Abbiamo visto come caricare sulla scheda un firmware che già abbiamo, ma come possiamo compilarne uno noi? Il primo passo è ovviamente ottenere il compilatore, chi ha letto il vecchio articolo avrà sicuramente notato, in fondo alla pagina, la presenza del link ad un compilatore ARM, è proprio quello che utilizzeremo per creare il firmware [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top:40%;
left:60px;
z-index:1;
#F0F4F9 
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;
width:110px;
height:60px;
padding-bottom:2px;
}


#bottomcontainerBox {
float:left;
height:30px;
width:100%;
#F0F4F9}

#bottomcontainerBox .buttons {
float:left;
height:30px;
width:110px;
margin:4px 4px 4px 4px;
}

</style>
<p>Abbiamo visto come caricare sulla scheda un firmware che già abbiamo, ma come possiamo compilarne uno noi?</p>
<div id="attachment_786" class="wp-caption aligncenter" style="width: 570px"><a href="http://www.ldlabs.org/blog/wp-content/uploads/2011/06/lpc-p1343.png" rel="cb1"><img class="size-full wp-image-786 colorbox-807" title="lpc-p1343" src="http://www.ldlabs.org/blog/wp-content/uploads/2011/06/lpc-p1343.png" alt="" width="560" height="320" /></a><p class="wp-caption-text">Layout della board</p></div>
<p><span id="more-807"></span>Il primo passo è ovviamente ottenere il <em>compilatore</em>, chi ha letto il vecchio articolo avrà sicuramente notato, in fondo alla pagina, la presenza del link ad un compilatore ARM, è proprio quello che utilizzeremo per creare il firmware da caricare:</p>
<p>&nbsp;</p>
<pre>wget http://www.codesourcery.com/sgpp/lite/arm/portal/package8734/public/\
arm-none-eabi/arm-2011.03-42-arm-none-eabi-i686-pc-linux-gnu.tar.bz2
tar jxvf arm-2011.03-42-arm-none-eabi-i686-pc-linux-gnu.tar.bz2</pre>
<p>Facciamo attenzione alla directory che utilizziamo per contenere il compilatore, dato che ci servirà per permetterci di raggiungerlo, infatti occorre impostare una <em>variabile del nostro terminale</em> con il percorso esatto. Dal terminale dove successivamente eseguiremo la compilazione digitiamo:</p>
<pre>export CROSS_COMPILE=/PERCORSO_VERSO_IL_COMPILATORE/arm-2011.03/bin/arm-none-eabi-</pre>
<p>In alternativa possiamo aggiungere la riga all&#8217;interno del file<em> ~/.bashrc</em> in modo da non doverlo riscrivere ogni volta.</p>
<p>Ora non ci resta che trovare qualcosa da compilare. Per i miei esperimenti utilizzo il mini-sistema operativo creato da Alessandro Rubini per processori <strong>Cortex-M3</strong> che si può scaricare <a href="http://gnudd.com/pub/cortex-m3/cortex-m3-v2011-04-23.tar.gz" target="_blank">da questo indirizzo</a>. Questo sistema è un buon inizio per inziare a muovere i primi passi con  la board (sto inziando anche io con questo), infatti permette di avere un sistema che si avvia e sul quale è  possibile effettuare delle aggiunte. Una volta scaricato e scompattato, occorre prima effettuare una modifica al main.c:</p>

<div class="wp_codebox"><table><tr id="p8078"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code" id="p807code8"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdint.h&gt;</span>
<span style="color: #339933;">#include &quot;io.h&quot;</span>
&nbsp;
<span style="color: #993333;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #993333;">volatile</span> <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
 <span style="color: #993333;">int</span> on <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #808080; font-style: italic;">/*
 * Call the mimmo application. Turn this if to false if you want to
 * run the older code that just flashes leds
 */</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> do_mimmo<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 do_mimmo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #808080; font-style: italic;">/* Older led-toggling application */</span>
 <span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">volatile</span> uint32_t <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #208080;">0x50038000</span> <span style="color: #339933;">=</span> <span style="color: #208080;">0xf</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* port C: all 4 out */</span>
&nbsp;
 <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 puts<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;stuff<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">++</span>on <span style="color: #339933;">&amp;</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
 <span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">volatile</span> uint32_t <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #208080;">0x5003003c</span> <span style="color: #339933;">=</span> <span style="color: #208080;">0xf</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">else</span>
 <span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">volatile</span> uint32_t <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #208080;">0x5003003c</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">1000</span><span style="color: #339933;">*</span><span style="color: #0000dd;">1000</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
 <span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>In particolare occorre modificare la riga 13, non facendo entrare il programma all&#8217;interno dell&#8217;if, cambiano quindi l&#8217;1 in 0. Dopo aver salvato il file, non ci resta che lanciare il comando <em> </em></p>
<p>make</p>
<p>dalla cartella estratta per eseguire la compilazione. Come si può leggere dal pdf allegato ai sorgenti, vengono creati due file bin, uno per l&#8217;esecuzione da ROM e uno per l&#8217;esecuzione da RAM. Dato che per programmare la RAM è necessario usare UART, quello che interessa a noi e che quindi dobbiamo trasferire sulla board è il file <em>m3c.rom.bin</em>:</p>
<p>mdel c:firmware.bin<br />
mcopy m3c.rom.bin c:new.bin</p>
<p>Per chi non capisse cosa sono questi ultimi due comandi, consiglio la lettura del <a href="http://www.ldlabs.org/blog/2011/06/13/programmare-arm-programmare-la-board-lpc-p1343/" target="_blank">precedente articolo</a> che spiega, tra l&#8217;altro, come configurare <em>mtools</em> per permettere il riconoscimento della board. Dopo aver resettato la board (togliere il jumper dai piedini JMP BLD_E e premere il tasto di Reset) il nuovo programma appena compilato e caricato verrà eseguito, facendo lampeggiare 4 led.</p>
<p>La prossima volta vedremo come accedere ai registri di configurazione e accendere dei led a piacere.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ldlabs.org/blog/2011/07/04/programmare-arm-compilare-il-bin-da-caricare-sulla-board-lpc-p1343/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

