{"id":303,"date":"2013-03-14T22:41:12","date_gmt":"2013-03-15T02:41:12","guid":{"rendered":"http:\/\/www.the-greathouses.net\/blog\/?p=303"},"modified":"2014-01-12T10:09:55","modified_gmt":"2014-01-12T15:09:55","slug":"pcduino-u-boot-part-3","status":"publish","type":"post","link":"https:\/\/www.the-greathouses.net\/blog\/2013\/03\/pcduino-u-boot-part-3\/","title":{"rendered":"pcDuino U-Boot &#8211; Part 3"},"content":{"rendered":"<p>In <a href=\"http:\/\/www.the-greathouses.net\/blog\/2013\/03\/pcduino-u-boot-part-1\/\" title=\"pcDuino U-Boot - Part 1\"><strong>Part 1<\/strong><\/a> and <a href=\"http:\/\/www.the-greathouses.net\/blog\/2013\/03\/pcduino-u-boot-part-2\/\" title=\"pcDuino U-Boot - Part 2\"><strong>Part 2<\/strong><\/a> of this series of posts I outlined the attempts I have made at using U-Boot to control the booting of the pcDuino. Specifically, I have been trying to configure the second stage boot to be from my SD card instead of the on board NAND flash. Unfortunately, the U-Boot implementation as installed does not allow persistent setting of the environment for boot from an alternative interface. And the installed U-Boot does not support the newer <em>boot.scr<\/em> or <em>uEnv.txt<\/em> extensions. The newer U-Boot versions available on <a href=\"https:\/\/github.com\/linux-sunxi\/u-boot-sunxi\/\" target=\"_blank\" title=\"Allwinner A1x native u-boot support\">linux-sunxi<\/a> are not compatible with the pcDuino. I also tried the <em>fw_printenv<\/em> and <em>fw_setenv<\/em> U-Boot tools, but they only work with \/dev\/mtdX NAND configurations. I was not able to find a ready made solution, so I had to roll my own.<!--more--><\/p>\n<h6>The U-Boot environment<\/h6>\n<p>The U-Boot environment is stored as simple list of strings in non-volatile memory with a 32-bit CRC added for validating the memory content. Typically, to modify the environment, a user will interrupt the boot process and access the U-Boot command line prompt. This can be made available on a serial port, or in some cases, on the main console. Once there is access to the U-Boot command line, it is only necessary to update the existing environment using <em>setenv<\/em> and then save the updates back to non-volatile memory using <em>saveenv<\/em>. For the pcDuino, the environment is stored in the NAND flash and should be updated with the new settings. The NAND flash update is not implemented. There are no error messages displayed, the environment is just not saved.<\/p>\n<p>This led me to investigating where the environment is stored on the pcDuino. This was not hard to determine with a quick check of the pcDuino NAND file systems. The U-Boot environment is stored in the second NAND partition &#8212; \/dev\/nandb &#8212; as viewed from the Linux environment. Nothing special formatting is performed on the partition, it is treated as a raw data area, with the environment stored as 128K bytes of data starting at the beginning.<\/p>\n<p>Now that I had the location of the environment, I thought should be able to use the default tools available with U-Boot to update this area. I proceeded to fetch the full source package for U-Boot from linux-sunxi and compiled the U-Boot tools without any problems.  I then proceeded to try <em>fw_printenv<\/em> to confirm access to the environment. <\/p>\n<p>That&#8217;s when my problems started with the tools. First, I had to create a <em>fw_env.config<\/em> file in the <em>\/etc<\/em> directory. No problem, I just copied the sample and tried again. Next problem&#8230; no <em>\/dev\/mtdX<\/em> devices were found. That&#8217;s right. On the pcDuion, the NAND flash provides file system mapping via the <em>\/dev\/nandX<\/em> devices. Should be a simple matter of updating the <em>\/etc\/fw_env.config<\/em> file. Right? No. I updated the configuration, and tried again. This time I had a non-supported <em>ioctl<\/em> error output from <em>fw_printenv<\/em>.<\/p>\n<p>Time to look at the source code and find out how to make this work with the pcDuino. To make a long story short, the U-Boot supplied tools are centered around the <em>\/dev\/mtd<\/em> NAND flash implementation. It would not be a simple matter to update them in a compatible manner for supporting the pcDuino. My decision was to create my own tools specifically for the pcDuino.<\/p>\n<h6>U-Boot tools for pcDuino<\/h6>\n<p>After deciding I needed to write my own tools, I had a working prototype in less than 30 minutes. The most complicated portion of the code was calculating the CRC-32 and I was able to find existing code for that task. This was fine for me, but I knew there was additional interest in the pcDuino community. I added some error handling and default modes to the code and am making it available for general use. <strong>Read the warning at the end of this post!<\/strong><\/p>\n<p>Here are the files for setting your environment on the pcDuino. Extract to a directory on your pcDuino and follow the instructions in the include README.txt file. I am distributing as a source package that you will need to compile on your system. I am assuming that anyone who wants to try this does have some basic Linux skills.<\/p>\n<p>Download the file from here: <a href=\"http:\/\/www.the-greathouses.net\/files\/u-boot-pcduino-env.tgz\" title=\"U-Boot pcDuino Tools\">u-boot-pcduino-env.tgz<\/a><\/p>\n<p>Quick instructions for downloading, installing, compiling and using from the command line. <\/p>\n<pre class=\"theme:terminal striped:false marking:false nums:false nums-toggle:false wrap-toggle:false plain:false plain-toggle:false lang:default decode:true \" title=\"pcDuino tools for U-Boot \" >sudo apt-get install -y wget\r\nwget http:\/\/www.the-greathouses.net\/files\/u-boot-pcduino-env.tgz\r\ntar xzvf u-boot-pcduino-env.tgz\r\ncd u-boot-pcduino-env\r\nmake<\/pre>\n<p>After building the tools, you can run them from the build directory or install to \/usr\/local\/bin using:<\/p>\n<pre class=\"theme:terminal striped:false marking:false nums:false nums-toggle:false wrap-toggle:false plain:false plain-toggle:false lang:default decode:true \" title=\"Install to \/usr\/local\/bin\" >sudo make install<\/pre>\n<p>Refer to my previous posting (<a href=\"http:\/\/www.the-greathouses.net\/blog\/2013\/03\/pcduino-u-boot-part-2\/\" title=\"pcDuino U-Boot - Part 2\"><strong>Part 2<\/strong><\/a>) for setting up an SD card partition for use as your root partition.<\/p>\n<p><strong>TODO:<\/strong> Add instructions for compiling and running my U-Boot tools for the pcDuino.<br \/>\nEnjoy!<br \/>\nBill<\/p>\n<h6><span style=\"color: #ff0000;\">WARNING<\/span><\/h6>\n<p><strong>ONLY TRY THE ABOVE IF YOU UNDERSTAND WHAT YOU ARE DOING. Connecting to the serial debug port has the potential to damage your pcDuino if your connections are incorrect. Changes to the U-Boot environment can render your pcDuino unbootable. YOU HAVE BEEN WARNED!<\/strong><\/p>\n<p><strong>Update 15-Mar-2013:<\/strong>Description of how I updated the U-Boot environment and instructions for using the required software.<\/p>\n","protected":false},"excerpt":{"rendered":"In Part 1 and Part 2 of this series of posts I outlined the attempts I have made at using &hellip;<a href=\"https:\/\/www.the-greathouses.net\/blog\/2013\/03\/pcduino-u-boot-part-3\/\">Continue reading &rarr;<\/a>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,35],"tags":[38,32,30],"class_list":["post-303","post","type-post","status-publish","format-standard","hentry","category-computers","category-pcduino","tag-cooking-3","tag-custom-boot","tag-u-boot"],"_links":{"self":[{"href":"https:\/\/www.the-greathouses.net\/blog\/wp-json\/wp\/v2\/posts\/303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.the-greathouses.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.the-greathouses.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.the-greathouses.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.the-greathouses.net\/blog\/wp-json\/wp\/v2\/comments?post=303"}],"version-history":[{"count":15,"href":"https:\/\/www.the-greathouses.net\/blog\/wp-json\/wp\/v2\/posts\/303\/revisions"}],"predecessor-version":[{"id":375,"href":"https:\/\/www.the-greathouses.net\/blog\/wp-json\/wp\/v2\/posts\/303\/revisions\/375"}],"wp:attachment":[{"href":"https:\/\/www.the-greathouses.net\/blog\/wp-json\/wp\/v2\/media?parent=303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.the-greathouses.net\/blog\/wp-json\/wp\/v2\/categories?post=303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.the-greathouses.net\/blog\/wp-json\/wp\/v2\/tags?post=303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}