pcDuino U-boot

来源:互联网 发布:如何定制淘宝客app 编辑:程序博客网 时间:2024/06/05 17:41

原文出处:http://www.the-greathouses.net/blog/category/pcduino/   该文章主要讲述使用串口连接pcduino,然后再启动时进入到U-BOOT,修改U-BOO环境参数以使板子挂载SD卡的分区作为文件系统,原文作者使用dosfstools来设置SD卡分区的文件系统类型,使用rsync拷贝系统文件,另外由于U-boot环境参数修改后无法保存,原文作者修改了u-boot-sunxi使其能在pcduino中使用,使用该修改过的u-boot-sunxi可导出导入保存在nand中的环境参数。另外原文作者没有说明分区问题,本人在试验的时候使用自带的fdisk工具对SD进行分区。


Part I


This evening I decided it was time to check out the boot loader and boot command options on the pcDuino. To access the serial port on the J5 debug port I used aSparkfun FTDI Basic Breakout-3.3v — a simple to use logic level serial to USB interface. With the power off and the FTDI Basic disconnected from the computer, I connected the serial lines and ground.
DebugHookup


Connections


pcDuiono J5 PinFTDI BasicDescription1 – RX3 – TXOpcDuino to FTDI serial data2 – GND6 – GNDcommon signal reference3 – TX2 – RXIFTDI to pcDuino serial data

After double checking the connections, I plugged the FTDI Basic into my Windows laptop computer. After confirming the port assignment, I usedTeraTerm to open the serial port on my computer. The serial communication configuration needed to be set for 115200 Baud, 8-bit, No parity, 1 stop bit, no flow control, and the serial port assigned by Windows to the FTDI Basic.


Power On and Boot


After applying power to the pcDuino, the bootloader (U-Boot) startup sequence showed in the terminal window, followed by the familiar Linux boot messages as the kernel was loaded and Linux started. Surprisingly, at the end of the Linux boot, I was presented with aroot prompt. Instead of presenting a login prompt, the debug port goes directly to a root shell. This I will need to change!

[  12.776652]Freeinginit memory:5108K/dev/nandde2fsck1.42.7(21-Jan-2013)/dev/nandd:clean,60026/96000files,314839/384000blocks[  12.837041]EXT3-fs(nandd):usinginternal journal[  12.842051]kjournaldstarting.  Commitinterval5seconds[  12.847559]EXT3-fs(nandd):mountedfilesystem withordereddata mode[  13.098102]setto DVI mode[  13.101848]get_hdmi_mode==DVI[  13.140992]hostnameused greateststackdepth:5648bytes left[  13.200950]hwclockused greateststackdepth:5592bytes left[  13.253305]plymouthdused greateststackdepth:5208bytes left[  13.262105]init:ureadahead main process(71)terminatedwith status5[  13.685501]dfused greateststackdepth:5168bytes left[  13.708732]grepused greateststackdepth:4960bytes left *StartingNTP serverntpd                                                    Welcome to Linaro 12.11(GNU/Linux3.0.8+armv7l) *Documentation:  https://wiki.linaro.org/                                                                        [OK][  20.106130]android_usb:alreadydisabledroot@ubuntu:~#


U-Boot Fun


Now for the real reason I wanted to try this. Access to U-Boot and the boot command line.

In the serial terminal window, I rebooted the pcDuino…

root@ubuntu:~# shutdown -r nowroot@ubuntu:~#Broadcast message from root@ubuntu        (/dev/ttyS0)at19:14... The systemisgoing down forrebootNOW!*Askingall remainingprocessestoterminate...                        [OK]*Allprocesses endedwithin1seconds....                              [OK]nm-dispatcher.action:Caughtsignal15,shutting down...nm-dispatcher.action:Disconnectedfrom thesystembus,exiting.*Deconfiguringnetwork interfaces...                                  [OK]*Unmountingtemporary filesystems...                                  [OK]*Deactivatingswap...                                                  [OK]*Unmountinglocal filesystems...                                      [OK]umount:/run/lock:notmounted*Willnow restart[  631.725545]Restartingsystem.

… and interrupted the U-Boot start up by pressing the space bar at the “Hit any key to stop autoboot” prompt.

HELLO!BOOT0is starting!boot0 version :1.5.0dram size =1024Succeed in opening nand flash.Succeed in reading Boot1 file head.The sizeofBoot1 is0x00056000.The filestoredin 0X00000000of block 2isperfect.Check is correct.Ready to disable icache.Succeed in loading Boot1.Jump to Boot1.[      0.181]boot1 version: 1.5.0[      0.181]pmu type =3[      0.182]bat vol =0[      0.213]axi:ahb:apb=3:2:2[      0.213]set dcdc2=1400,clock=1008successed[      0.215]key[      0.227]no key found[      0.227]flash init start[      0.239]flash init finish[      0.241]fs init ok[      0.242]fattype FAT16[      0.242]fs mount ok[      0.247]script finish[      0.249]power finish[      0.257]BootMain start[      0.257]0[      0.272]usbdc_vol =4000,usbdc_cur =0[      0.272]usbpc_vol =4000,usbpc_cur =0[      0.275]init to usbpc[      0.278]set pc[      0.368]power_start=0x00000002[      0.368]pre sys mode[      0.368]startup status= -1[      0.371]key value =0[      0.374]unable to findrecovery_key key_maxvalue[      0.382]test for multios boot withdisplay[      1.006]show pic finish[      1.006]load kernel start[      1.024]load kernel successed[      1.024]start address= 0x4a000000[      1.026]power exit detect[ U-Boot2011.09-rc1-svn62(Feb01 2013-22:20:45)AllwinnerTechnology CPU:  SUNXIFamilyBoard:A10-EVBDRAM:  512MiBNAND:  1900MiBIn:    serialOut:  serialErr:  serial--------fastbootpartitions---------totalpartitions:5--name-        -start-      -size-bootloader  :1000000      2000000env        :3000000      1000000boot        :4000000      1000000rootfs      :5000000      5dc00000UDISK      :62c00000      14000000-----------------------------------no miscpartitionisfoundHit any key tostopautoboot:  0sunxi#

Greeted by the U-Boot prompt. No to check for what commands are available for modifying the environment using thehelp command.

sunxi#help?      -alias for 'help'base    -printor set address offsetboot    -bootdefault,i.e.,run'bootcmd'boota  -boota  -boot android bootimgfrommemory bootd  -boot default,i.e.,run'bootcmd'bootm  -boot application imagefrommemorycmp    -memory comparecp      -memorycopycrc32  -checksum calculationenv    -environmenthandling commandsexit    -exitscriptfalse  -donothing,unsuccessfullyfastboot-fastboot-use USB Fastbootprotocol fatdown-download data toados filesystemfatinfo-print information aboutfilesystemfatload-load binary filefromados filesystemfatls  -list files inadirectory(default/)go      -startapplication ataddress'addr'help    -printcommand description/usagekey_test-Testthe keyvalueand dump key registersloop    -infiniteloop onaddressrangemd      -memorydisplaymm      -memorymodify(auto-incrementingaddress)mmc    -MMC sub systemmmcinfo-display MMC infomtest  -simple RAM read/writetestmw      -memorywrite(fill)nand    -NANDsub-systemnboot  -boot from NANDdevicenm      -memorymodify(constantaddress)printenv-printenvironment variablesreset  -Perform RESET ofthe CPUrun    -run commands inan environment variablesaveenv-save environment variablestopersistentstoragesetenv  -setenvironment variablesshowvar-print local hushshellvariablessunxi_flash-sunxi_flashsub-systemtest    -minimaltest like/bin/shtrue    -donothing,successfullyversion-print monitor,compilerandlinker versionsunxi#

Current environment settings.

sunxi#env printboot_fastboot=fastbootboot_normal=fatloadnand00x48000000uImage;bootm0x48000000boot_recovery=nandread40007800recovery;boota40007800bootargs=console=ttyS0,115200root=/dev/nanddinit=/initloglevel=8rootfstype=ext4rootwaitbootcmd=runsetargsload1 boot_normalbootdelay=3console=ttyS0,115200fastboot_key_value_max=0x8fastboot_key_value_min=0x2init=/initload1=fatloadnand043000000evb.binloglevel=8mmc_root=/dev/mmcblk0p7nand_root=/dev/nanddpartitions=nanda@boot:nandb@rootfs:nandc@UDISKrecovery_key_value_max=0x13recovery_key_value_min=0x10setargs=setenvbootargsconsole=${console}root=${nand_root}init=${init}loglevel=${loglevel}stderr=serialstdin=serialstdout=serial Environmentsize:749/131068bytessunxi#

Interesting. By default, the A10 settins are loaded to memory from evb.bin and the kernel is loaded fromuImage from the NAND flash/boot partition. The default kernel command line sets/root to the NAND flash root partition. Then off it goes.


Part II


In Part 1 I described connecting to the pcDuino 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.


Configuring the SD Card


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.If you are attempting this, the following steps will result in a loss of all data already on an SD card.

For some of the steps below, additional software needed to be installed on the pcDuino. For formatting a DOS FAT partition, thedosfstools package must be installed. For copying the files between filesystems, I use thersync package.


sudo apt-get updatesudo apt-get install-ydosfstoolssuod apt-get install-yrsync

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’m lazy, so I just ask the system to unmount every thing accociated with the SD card slot. The redirection to /dev/null is to avoid error messages I would just ignore.

formin/dev/mmcblk0*;dosudo umount $m>/dev/null2>/dev/null;done

Next, the new partitions need defined. I set my card up with a small (16MB) FAT partition for future use as a/boot 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.

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.

mkfs.vfat/dev/mmcblk0p1mkfs.ext4/dev/mmcblk0p2

With the new file systems on the card, I needed to make certain they were not automatically mounted.

formin/dev/mmcblk0*;dosudo umount $m>/dev/null2>/dev/null;done

Then, the file systems were copied. Starting with the /boot partition

sudo mount /dev/mmcblk0p1/mntsudo mount /dev/nanda/bootsudo rsync -aqPx-H--numeric-ids/boot//mntsudo umount /mntsudo umount /boot

And the root / file system

sudo mount /dev/mmcblk0p2/mntsudo rsync -aqPx-H--numeric-ids//mntsudo umount /mnt


Testing the SD card image


To test, I rebooted the system with the serial debug output connected to my lap top as I described inPart 1 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.

setenv nand_root /dev/mmcblk0p2boot

After booting, it was necessary to check if the root / was being used from the SD card.

df-hFilesystem      Size  UsedAvailUse%Mountedon/dev/mmcblk0p2  15G  1.4G  13G  10%/...

CONFIRMED: The pcDuino will boot to an alternate root file system. All that’s needed now is to make it permanent.


Setting a permanent new root file system


Time to reboot the system and back into U-Boot to make the environment change permanent. Thesaveenv 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.

setenv nand_root /dev/mmcblk0p2saveenvboot

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.

sudo reboot...df-hFilesystem      Size  UsedAvailUse%Mountedon/dev/nandd      1.9G  1.2G  700M  63%/...

FAILURE! The changes are not persistent. The saveenv did not work. No errors were displayed, but the environment was not updated.


Postmortem


After a detailed investigation, I concluded the saveenv 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 Part 3 and a workable solution will be presented. Stay tuned!



Part III


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 newerboot.scr oruEnv.txt extensions. The newer U-Boot versions available onlinux-sunxi are not compatible with the pcDuino. I also tried thefw_printenv andfw_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 usingsetenv 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-supportedioctl error output fromfw_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.

sudo apt-get install-ywgetwget http://www.the-greathouses.net/files/u-boot-pcduino-env.tgztar xzvfu-boot-pcduino-env.tgzcdu-boot-pcduino-envmake

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

sudo make install

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


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!





原创粉丝点击