Home » Computers, pcDuino » pcDuino U-Boot – Part 3
Mar
14

In Part 1 and Part 2 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 boot.scr or uEnv.txt extensions. The newer U-Boot versions available on linux-sunxi are not compatible with the pcDuino. I also tried the fw_printenv and fw_setenv 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.

The U-Boot environment

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 setenv and then save the updates back to non-volatile memory using saveenv. 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.

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 — /dev/nandb — 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.

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 fw_printenv to confirm access to the environment.

That’s when my problems started with the tools. First, I had to create a fw_env.config file in the /etc directory. No problem, I just copied the sample and tried again. Next problem… no /dev/mtdX devices were found. That’s right. On the pcDuion, the NAND flash provides file system mapping via the /dev/nandX devices. Should be a simple matter of updating the /etc/fw_env.config file. Right? No. I updated the configuration, and tried again. This time I had a non-supported ioctl error output from fw_printenv.

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 /dev/mtd 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.

U-Boot tools for pcDuino

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. Read the warning at the end of this post!

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.

Download the file from here: u-boot-pcduino-env.tgz

Quick instructions for downloading, installing, compiling and using from the command line.

After building the tools, you can run them from the build directory or install to /usr/local/bin using:

Refer to my previous posting (Part 2) for setting up an SD card partition for use as your root partition.

TODO: Add instructions for compiling and running my U-Boot tools for the pcDuino.
Enjoy!
Bill

WARNING

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!

Update 15-Mar-2013:Description of how I updated the U-Boot environment and instructions for using the required software.

, ,

3 Responses to “pcDuino U-Boot – Part 3”

  1. April 1st, 2013 at 12:14 | #1

    There is a nand compatible bootloader branch that you might have used.

    You may want to see if it works or not for you anyway.

    https://github.com/TheSeven/u-boot-sunxi

    I’d be interested if it works or not. Don’t have a pcduino to test with though.

  2. April 1st, 2013 at 13:19 | #2

    This is a clone of the same U-Boot version I have worked with. The u-boot-sunxi bootloader branch that supports reading the A10 implemented NAND flash, does not support writing. If you examine the sources in nand_spl you will notice there are no routines for writing back to the NAND flash.

    Thank you and enjoy!
    Bill

Add reply