{"id":284,"date":"2013-03-14T13:41:42","date_gmt":"2013-03-14T17:41:42","guid":{"rendered":"http:\/\/www.the-greathouses.net\/blog\/?p=284"},"modified":"2014-01-12T10:10:06","modified_gmt":"2014-01-12T15:10:06","slug":"pcduino-u-boot-part-2","status":"publish","type":"post","link":"https:\/\/www.the-greathouses.net\/blog\/2013\/03\/pcduino-u-boot-part-2\/","title":{"rendered":"pcDuino U-Boot &#8211; Part 2"},"content":{"rendered":"<p>In <a href=\"http:\/\/www.the-greathouses.net\/blog\/2013\/03\/pcduino-u-boot-part-1\/\" ><strong>Part 1<\/strong><\/a> I described connecting to the <a href=\"https:\/\/www.sparkfun.com\/products\/11712\" title=\"pcDuino at Sparkfun\" target=\"_blank\">pcDuino<\/a> serial port and accessing the U-Boot subsystem. With this access to the boot environment, the task of booting to a root file system other than the NAND flash looked promising.<!--more--><\/p>\n<h6>Configuring the SD Card<\/h6>\n<p>The pcDuino accepts a micro-SD card (I just refer to it as SD to save typing) for additional storage. It is best to partition and format the card with a Linux file system for use on the pcDuino. <strong>If you are attempting this, the following steps will result in a loss of all data already on an SD card.<\/strong><\/p>\n<p>For some of the steps below, additional software needed to be installed on the pcDuino. For formatting a DOS FAT partition, the <em>dosfstools<\/em> package must be installed. For copying the files between filesystems, I use the <em>rsync<\/em> package.<\/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=\"Required software packages\" >sudo apt-get update\r\nsudo apt-get install -y dosfstools\r\nsuod apt-get install -y rsync<\/pre>\n<p>First, the SD card must be inserted in the card slot and partitioned. By default, the pcDuino will attempt to automatically mount the SD card partitions, so these partitions must be unmounted after inserting the card. I&#8217;m lazy, so I just ask the system to unmount every thing accociated with the SD card slot. The redirection to <em>\/dev\/null<\/em> is to avoid error messages I would just ignore.<\/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=\"Unmounting partitiions\" >for m in \/dev\/mmcblk0* ; do sudo umount $m >\/dev\/null 2>\/dev\/null ; done<\/pre>\n<p>Next, the new partitions need defined. I set my card up with a small (16MB) FAT partition for future use as a <em>\/boot<\/em> file system, and used the remaining space for the root file system. The pcDuino desktop DiskManager allows the formatting to be done from from a graphical interface. Or, as I prefer, the fdisk command line application can be used.<\/p>\n<p>Once the partitions are created, the file systems need to be created, mounted, and a copy of the existing operating system copied to the corresponding locations. For my configuration, the following commands were used to accomplish this task.<\/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=\"Create file systems\" >mkfs.vfat \/dev\/mmcblk0p1\r\nmkfs.ext4 \/dev\/mmcblk0p2<\/pre>\n<p>With the new file systems on the card, I needed to make certain they were not automatically mounted.<\/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=\"Unmounting partitiions\" >for m in \/dev\/mmcblk0* ; do sudo umount $m >\/dev\/null 2>\/dev\/null ; done<\/pre>\n<p>Then, the file systems were copied. Starting with the <em>\/boot<\/em> partition<\/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=\"Copy \/boot\" >sudo mount \/dev\/mmcblk0p1 \/mnt\r\nsudo mount \/dev\/nanda \/boot\r\nsudo rsync -aqPx -H --numeric-ids \/boot\/ \/mnt\r\nsudo umount \/mnt\r\nsudo umount \/boot<\/pre>\n<p>And the root <em>\/<\/em> file system<\/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=\"Copy \/\" >sudo mount \/dev\/mmcblk0p2 \/mnt\r\nsudo rsync -aqPx -H --numeric-ids \/ \/mnt\r\nsudo umount \/mnt<\/pre>\n<h6>Testing the SD card image<\/h6>\n<p>To test, I rebooted the system with the serial debug output connected to my lap top as I described in <a href=\"http:\/\/www.the-greathouses.net\/blog\/2013\/03\/pcduino-u-boot-part-1\/\" target=\"_blank\"><strong>Part 1<\/strong><\/a> and entered into the U-Boot command line. From the U-Boot prompt, I set the default root device to my root partition on the SD card and booted.<\/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=\"U-Boot test\" >setenv nand_root \/dev\/mmcblk0p2\r\nboot<\/pre>\n<p>After booting, it was necessary to check if the root <em>\/<\/em> was being used from the SD card.<\/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=\"Check root file system\" >df -h\r\nFilesystem      Size  Used Avail Use% Mounted on\r\n\/dev\/mmcblk0p2   15G  1.4G   13G  10% \/\r\n...<\/pre>\n<p><strong>CONFIRMED:<\/strong> The pcDuino will boot to an alternate root file system. All that&#8217;s needed now is to make it permanent.<\/p>\n<h6>Setting a permanent new root file system<\/h6>\n<p>Time to reboot the system and back into U-Boot to make the environment change permanent. The <em>saveenv<\/em> command is used to permanently write environment changes to non-volatile storage. In the case of the pcDuino the environment is saved to a specific NAND flash area.<\/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=\"U-Boot update\" >setenv nand_root \/dev\/mmcblk0p2\r\nsaveenv\r\nboot<\/pre>\n<p>No errors were displayed, and a check of the mounted file systems showed the SD card was being used for the root file system. Time for the critical test. Reboot without entering U-Boot to confirm the change is permanent.<\/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=\"Final test\" >sudo reboot\r\n...\r\ndf -h\r\nFilesystem      Size  Used Avail Use% Mounted on\r\n\/dev\/nandd      1.9G  1.2G  700M  63% \/\r\n...\r\n<\/pre>\n<p><strong>FAILURE!<\/strong> The changes are not persistent. The <em>saveenv<\/em> did not work. No errors were displayed, but the environment was not updated.<\/p>\n<h6>Postmortem<\/h6>\n<p>After a detailed investigation, I concluded the <em>saveenv<\/em> was non-functional in the pcDuino U-Boot version. The NAND flash write routines are not present or operational. More details of the investigation into alternatives for controlling the boot process will be in <a href=\"http:\/\/www.the-greathouses.net\/blog\/2013\/03\/pcduino-u-boot-part-3\/\" title=\"pcDuino U-Boot - Part 3\"><strong>Part 3<\/strong><\/a> and a workable solution will be presented. Stay tuned!<\/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> Add information for installing <em>dosfstools<\/em> and <em>rsync<\/em> packages.<\/p>\n","protected":false},"excerpt":{"rendered":"In Part 1 I described connecting to the pcDuino serial port and accessing the U-Boot subsystem. With this access to &hellip;<a href=\"https:\/\/www.the-greathouses.net\/blog\/2013\/03\/pcduino-u-boot-part-2\/\">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":[],"class_list":["post-284","post","type-post","status-publish","format-standard","hentry","category-computers","category-pcduino"],"_links":{"self":[{"href":"https:\/\/www.the-greathouses.net\/blog\/wp-json\/wp\/v2\/posts\/284","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=284"}],"version-history":[{"count":17,"href":"https:\/\/www.the-greathouses.net\/blog\/wp-json\/wp\/v2\/posts\/284\/revisions"}],"predecessor-version":[{"id":376,"href":"https:\/\/www.the-greathouses.net\/blog\/wp-json\/wp\/v2\/posts\/284\/revisions\/376"}],"wp:attachment":[{"href":"https:\/\/www.the-greathouses.net\/blog\/wp-json\/wp\/v2\/media?parent=284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.the-greathouses.net\/blog\/wp-json\/wp\/v2\/categories?post=284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.the-greathouses.net\/blog\/wp-json\/wp\/v2\/tags?post=284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}