<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>Lindus Embedded</title>
	<atom:link href="http://www.lindusembedded.com/blog/rss/feed.xml" rel="self" type="application/rss+xml" />
	<link>http://www.lindusembedded.com/blog</link>
	<description>Embedding Open Source</description>
	<lastBuildDate>Mon, 05 Mar 2012 12:01:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Android GitWeb</title>
		<link>http://www.lindusembedded.com/blog/2012/02/23/android-gitweb/</link>
		<comments>http://www.lindusembedded.com/blog/2012/02/23/android-gitweb/#comments</comments>
		<pubDate>Thu, 23 Feb 2012 11:43:03 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.lindusembedded.com/blog/2012/02/23/android-gitweb/</guid>
		<description><![CDATA[Since the kernel.org servers were hacked a browsable repository can be found here.]]></description>
			<content:encoded><![CDATA[<p>Since the kernel.org servers were hacked a browsable repository can be found <a href="https://www.codeaurora.org/gitweb/quic/la/" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lindusembedded.com/blog/2012/02/23/android-gitweb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android kernel sources download and compilation</title>
		<link>http://www.lindusembedded.com/blog/2012/02/23/android-kernel-sources-download-and-compilation/</link>
		<comments>http://www.lindusembedded.com/blog/2012/02/23/android-kernel-sources-download-and-compilation/#comments</comments>
		<pubDate>Thu, 23 Feb 2012 11:33:46 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.lindusembedded.com/blog/2012/02/23/android-kernel-sources-download-and-compilation/</guid>
		<description><![CDATA[Compile Android&#8217;s kernel tree user@computer:$ git clone https://android.googlesource.com/kernel/common.git linux-androidcd linux-androidgit branch -rorigin/HEAD -&#62; origin/masterorigin/android-2.6.39origin/android-3.0origin/android-3.3origin/mastergit checkout origin/android-2.6.39make ARCH=arm CROSS_COMPILE=${SDK_ROOT}}/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi- mx51_defconfigmake -j4 ARCH=arm CROSS_COMPILE=${SDK_ROOT}}/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi- This generates a file named arch/arm/boot/zImage Compile Android&#8217;s emulator kernel user@computer:$ git clone https://android.googlesource.com/kernel/goldfish.gitgit checkout origin/android-goldfish-2.6.29make ARCH=arm CROSS_COMPILE=${SDK_ROOT}}/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi- goldfish_defconfig # configure the armv5 kernelmake ARCH=arm CROSS_COMPILE=${SDK_ROOT}}/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi- goldfish_armv7_defconfig # configure the armv7 kernelmake -j4 [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Compile Android&#8217;s kernel tree</strong></p>

<div class="wp-terminal">user@computer:$ git clone https://android.googlesource.com/kernel/common.git linux-android<br/>cd linux-android<br/>git branch -r<br/><br/>origin/HEAD -&gt; origin/master<br/>origin/android-2.6.39<br/>origin/android-3.0<br/>origin/android-3.3<br/>origin/master<br/><br/>git checkout origin/android-2.6.39<br/>make ARCH=arm CROSS_COMPILE=${SDK_ROOT}}/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi- mx51_defconfig<br/>make -j4 ARCH=arm CROSS_COMPILE=${SDK_ROOT}}/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-<br/><br/></div>

<p>This generates a file named <strong>arch/arm/boot/zImage</strong></p>
<p><strong>Compile Android&#8217;s emulator kernel</strong></p>

<div class="wp-terminal">user@computer:$ git clone https://android.googlesource.com/kernel/goldfish.git<br/>git checkout origin/android-goldfish-2.6.29<br/>make ARCH=arm CROSS_COMPILE=${SDK_ROOT}}/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi- goldfish_defconfig  			# configure the armv5 kernel<br/>make ARCH=arm CROSS_COMPILE=${SDK_ROOT}}/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi- goldfish_armv7_defconfig		# configure the armv7 kernel<br/>make -j4 ARCH=arm CROSS_COMPILE=${SDK_ROOT}}/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-<br/><br/></div>

<p>This generates a file named <strong>arch/arm/boot/zImage</strong></p>
<p>Both the standard and emulator kernels are provided precompiled in the SDK at <strong>${SDK_ROOT}/prebuilt/android-arm/kernel.</strong></p>
<p>You can now run the emulator as:</p>

<div class="wp-terminal">user@computer:$ make sdk -j4<br/>${SDK_ROOT}/out/host/linux-x86/bin/emulator -kernel ${SDK_ROOT}/prebuilt/android-arm/kernel/kernel-qemu-armv7 -show-kernel -verbose<br/><br/></div>

<p>Note that as a convenience, if the name of the kernel image ends with -armv7, then the cortex-a8 emulation will be turned on automatically. Otherwise you would have to pass the flags manually (-qemu -cpu cortex-a8).</p>
<p>Reportedly the qemu emulator included in the Android SDK doesn&#8217;t support ARMv7 emulation properly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lindusembedded.com/blog/2012/02/23/android-kernel-sources-download-and-compilation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android&#8217;s partition images</title>
		<link>http://www.lindusembedded.com/blog/2012/02/23/androids-partition-images/</link>
		<comments>http://www.lindusembedded.com/blog/2012/02/23/androids-partition-images/#comments</comments>
		<pubDate>Thu, 23 Feb 2012 11:04:00 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.lindusembedded.com/blog/2012/02/23/androids-partition-images/</guid>
		<description><![CDATA[Ramdisk A ramdisk.img (initrd) is a small partition image that is mounted read-only by the kernel at boot time. It only contains /init and a few config files. It is used to start init which will mount the rest of the system images properly and run the init procedure. A Ramdisk is a standard Linux [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Ramdisk</strong></p>
<p>A <strong>ramdisk.img</strong> (initrd) is a small partition image that is mounted read-only by the kernel at boot time. It only contains /init and a few config files. It is used to start init which will mount the rest of the system images properly and run the init procedure. A Ramdisk is a standard Linux feature.</p>
<p>ramdisk.img is included ($SDK_ROOT/tools/lib/images/ramdisk.img) or compiled ($SDK_ROOT/out/target/product/$PRODUT_NAME/ramdisk.img) by the google android sdk. It&#8217;s in a gzipped cpio file.</p>
<p><strong>Modifying Android&#8217;s ramdisk image</strong></p>
<p>To modify it, first copy it to your Linux machine and extract it as follows:</p>

<div class="wp-terminal">user@computer:$ mv ramdisk.img ramdisk.cpio.gz<br/>gzip -d ramdisk.cpio.gz<br/>cpio -i -F ramdisk.cpio<br/><br/></div>

<p>Make any changes you want to the extracted ramdisk.cpio, and remove the unneeded files. Recreate the ramdisk.cpio with command:</p>

<div class="wp-terminal">user@computer:$ cpio -i -t -F ../ramdisk.cpio | cpio -o -H newc -O ../ramdisk_new.cpio<br/><br/></div>

<p><strong>System and data images</strong></p>
<p>The <strong>system.img</strong> is a partition image that will be mounted as <strong>/</strong> and thus contains all system binaries.<br />
 The <strong>userdata.im</strong>g is a partition image that can be mounted as <strong>/data</strong> and thus contains all application-specific and user-specific data.</p>
<p>On the real device they have to be mounted by the init.rc script which runs from the ramdisk. They can be of different formats, usually YAFFS2, EXT4 or UBI-FS.</p>
<p>They are generated by the build system and can be used to flash to a real device. The emulator uses them differently (see below)</p>
<p><strong>Android emulator images</strong></p>
<ul>
<li><strong>system.img</strong> is copied into a temporary file, which is used by the emulator session. So any change you make to / as root in the emulator are lost when the program exits</li>
<li><strong>userdata.img</strong> is only used when you use -wipe-data. Instead, it uses  ~/.android/userdata-qemu.img (on Linux) as the persistent /data partition image. Using -wipe-data simply copies the content of userdata.img into userdata-qemu.img</li>
<li><strong>sdcard.img</strong>, if present or specified with -sdcard , corresponds to /sdcard</li>
<li><strong>cache.img</strong> if specified in the emulator with -cache  corresponds to /cache. if none is specified, an empty temporary file is created at emulator startup and /cache will be mounted to it. this temp file is automatically cleaned up at exit.</li>
</ul>
<p>The emulator will not modify system.img and userdata.img since they were generated as device images.</p>
<p><strong>Extracting Android&#8217;s YAFFS2 images</strong></p>
<p>A YAFFS2 file is identied as a &#8220;VMS Alpha executable&#8221; by Linux.</p>

<div class="wp-terminal">user@computer:$ file ${SDK_ROOT}}/out/target/product/imx51_ccwmx51js/system.img<br/>./out/target/product/imx51_ccwmx51js/system.img: VMS Alpha executable<br/><br/></div>

<p>Download <a href="http://unyaffs.googlecode.com/files/unyaffs" target="_blank">unyaffs</a> from the unyaffs Google Project Hosting.</p>
<p>If the executable does not work on your system you can download the <a href="http://code.google.com/p/unyaffs/" target="_blank">source</a> and recompile it.</p>

<div class="wp-terminal">user@computer:$ gcc -o unyaffs unyaffs.c<br/>sudo chmod +x /complete/directory/path/to/unyaffs<br/><br/></div>

<p>Copy the YAFF2 img files to the same folder and extract them:</p>

<div class="wp-terminal">user@computer:$ ./unyaffs system.img<br/>./unyaffs data.img<br/>./unyaffs cache.img<br/><br/></div>

<p><strong>Extracting JFFS2 images</strong></p>
<p>Just for completion, here is how to extract a JFFS2 image.</p>

<div class="wp-terminal">user@computer:$ modprobe mtdblock<br/>modprobe jffs2<br/>modprobe mtdram total_size=65536 erase_size=256<br/>mknod /tmp/mtdblock0 b 31 0<br/>dd if=/pathtoimage/rootfs.jffs2 of=/tmp/mtdblock0<br/>mount -t jffs2 /tmp/mtdblock0 /mnt<br/><br/></div>

]]></content:encoded>
			<wfw:commentRss>http://www.lindusembedded.com/blog/2012/02/23/androids-partition-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rs232 101</title>
		<link>http://www.lindusembedded.com/blog/2012/01/16/rs232-101/</link>
		<comments>http://www.lindusembedded.com/blog/2012/01/16/rs232-101/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 10:58:07 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.lindusembedded.com/blog/2012/01/16/rs232-101/</guid>
		<description><![CDATA[RS232 focusses on the connection of DTE, data terminal equipment (computers, printers, etc.) with DCE, data communication equipment (modems).RS232 cables can use DB25 or DB9 connectors. DB25 connectors have provision for two RS232 connections, but the single connection DB9 is most commonly used. RS323 DB9 pinout 1 DCD Data carrier detect 2 RD Receive data [...]]]></description>
			<content:encoded><![CDATA[<p>RS232 focusses on the connection of <strong>DTE</strong>, data terminal equipment (computers, printers, etc.) with <strong>DCE</strong>, data communication equipment (modems).RS232 cables can use DB25 or DB9 connectors. DB25 connectors have provision for two RS232 connections, but the single connection DB9 is most commonly used.</p>
<h2><strong>RS323 DB9 pinout</strong></h2>
</p>
<div>
<table border="0">
<tbody>
<tr>
<td>1</td>
<td>DCD</td>
<td>Data carrier detect</td>
</tr>
<tr>
<td>2</td>
<td>RD</td>
<td>Receive data</td>
</tr>
<tr>
<td>3</td>
<td>TD</td>
<td>Transmit data</td>
</tr>
<tr>
<td>4</td>
<td>DTR</td>
<td>Data terminal ready</td>
</tr>
<tr>
<td>5</td>
<td>SG</td>
<td>Signal ground</td>
</tr>
<tr>
<td>6</td>
<td>DSR</td>
<td>Data set ready</td>
</tr>
<tr>
<td>7</td>
<td>RTS</td>
<td>Request to send</td>
</tr>
<tr>
<td>8</td>
<td>CTS</td>
<td>Clear to send</td>
</tr>
<tr>
<td>9</td>
<td>RI</td>
<td>Ring indicator</td>
</tr>
</tbody>
</table>
</div>
<h2><strong>DTE to DTE connections through a null modem cable (PC to PC)</strong></h2>
<p>The purpose of a null-modem cable is to permit two RS-232 <strong>DTE</strong> devices to communicate with each other without modems or other communication devices (i.e., <strong>DCEs</strong> ) between them.</p>
<p>A null modem cable is an RS232 serial cable where the transmit and receive lines are crosslinked. In some cables there are also handshake lines crosslinked. In many situations a straight through serial cable is used, together with a null modem adapter. The adapter contains the necessary crosslinks between the signals.</p>
<p><strong>Null modem without handshaking</strong></p>
<div>
<table border="0">
<tbody>
<tr>
<td>Connector 1</td>
<td>Connector 2></td>
<td>Function</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td>Rx&nbsp;-&gt;&nbsp;Tx></td>
</tr>
<tr>
<td>3</td>
<td>2</td>
<td>>Tx>&nbsp;-&gt;&nbsp;Rx</td>
</tr>
<tr>
<td>5</td>
<td>5</td>
<td>Signal ground</td>
</tr>
</tbody>
</table>
</div>
<p><strong>Null modem with loop back handshaking</strong></p>
<div>
<table border="0">
<tbody>
<tr>
<td>Connector 1</td>
<td>Connector 2</td>
<td>Function</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td>Rx -&gt; Tx</td>
</tr>
<tr>
<td>3</td>
<td>2</td>
<td>Tx&nbsp;-&gt;&nbsp;Rx</td>
</tr>
<tr>
<td>5</td>
<td>5</td>
<td>Signal ground</td>
</tr>
<tr>
<td>1 + 4 + 6</td>
<td>-</td>
<td>DTR -&gt;&nbsp;>CD + DSR</td>
</tr>
<tr>
<td>-</td>
<td>1 + 4 + 6</td>
<td>DTR -&gt;&nbsp;CD + DSR</td>
</tr>
<tr>
<td>7 + 8</td>
<td>-</td>
<td>RTS&nbsp;-&gt;&nbsp;CTS</td>
</tr>
<tr>
<td>-</td>
<td>7 + 8</td>
<td>>RTS&nbsp;-&gt;&nbsp;CTS</td>
</tr>
</tbody>
</table>
</div>
<p><strong>Null modem with partial handshaking</strong></p>
<div>
<table border="0">
<tbody>
<tr>
<td>Connector 1</td>
<td>Connector 2</td>
<td>Function</td>
</tr>
<tr>
<td>1</td>
<td>7 + 8</td>
<td>RTS2 -&gt;&nbsp;CTS2 + CD1</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td>Rx -&gt;&nbsp;Tx</td>
</tr>
<tr>
<td>3</td>
<td>2</td>
<td>Tx -&gt;&nbsp;Rx</td>
</tr>
<tr>
<td>4</td>
<td>6</td>
<td>DTR -&gt;&nbsp;DSR</td>
</tr>
<tr>
<td>5</td>
<td>5</td>
<td>Signal ground</td>
</tr>
<tr>
<td>6</td>
<td>4</td>
<td>>DSR -&gt;&nbsp;DTR</td>
</tr>
<tr>
<td>7 + 8</td>
<td>1</td>
<td>RTS1 -&gt;&nbsp;CTS1 + CD2</td>
</tr>
</tbody>
</table>
</div>
<p><strong>Null modem with full handshaking</strong></p>
<div>
<table border="0">
<tbody>
<tr>
<td>Connector 1</td>
<td>Connector 2</td>
<td>Function</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td>Rx -&gt;&nbsp;Tx</td>
</tr>
<tr>
<td>3</td>
<td>2</td>
<td>Tx -&gt;&nbsp;Rx</td>
</tr>
<tr>
<td>4</td>
<td>6</td>
<td>DTR -&gt;&nbsp;DSR</td>
</tr>
<tr>
<td>5</td>
<td>5</td>
<td>Signal ground</td>
</tr>
<tr>
<td>6</td>
<td>4</td>
<td>DSR -&gt;&nbsp;DTR</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>RTS -&gt;&nbsp;CTS</td>
</tr>
<tr>
<td>8</td>
<td>7</td>
<td>CTS -&gt;&nbsp;RTS</td>
</tr>
</tbody>
</table>
</div>
<h2><strong>Software flow control (XOFF/XON)</strong></h2>
<p>When one end of a data link is unable to accept any more data (or approaching that point), it sends XOFF to the other end. The other end receives the XOFF code, and suspends transmission.</p>
<p>Once the first end is ready to accept data again, it sends XON, and the other end resumes transmission.</p>
<p>Requires less wiring and is slower, as sending XOFF requires at least one character time to transmit, it may be queued, has to be done in software and has the overhead of escaping the control codes so that they are not confused with data.</p>
<p><strong>XOFF/XON representations in ASCII</strong></p>
<div>
<table border="0">
<tbody>
<tr>
<td>Code</td>
<td>Meaning</td>
<td>ASCII</td>
<td>Dec</td>
<td>Hex</td>
<td>Keyboard</td>
</tr>
<tr>
<td>XOFF</td>
<td>Pause transmission</td>
<td>DC3</td>
<td>19</td>
<td>0&#215;13</td>
<td>CTRL+S</td>
</tr>
<tr>
<td>XON</td>
<td>Resume transmission</td>
<td>DC1</td>
<td>17</td>
<td>0&#215;11</td>
<td>CTRL+Q</td>
</tr>
</tbody>
</table>
</div>
<h2><strong>Hardware flow control</strong></h2>
<p>In common RS232 there are pairs of control lines:</p>
<ul>
<li><strong>RTS flow control</strong>, RTS/CTS</li>
<li><strong>DTR flow control</strong>, DTR/DSR</li>
</ul>
<p>Hardware flow control is typically handled by the DTE or &#8220;master end&#8221;, as it is first raising or asserting its line to command the other side.</p>
<div></div>
<p>In case of RTS control flow, DTE sets its RTS, which signals the opposite end (the slave end such as a DCE) to begin monitoring its data input line. When ready for data, the slave end will raise its complementary line,</p>
<p>CTS in this example, which signals the master to start sending data, and for the master to begin monitoring the slave&#8217;s data output line. If either end needs to stop the data, it lowers its respective &#8220;data readyness&#8221; line.</p>
<p>For PC-to-modem and similar links, the case of DTR flow control, DTR/DSR are raised for the entire modem session (say a dialup internet call), and RTS/CTS are raised for each block of data.</p>
<h2><strong>Testing serial ports with stty</strong></h2>
<p>Print configuration</p>

<div class="wp-terminal">user@computer:$ <br/>stty -F /dev/ttyS0 -a<br/><br/></div>

<p>Set to 38400, no flow control, one stop bit, odd parity, 8 bit, disable special characters</p>
<p>On target,</p>

<div class="wp-terminal">user@computer:$ <br/>stty -F /dev/ttyS1 speed 38400 raw -echo -echoe -echok -echoctl -echoke -cstopb -parenb -parodd cs8 -crtscts icanon<br/><br/></div>


<div class="wp-terminal">user@computer:$ <br/>cat /dev/ttyS1<br/><br/></div>

<p>On host,</p>

<div class="wp-terminal">user@computer:$ <br/>stty -F /dev/ttyS1 speed 38400 raw -echo -echoe -echok -echoctl -echoke -cstopb -parenb -parodd cs8 -crtscts icanon<br/><br/></div>


<div class="wp-terminal">user@computer:$ <br/>for x in 1 2 3 4 5; do date &gt; /dev/ttyS1;sleep 1;done<br/><br/></div>

<p>To turn on the hardware flow control, do:</p>

<div class="wp-terminal">user@computer:$ <br/>stty -F /dev/ttyS1 crtscts<br/><br/></div>


<div class="wp-terminal">user@computer:$ <br/>stty -F /dev/ttyS1 crtscts<br/><br/></div>

]]></content:encoded>
			<wfw:commentRss>http://www.lindusembedded.com/blog/2012/01/16/rs232-101/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android battery support</title>
		<link>http://www.lindusembedded.com/blog/2011/12/30/android-battery-support/</link>
		<comments>http://www.lindusembedded.com/blog/2011/12/30/android-battery-support/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 12:32:27 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.lindusembedded.com/blog/2011/12/30/android-battery-support/</guid>
		<description><![CDATA[The Android Gingerbread battery service has a JNI interface which supports a power supply class battery driver with hardcoded attributes. However, different platforms drivers may provide different attributes, so to allow for this configurability you can add platform specific system properties like: devices/&#60;manuf&#62;/&#60;platform&#62;/system.prop ro.power_supply.ac.online = online ro.power_supply.usb.online is not supported ro.power_supply.bat.status = status ro.power_supply.bat.health is [...]]]></description>
			<content:encoded><![CDATA[<p>The Android Gingerbread <a href="https://github.com/android/platform_frameworks_base/blob/master/services/java/com/android/server/BatteryService.java" target="_blank">battery service</a> has a <a href="https://github.com/android/platform_frameworks_base/blob/master/services/jni/com_android_server_BatteryService.cpp" target="_blank">JNI interface</a> which supports a power supply class battery driver with hardcoded attributes. However, different platforms drivers may provide different attributes, so to allow for this configurability you can add platform specific system properties like:<br />
<strong>devices/&lt;manuf&gt;/&lt;platform&gt;/system.prop</strong></p>
<pre>
ro.power_supply.ac.online = online
ro.power_supply.usb.online is not supported
ro.power_supply.bat.status = status
ro.power_supply.bat.health is not supported
ro.power_supply.bat.present = present
ro.power_supply.bat.capacity = capacity
ro.power_supply.bat.voltage_now = voltage_avg
ro.power_supply.bat.temperature is not supported
ro.power_supply.bat.technology = technology
</pre>
<p>And then you retrive and use each of the properties, for example.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">property_get<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;ro.power_supply.ac.online&quot;</span><span style="color: #339933;">,</span> value<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
snprintf<span style="color: #009900;">&#40;</span>path<span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>path<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s/%s/%s&quot;</span><span style="color: #339933;">,</span> POWER_SUPPLY_PATH<span style="color: #339933;">,</span> name<span style="color: #339933;">,</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>For the battery status to be updated by the Battery Service, it needs to receive a uevent from the Linux kernel driver. Verify that your battery driver does something like:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> bat_status_old <span style="color: #339933;">!=</span> bat_status.<span style="color: #202020;">status</span> <span style="color: #009900;">&#41;</span>
    power_supply_changed<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>chg_device<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>psy<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
bat_status_old <span style="color: #339933;">=</span> bat_status.<span style="color: #202020;">status</span></pre></div></div>

<p>At least on the status and capacity update functions.</p>
<p>The battery data is dumped into <strong>/data/system/batterystats.bin</strong>, a binary file that can be dumped using dumpsys.</p>

<div class="wp-terminal">user@computer:$ <br/>$~ adb shell dumpsys battery<br/>Current Battery Service state:<br/>AC powered: false<br/>AC capacity: 500000<br/>USB powered: true<br/>status: 5<br/>health: 2<br/>present: true<br/>level: 100<br/>scale: 100<br/>voltage:4201<br/>temperature: 271<br/>technology: Li-pol<br/><br/></div>

<p>Your app would need <strong>android.permission.DUMP</strong> to execute dumpsys.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lindusembedded.com/blog/2011/12/30/android-battery-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GPIO (General Purpose Input/Output) interfaces in Linux</title>
		<link>http://www.lindusembedded.com/blog/2011/12/29/gpio-general-purpose-inputoutput-interfaces-in-linux-2/</link>
		<comments>http://www.lindusembedded.com/blog/2011/12/29/gpio-general-purpose-inputoutput-interfaces-in-linux-2/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 16:19:14 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.lindusembedded.com/blog/wordpress/?p=106</guid>
		<description><![CDATA[What are GPIOs? GPIOs are very common in embedded hardware, representing pins connected to ball grid array (BGA) packages.They are commonly used to provide flexibility in System On Chip (SOC), and it is common for pins to be multiplexed and shared for different functionality. As such, GPIOs are specific to each platform and we can [...]]]></description>
			<content:encoded><![CDATA[<h2>What are GPIOs?</h2>
<p>GPIOs are very common in embedded hardware, representing pins connected to ball grid array (BGA)<br />
 packages.They are commonly used to provide flexibility in System On Chip (SOC), and<br />
 it is common for pins to be multiplexed and shared for different functionality. As such,<br />
 GPIOs are specific to each platform and we can only speak in generic terms.</p>
<p>Usually they can be used as writable output and readable inputs which can also be used<br />
 as IRQs.</p>
<h2>Generic GPIO API</h2>
<p>Linux platforms that support GPIO conventions declare GENERIC_GPIO, and drivers use the<br />
 interface in linux/gpio.h. GPIOs are identified by platform specific integer<br />
 numbers, with negative numbers being invalid.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> gpio_is_valid<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> number<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Check whether a given number is a valid GPIO.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> gpio_request<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> gpio<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>label<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Request a GPIO returning 0 on success or a negative error value.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> gpio_free<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> gpio<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Frees a previously requested GPIO.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> gpio_direction_input<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> gpio<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> gpio_direction_output<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> gpio<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Set the direction of the GPIO returning 0 on success or a negative error value.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> gpio_get_value<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> gpio<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> gpio_set_value<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> gpio<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The getter return 0 or 1 (high or low), and the setter sets 0 or 1 (high or low).</p>
<p>Most GPIO controllers are accessed withouth the need for sleep and can be safely<br />
 accessed through IRQ handlers. Some use message buses like I2C or SPI which may sleep,<br />
 and this should be accessed by the following accessors:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> gpio_get_value_cansleep<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> gpio<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> gpio_set_value_cansleep<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> gpio<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Platform code will have defined the mapping between the GPIOs and IRQs number<br />
 namespaces, so we can use the following functions to swap between them.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> gpio_to_irq<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> gpio<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> irq_to_gpio<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> irq<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Not al GPIOs can be configured as IRQs and in that case they will return a negative<br />
 errno.</p>
<h2>GPIOLIB</h2>
<p>An optional framework to support diferrent GPIO controllers (packaged as a &#8220;struct<br />
 gpio_chip&#8221;) with the same API. With debugfs available, /sys/kernel/debug/gpio lists all<br />
 registered controllers and the state of used GPIOs. The platform will define<br />
 ARCH_REQUIRE_GPIOLIB to compile the framework in, ARCH_WANT_OPTIONAL_GPIOLIB to let the<br />
 user built it into the kernel optionally, or none if GPIOLIB is not supported.</p>
<h2>SYSFS support</h2>
<p>When using GPIOLIB, a sysfs interface can be enabled to control GPIO directon and value<br />
 from userspace. The control interface lives in /sys/class/gpio.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">echo <span style="color: #0000dd;">19</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #339933;">/</span>sys<span style="color: #339933;">/</span>class<span style="color: #339933;">/</span>gpio<span style="color: #339933;">/</span>export</pre></div></div>

<p>Will create a gpio19 node and request the GPIO number 19.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">echo <span style="color: #0000dd;">19</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #339933;">/</span>sys<span style="color: #339933;">/</span>class<span style="color: #339933;">/</span>gpio<span style="color: #339933;">/</span>unexport</pre></div></div>

<p>Will free the GPIO 19.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">echo <span style="color: #ff0000;">&quot;in&quot;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #339933;">/</span>sys<span style="color: #339933;">/</span>class<span style="color: #339933;">/</span>gpio<span style="color: #339933;">/</span>gpio19<span style="color: #339933;">/</span>direction
echo <span style="color: #ff0000;">&quot;out&quot;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #339933;">/</span>sys<span style="color: #339933;">/</span>class<span style="color: #339933;">/</span>gpio<span style="color: #339933;">/</span>gpio19<span style="color: #339933;">/</span>direction</pre></div></div>

<p>Will configure it as input or output.</p>
<pre>cat /sys/class/gpio/gpio19/value
</pre>
<p>Will read from an input GPIO.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">echo <span style="color: #0000dd;">0</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #339933;">/</span>sys<span style="color: #339933;">/</span>class<span style="color: #339933;">/</span>gpio<span style="color: #339933;">/</span>gpio19<span style="color: #339933;">/</span>value
echo <span style="color: #0000dd;">1</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #339933;">/</span>sys<span style="color: #339933;">/</span>class<span style="color: #339933;">/</span>gpio<span style="color: #339933;">/</span>gpio19<span style="color: #339933;">/</span>value</pre></div></div>

<p>Will write to an output GPIO.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">echo rising <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #339933;">/</span>sys<span style="color: #339933;">/</span>class<span style="color: #339933;">/</span>gpio<span style="color: #339933;">/</span>gpio19<span style="color: #339933;">/</span>edge
echo falling <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #339933;">/</span>sys<span style="color: #339933;">/</span>class<span style="color: #339933;">/</span>gpio<span style="color: #339933;">/</span>gpio19<span style="color: #339933;">/</span>edge
echo both <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #339933;">/</span>sys<span style="color: #339933;">/</span>class<span style="color: #339933;">/</span>gpio<span style="color: #339933;">/</span>gpio19<span style="color: #339933;">/</span>edge
echo none <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #339933;">/</span>sys<span style="color: #339933;">/</span>class<span style="color: #339933;">/</span>gpio<span style="color: #339933;">/</span>gpio19<span style="color: #339933;">/</span>edge</pre></div></div>

<p>If the GPIO can be configured as IRQ,the above configure the signal edges.</p>
<p>Drivers can also make GPIOs available through sysfs using:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> gpio_export<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> gpio<span style="color: #339933;">,</span> bool direction_may_change<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> gpio_unexport<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And the following can be used to symlink to a different sysfs location to provide the<br />
 interface under a different device.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> gpio_export_link<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> device <span style="color: #339933;">*</span>dev<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>name<span style="color: #339933;">,</span><span style="color: #993333;">unsigned</span> gpio<span style="color: #009900;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.lindusembedded.com/blog/2011/12/29/gpio-general-purpose-inputoutput-interfaces-in-linux-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android user space boot up process</title>
		<link>http://www.lindusembedded.com/blog/2011/12/28/android-user-space-boot-up-process/</link>
		<comments>http://www.lindusembedded.com/blog/2011/12/28/android-user-space-boot-up-process/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 16:55:18 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.lindusembedded.com/blog/?p=513</guid>
		<description><![CDATA[The Linux kernel will launch the init process which is the parent of all othe processes in the system. Init will execute the init.rc script launching the system service processes. The first process to launch is Zygote, which will execute and initialize the Dalvik VM. The first Java component to start is the system server. [...]]]></description>
			<content:encoded><![CDATA[<p>The Linux kernel will launch the init process which is the parent of all othe processes in the system.</p>
<p>Init will execute the <strong><a href="http://www.androidenea.com/2009/08/init-process-and-initrc.html" target="_blank">init.rc</a></strong> script launching the system service processes.</p>
<p>The first process to launch is Zygote, which will execute and initialize the Dalvik VM.</p>
<p>The first Java component to start is the system server. This in turn will launch all the rest of the Android services, which will run in the System Server context.</p>
<p><a href="https://github.com/android/platform_frameworks_base/blob/master/services/java/com/android/server/SystemServer.java" target="_blank">frameworks/base/services/java/com/android/server/SystemServer.java</a></p>
<p>The server loads a native <strong>android_servers</strong> library that provides interfaces to native funcitonality.</p>
<p><a href="https://github.com/android/platform_frameworks_base/tree/master/services/jni" target="_blank">frameworks/base/services/jni/</a></p>
<p>Then <strong>init1(args)</strong>, the native init method that starts up native services is called. This is implemented in system_init in <a href="https://github.com/android/platform_frameworks_base/blob/master/cmds/system_server/library/system_init.cpp" target="_blank">frameworks/base/cmds/system_server/library/system_init.cpp</a></p>
<p>Once it finishes starting native services there is a callback to <strong>init2</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">runtime<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>callStatic<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;com/android/server/SystemServer&quot;</span>, <span style="color: #0000ff;">&quot;init2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Which then creates the server thread. Each service started by the system server runs as a separate Dalvik thread in the SystemServer process. These can be analyzed using the <a href="http://developer.android.com/guide/developing/debugging/ddms.html" target="_blank">DDMS</a> tool.</p>
<p>After the system boot has completed there is a standard broadcast <strong>android.intent.action.BOOT_COMPLETED</strong>. This can be used to <a href="http://www.androidenea.com/2009/09/starting-android-service-after-boot.html" target="_blank">start a service</a> or perform some action by an application if it includes a broadcast receiver that registers for this intent.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lindusembedded.com/blog/2011/12/28/android-user-space-boot-up-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Android property system</title>
		<link>http://www.lindusembedded.com/blog/2011/12/21/the-android-property-system/</link>
		<comments>http://www.lindusembedded.com/blog/2011/12/21/the-android-property-system/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 18:06:00 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[android]]></category>

		<guid isPermaLink="false">http://www.lindusembedded.com/blog/?p=501</guid>
		<description><![CDATA[A property is a key/value pair, both of which are of string type. Many android applications and libraries directly or indirectly relies on this feature to determine their runtime behavior. Properties are stored in a shared memory block which can only be written to by the property service process. This service, started by init, reads [...]]]></description>
			<content:encoded><![CDATA[<p>A property is a key/value pair, both of which are of string type. Many android applications and libraries directly or indirectly relies on this feature to determine their runtime behavior.</p>
<p>Properties are stored in a shared memory block which can only be written to by the property service process. This service, started by init, reads properties from persisten storage and writes them into memory.</p>
<p>To read properties a consumer process (via libcutil) loads the shared memory into its own virtual memory, using an enviromental variable called  <strong>ANDROID_PROPERTY_WORKSPACE</strong> which keeps the fd for the shared memory area and its size.</p>

<div class="wp-terminal">user@computer:$ / # echo $ANDROID_PROPERTY_WORKSPACE<br/>9,32768<br/><br/></div>

<p>To write properties a setter process will also load the shared memory into its virtual space, but will rely on a unix domain socket (<strong>/dev/socket/property_service</strong>) to tell the property service to change a property both in shared memory and in persistent storage.</p>
<p>The shared memory region is structured as follows:</p>
<pre>count
serial
magic
version
reserved[4]
toc[1]
... starts at 1024 bytes offset.
prop_info[PA_COUNT_MAX]
</pre>
<p>Where <strong>PA_COUNT_MAX</strong> is defined in <strong>system\core\init\property_service.c</strong>, and it&#8217;s 247 by default.</p>
<p>After setting up the shared memory area,the init process will load properties from following files:</p>
<pre> /default.prop
 /system/build.prop
 /system/default.prop
 /data/local.prop
</pre>
<p>Then init starts the property service and waits polling on its socket.</p>
<p>To get or set properties:</p>
<p><span style="text-decoration: underline;"><strong>Native code (linking against libcutils)</strong></span></p>
<p><span style="text-decoration: underline;"><strong></strong></span><br />
 #include &lt;cutils/properties.h&gt;<br />
 property_get/property_set</p>
<p><span style="text-decoration: underline;"><strong>Java code</strong></span></p>
<p>System.getProperty/System.setProperty functions in the java.lang library. These are Java properties, stored on a hashtable.<br />
 android.os.SystemProperties can be used to access native properties through JNI. Anyone can read them, but only the system server UID can write to them. The class is defined in&nbsp;<a href="https://github.com/android/platform_frameworks_base/blob/master/core/java/android/os/SystemProperties.java">https://github.com/android/platform_frameworks_base/blob/master/core/java/android/os/SystemProperties.java</a></p>
<p>Currently, properties can&#8217;t be removed.</p>
<p><em style="font-family: monospace; white-space: pre;">&nbsp;</em></p>
<p><em style="font-family: monospace; white-space: pre;">&nbsp;</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lindusembedded.com/blog/2011/12/21/the-android-property-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mounting a dd&#8217;ed disk</title>
		<link>http://www.lindusembedded.com/blog/2011/08/14/mounting-a-dded-disk/</link>
		<comments>http://www.lindusembedded.com/blog/2011/08/14/mounting-a-dded-disk/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 09:59:53 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.lindusembedded.com/blog/?p=181</guid>
		<description><![CDATA[When you duplicate a disk you do something like: dd if=/dev/sda of=/tmp/mydisk.dd When you receive an image file, you can check it with file: mydisk.dd: x86 boot sector; partition 1: ID=0x83, starthead 0, startsector 15128,7722844 sectors, extended partition table (last)\011, code offset 0x0 And with fdisk: fdisk -l -u mydisk.dd You must set cylinders. You [...]]]></description>
			<content:encoded><![CDATA[<p>When you duplicate a disk you do something like:</p>
<p><code>dd if=/dev/sda of=/tmp/mydisk.dd</code></p>
<p>When you receive an image file, you can check it with file:</p>
<p><code>mydisk.dd: x86 boot sector; partition 1: ID=0x83, starthead 0, startsector 15128,7722844 sectors, extended partition table (last)\011, code offset 0x0</code></p>
<p>And with fdisk:</p>
<pre>fdisk -l -u mydisk.dd

You must set cylinders.
You can do this from the extra functions menu.

Disk mydisk.dd: 0 MB, 0 bytes
122 heads, 62 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x674d869c

     Device Boot      Start         End      Blocks   Id  System
mydisk.ddp1           15128     7737971     3861422   83  Linux</pre>
<p>To mount it, you need to specify the offset of the partition you want to mount, not in sectors but in bytes. So to mount sector 15128 the offset is 15128*512:</p>
<p><code>sudo mount -o loop,offset=7745536 -t auto /my/path/mydisk.dd /mnt</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lindusembedded.com/blog/2011/08/14/mounting-a-dded-disk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Looking at the kernel log from the bootloader</title>
		<link>http://www.lindusembedded.com/blog/2011/08/10/looking-at-the-kernel-log-from-the-bootloader/</link>
		<comments>http://www.lindusembedded.com/blog/2011/08/10/looking-at-the-kernel-log-from-the-bootloader/#comments</comments>
		<pubDate>Wed, 10 Aug 2011 17:25:33 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[embedded]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Linux kernel]]></category>

		<guid isPermaLink="false">http://www.lindusembedded.com/blog/?p=464</guid>
		<description><![CDATA[Assuming you have a bootloader that doesn&#39;t overwrite memory on boot (U-Boot is one that doesn&#39;t) you can warm reset your device and have a look at the kernel&#39;s log buffer from its shell. The log is stored is: user@computer:$ grep __log_buf System.mapc047ebf8 b __log_buf To convert the virtual address to physical, you need to [...]]]></description>
			<content:encoded><![CDATA[<p>Assuming you have a bootloader that doesn&#39;t overwrite memory on boot (<a href="http://www.denx.de/wiki/U-Boot">U-Boot</a> is one that doesn&#39;t) you can warm reset your device and have a look at the kernel&#39;s log buffer from its shell.</p>
<p>The log is stored is:</p>

<div class="wp-terminal">user@computer:$ grep __log_buf System.map<br/>c047ebf8 b __log_buf<br/></div>

<p>To convert the virtual address to physical, you need to substract the kernel base. For ARM it&#39;s <a href="http://lxr.linux.no/linux+v3.0.1/arch/arm/kernel/head.S#L52">KERNEL_START</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#define KERNEL_START    KERNEL_RAM_VADDR</span></pre></div></div>

<p>And <a href="http://lxr.linux.no/linux+v3.0.1/arch/arm/kernel/head.S#L36">KERNEL_RAM_VADD</a>R:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#define KERNEL_RAM_VADDR        (PAGE_OFFSET + TEXT_OFFSET)</span></pre></div></div>

<p>With <a href="http://lxr.linux.no/linux+v3.0.1/arch/arm/Kconfig#L1377">PAGE_OFFSET</a> defined in your configuration:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">config PAGE_OFFSET
	hex
	<span style="color: #b1b100;">default</span> <span style="color: #208080;">0x40000000</span> <span style="color: #b1b100;">if</span> VMSPLIT_1G
	<span style="color: #b1b100;">default</span> <span style="color: #208080;">0x80000000</span> <span style="color: #b1b100;">if</span> VMSPLIT_2G
	<span style="color: #b1b100;">default</span> <span style="color: #208080;">0xC0000000</span></pre></div></div>

<p>And <a href="http://lxr.linux.no/linux+v3.0.1/arch/arm/Makefile#L223">TEXT_OFFSET</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;"># The byte offset of the kernel image in RAM from the start of RAM.</span>
TEXT_OFFSET <span style="color: #339933;">:=</span> $<span style="color: #009900;">&#40;</span>textofs<span style="color: #339933;">-</span>y<span style="color: #009900;">&#41;</span></pre></div></div>

<p>With&nbsp;<a href="http://lxr.linux.no/linux+v3.0.1/arch/arm/Makefile#L123"><span class="Apple-style-span" style="font-family: monospace; white-space: pre; ">textofs-y</span></a>:</p>
<p><meta content="text/html; charset=utf-8" http-equiv="content-type" /></p>
<pre lan="c">textofs-y	:= 0x00008000</pre>
<p>So KERNEL_START = 0xC0000000 + 0&#215;00008000 = 0xC0008000</p>
<p>And __log_buf = 0xc047ebf8 &#8211; 0xC0008000 = 0x00476BF8</p>
<p>So, after a warm reset you stop at the U-Boot prompt and you do:</p>
<pre>md.l 0x00476BF8
00476bf8: 00000000 00000000 00000000 00000000    ................
00476c08: 00000000 00000000 00000000 00000000    ................
00476c18: 00000000 00000000 00000000 00000000    ................
00476c28: 00000000 00000000 00000000 00000000    ................
00476c38: 00000000 00000000 00000000 00000000    ................
00476c48: 00000000 00000000 00000001 000002ee    ................
00476c58: 00000000 00000002 c0476c60 c0476c60    ........`lG.`lG.
00476c68: c02a2424 c048355c c048355c ffffaaf2    $$*.\5H.\5H.....
00476c78: c0482dc0 c02a24b4 c0476bac 00000000    .-H..$*..kG.....
00476c88: 00000007 00000000 00000000 00000000    ................
00476c98: 00000000 00000000 00000000 00000000    ................
00476ca8: dc2da048 c0499eec 00000000 0002bf20    H.-...I..... ...
00476cb8: 00000001 c04782d8 c0476d0c 00000000    ......G..mG.....
00476cc8: 00000000 00000000 00000000 00000000    ................
00476cd8: c02b7914 c02b7928 c02b782c 00000000    .y+.(y+.,x+.....
00476ce8: 00000000 00000000 00000000 00000000    ................
00476cf8: 00000000 00000000 00000000 00000000    ................
00476d08: 00000000 c0476cbc c04782d8 00000001    .....lG...G.....
00476d18: 00000000 00000000 c02b7914 c02b7928    .........y+.(y+.
00476d28: c02b782c 00000000 00000000 00000000    ,x+.............
</pre>
<p>Which is garbage.</p>
<p>However, if you ignore the TEXT_OFFSET:</p>
<p>__log_buf = 0xc047ebf8 &#8211; 0xC0000000 = 0x0047ebf8</p>
<pre>md.l 0x0047ebf8
0047ebf8: 6f695f75 3a6c7463 5d363633 5f555056    u_ioctl:366]VPU_
0047ec08: 5f434f49 474b4c43 5f455441 54544553    IOC_CLKGATE_SETT
0047ec18: 0a474e49 413e363c 765b2047 695f7570    ING.&lt;6&gt;AG [vpu_i
0047ec28: 6c74636f 3636333a 5550565d 434f495f    octl:366]VPU_IOC
0047ec38: 4b4c435f 45544147 5445535f 474e4954    _CLKGATE_SETTING
0047ec48: 3e363c0a 5b204741 5f757076 74636f69    .&lt;6&gt;AG [vpu_ioct
0047ec58: 36333a6c 50565d36 4f495f55 4c435f43    l:366]VPU_IOC_CL
0047ec68: 5441474b 45535f45 4e495454 363c0a47    KGATE_SETTING.&lt;6
0047ec78: 2047413e 7570765b 636f695f 333a6c74    &gt;AG [vpu_ioctl:3
0047ec88: 565d3636 495f5550 435f434f 41474b4c    66]VPU_IOC_CLKGA
0047ec98: 535f4554 49545445 3c0a474e 47413e36    TE_SETTING.&lt;6&gt;AG
0047eca8: 70765b20 6f695f75 3a6c7463 5d363633     [vpu_ioctl:366]
0047ecb8: 5f555056 5f434f49 474b4c43 5f455441    VPU_IOC_CLKGATE_
0047ecc8: 54544553 0a474e49 413e363c 765b2047    SETTING.&lt;6&gt;AG [v
0047ecd8: 695f7570 6c74636f 3636333a 5550565d    pu_ioctl:366]VPU
0047ece8: 434f495f 4b4c435f 45544147 5445535f    _IOC_CLKGATE_SET
0047ecf8: 474e4954 3e363c0a 5b204741 5f757076    TING.&lt;6&gt;AG [vpu_
0047ed08: 74636f69 36333a6c 50565d36 4f495f55    ioctl:366]VPU_IO
0047ed18: 4c435f43 5441474b 45535f45 4e495454    C_CLKGATE_SETTIN
0047ed28: 363c0a47 2047413e 7570765b 636f695f    G.&lt;6&gt;AG [vpu_ioc</pre>
<p>Voila!</p>
<p>If anyone has an explanation as to why I need to omit the TEXT_OFFSET in the calculation it would be welcomed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lindusembedded.com/blog/2011/08/10/looking-at-the-kernel-log-from-the-bootloader/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>

