Thursday, August 6, 2015

Booting Beagle Bone Black over UART

Hi Foks.! Welcome to my blog.

Yes, we are going to boot BBB (Beagle Bone Black) over UART, seems strange..? even I had the same opinion, but its importance is really know when you work on a new board bring up task. UART interface is very reliable and easy to configure, hence I prefer this as the best option as boot media/interface during bring up time, later we can verify other boot mechanism like boot from SPI/NAND/MMC.

Once we are at U-boot prompt we are almost done, we can chose how we want to load the kernel image and from the command line arguments we save the about file system and other extra env settings. 

To get started we need the following:
  • BeagleBoneBlack (BBB) board
  • Linux distribution based host machine ( I have Ubuntu 14.04)
  • CP2102 USB2.0 to TTL UART serial converter module.
  • 100-240V to 5V-1.0 or 2.0A  adapter/converter.
Note: With USB power BBB will not fall-back to UART boot mode, use power supply.  
Serial Connection:

Locate the 6-pin header on BBB, written as "J1" below the first pin on the PCB as show in the below picture.

 
  • J1 = GND (Ground)
  • J4 = RXD (Receive Data)
  • J5 = TXD (Transmit Data)

CP2102 USB2.0 to TTL UART serial converter

Connect J4 (RXD) to TXD line of  CP2102 USB2.0 to TTL UART serial converter
Connect J5 (TXD) to RXD line of  CP2102 USB2.0 to TTL UART serial converter
Connect J1 (GND) to GND line of  CP2102 USB2.0 to TTL UART serial converter

This makes the serial console setup ready.


Download U-Boot Source :

gvk51@gvk:~$ mkdir src
gvk51@gvk:~$ cd src
gvk51@gvk:~/src$ git clone git://git.denx.de/u-boot.git


Initialize Build Environment : 

gvk51@gvk:~$ sudo apt-get install git u-boot-tools g++ gawk lzop texinfo git-core build-essential libncurses5-dev gcc-arm-linux-gnueabi

Install all the mentioned packages for making build smooth.
 


Building the Source:

After successful installation of packages we now start building the u-boot source, for use to boot from UART we need the following images u-boot-spl.bin & u-boot.img

gvk51@gvk:~/src$ mkdir images
gvk51@gvk:~/src$ u-boot
gvk51@gvk:~/src/u-boot$ make am335x_boneblack_defconfig
gvk51@gvk:~/src/u-boot$ make -j4
gvk51@gvk:~/src/u-boot$ cp ./u-boot.img ../images/
gvk51@gvk:~/src/u-boot$ cp ./spl/u-boot-spl.bin ../images/

Booting BBB from UART:

BBB has different boots modes like boot from eMMC, uSD, serial & usb. To change the boot mode there is a switch S2, holding the boot switch down during boot without a uSD card inserted will force the boot source to be the USB port and if nothing is detected on the USB client port, it will go to the serial port for download.

Host tools for UART boot:

I have used picocom host tool to boot from serial, install it as shown below

gvk51@gvk:~$ sudo apt-get install picocom lrzsz

cd to directory where we have copied images, that is src/images folder. Assuming you have connected serial-to-usb converter, then you see a device node say /dev/ttyUSB0 on your host machine. Launch picocom from the images folder.

Commands for picocom:
  • sending a file: press Ctrl+a and then press Ctrl+s
  • exit: Ctrl+a and then press Ctrl+x
Step1: Open a terminal, issue command sudo picocom -b 115200 /dev/ttyUSB0 --send-cmd "sx -vv", you will see the following output on the console.


picocom v1.7

port is            : /dev/ttyUSB0
flowcontrol     : none
baudrate is     : 115200
parity is          : none
databits are    : 8
escape is         : C-a
local echo is    : no
noinit is          : no
noreset is        : no
nolock is         : no
send_cmd is     : sx -vv
receive_cmd is : rz -vv
imap is            :
omap is           :
emap is           : crcrlf,delbs,

Terminal ready
Step2: give key-combination (ctrl+a and ctrl+s), then you will see the following prompt,

*** file:
enter the file name u-boot-spl.bin and hit enter, you will see 

sx -vv u-boot-spl.bin
Sending u-boot-spl.bin, 570 blocks: Give your local XMODEM receive command now.

 

Step3: Now holding the boot-mode switch apply power to BBB, make sure there is no uSD & no USB cable connected. picocom starts sending the first stage boot-loader u-boot-spl.bin over UART, you will see the following output, after successful transfer you will see the character 'C' as acknowledgement from BBB.
 
Xmodem sectors/kbytes sent:   0/ 0kRetry 0: Timeout on sector ACK
Retry 0: Timeout on sector ACK
Retry 0: Got 00 for sector ACK
Retry 0: NAK on sector
Bytes Sent:  73088   BPS:304                            

Transfer complete

*** exit status: 0

U-Boot SPL 2015.07-00256-g413978d-dirty (Aug 06 2015 - 11:52:06)
C

Step4:  After you see the acknowledgement give key combination ctrl+a and ctrl+s to send the u-boot.img.

*** file:
enter the file name u-boot.img and hit enter, here you need to be patient, transfer of u-boot takes around 2-3 minutes and after successful you don't see any acknowledgement 'C' from BBB, after that wait for another 1-2 minutes to see BBB restarting and halt it at u-boot prompt by pressing a key, you will see the below log.

*** file: u-boot.img
sx -vv u-boot.img
Sending u-boot.img, 3239 blocks: Give your local XMODEM receive command now.
Xmodem sectors/kbytes sent:   0/ 0kRetry 0: NAK on sector
Bytes Sent: 414720   BPS:4480                           

Transfer complete

*** exit status: 0
xyzModem - CRC mode, 3241(SOH)/0(STX)/0(CAN) packets, 3 retries
Loaded 414700 bytes

U-Boot 2015.07-00256-g413978d-dirty (Aug 06 2015 - 11:52:06 +0530)

       Watchdog enabled
I2C:   ready
DRAM:  512 MiB
MMC:   OMAP SD/MMC: 0
Card did not respond to voltage select!
MMC init failedNet:   <ethaddr> not set. Validating first E-fuse MAC
cpsw, usb_ether
Hit any key to stop autoboot:  0
U-Boot# 

Here is the complete log of the boot sequence.

picocom -b 115200 /dev/ttyUSB0 --send-cmd "sx -vv"
picocom v1.7

port is        : /dev/ttyUSB0
flowcontrol    : none
baudrate is    : 115200
parity is      : none
databits are   : 8
escape is      : C-a
local echo is  : no
noinit is      : no
noreset is     : no
nolock is      : no
send_cmd is    : sx -vv
receive_cmd is : rz -vv
imap is        : 
omap is        : 
emap is        : crcrlf,delbs,

Terminal ready

*** file: u-boot-spl.bin
sx -vv u-boot-spl.bin 
Sending u-boot-spl.bin, 570 blocks: Give your local XMODEM receive command now.
Bytes Sent:  73088   BPS:6471                            

Transfer complete

*** exit status: 0

U-Boot SPL 2015.07-00256-g413978d-dirty (Aug 06 2015 - 11:52:06)
C
*** file: u-boot.img
sx -vv u-boot.img 
Sending u-boot.img, 3239 blocks: Give your local XMODEM receive command now.
Xmodem sectors/kbytes sent:   0/ 0kRetry 0: NAK on sector
Bytes Sent: 414720   BPS:4480                            

Transfer complete

*** exit status: 0
 xyzModem - CRC mode, 3241(SOH)/0(STX)/0(CAN) packets, 3 retries
Loaded 414700 bytes


U-Boot 2015.07-00256-g413978d-dirty (Aug 06 2015 - 11:52:06 +0530)

       Watchdog enabled
I2C:   ready
DRAM:  512 MiB
MMC:   OMAP SD/MMC: 0
Card did not respond to voltage select!
MMC init failedNet:   <ethaddr> not set. Validating first E-fuse MAC
cpsw, usb_ether
Hit any key to stop autoboot:  0 
U-Boot# 


from u-boot its always up to you from where you load the kernel and filesystem.


To boot BBB with Network File System click this link: BBB booting with NFS

Download working images of "u-boot-spl.bin", "u-boot.img" and ".config" files from this LINK

Please leave your comments, it will be encouraging :) 


27 comments:

  1. any example of bin to move the led ?

    ReplyDelete
  2. Hi Micka, are you looking for a sample code that does blinking of LED ??

    ReplyDelete
  3. Yes ! Exactly ! but the program has to be downloaded with uart0.

    ReplyDelete
  4. have you booted to Linux shell??
    or you want to do the LED control from MLO??
    give some details about your setup, so that I will try to help from my side

    ReplyDelete
  5. I've erased the emmc and I've no sdcard.
    My project is to download a program to the beaglebone black with uart0. I guess that I should use code composer studio to do it ? Do you have a sample project ? Micka,

    ReplyDelete
  6. I am not having a sample project, but I can give you some inputs.

    - I am not sure how you are going to use code composer studio to do that, may be TI has some gel files which does the configuration of the CPU am335x

    - The option I would prefer is to compile the u-boot, and then control the on board user status LEDs, USR0-3 which are connected to GPIO1_21-24 pins. Do you have the source of u-boot and able to compile it and load the images generated using UART??

    ReplyDelete
  7. Hi,
    I am trying to boot from uart. when Iexecute the commande make -j4, I have this error:

    scripts/kconfig/conf --silentoldconfig Kconfig
    CHK include/config.h
    GEN include/autoconf.mk
    GEN include/autoconf.mk.dep
    GEN spl/include/autoconf.mk
    CHK include/config/uboot.release
    CHK include/generated/timestamp_autogenerated.h
    UPD include/generated/timestamp_autogenerated.h
    CFG u-boot.cfg
    cc1: error: bad value (armv5) for -march= switch
    make: *** [u-boot.cfg] Erreur 1
    make: *** Attente des tâches non terminées....


    any help please ??

    ReplyDelete
  8. Hi Silica,

    From where you have downloaded u-boot & I understand you are building for beagle bone black, correct me if I am wrong. What is the tool chain you are using for cross compilation??

    ReplyDelete
  9. Hi,
    I have followed steps in this blog. I am using a BBB from element14. Is there any additional step that I must do?

    ReplyDelete
  10. Hi Silica,

    I tried the fresh building on a new Ubuntu machine, I came across the same issue you have mentioned.

    It was my bad that I did not mention in the post that we have to export the following:

    export CROSS_COMPILE=arm-linux-gnueabi-
    export ARCH=arm

    after this I was able to build fine. Here is build log

    vamshig@vamshig:~/src/u-boot$ make
    scripts/kconfig/conf --silentoldconfig Kconfig
    CHK include/config.h
    UPD include/config.h
    GEN include/autoconf.mk
    GEN include/autoconf.mk.dep
    GEN spl/include/autoconf.mk
    CHK include/config/uboot.release
    UPD include/config/uboot.release
    CHK include/generated/version_autogenerated.h
    UPD include/generated/version_autogenerated.h
    CHK include/generated/timestamp_autogenerated.h
    UPD include/generated/timestamp_autogenerated.h
    CC lib/asm-offsets.s
    lib/asm-offsets.c:1:0: error: bad value (armv5) for -march= switch
    /*
    ^
    make[1]: *** [lib/asm-offsets.s] Error 1
    make: *** [prepare0] Error 2
    vamshig@vamshig:~/src/u-boot$ export CROSS_COMPILE=arm-linux-gnueabi-
    vamshig@vamshig:~/src/u-boot$ make
    CHK include/config/uboot.release
    CHK include/generated/version_autogenerated.h
    UPD include/generated/version_autogenerated.h
    CHK include/generated/timestamp_autogenerated.h
    UPD include/generated/timestamp_autogenerated.h
    CC lib/asm-offsets.s
    CHK include/generated/generic-asm-offsets.h
    UPD include/generated/generic-asm-offsets.h
    CC arch/arm/lib/asm-offsets.s
    CHK include/generated/asm-offsets.h
    ....
    ....
    ....
    CC spl/lib/time.o
    CC spl/lib/uuid.o
    CC spl/lib/vsprintf.o
    CC spl/lib/panic.o
    CC spl/lib/strto.o
    LD spl/lib/built-in.o
    LDS spl/u-boot-spl.lds
    LD spl/u-boot-spl
    OBJCOPY spl/u-boot-spl-nodtb.bin
    COPY spl/u-boot-spl.bin
    MKIMAGE MLO
    CFG spl/u-boot-spl.cfg
    vamshig@vamshig:~/src/u-boot$

    ReplyDelete
  11. Hi,
    Thanks for your help. I still have a problem when sending the binary file, here is the log:
    silica@Ssilica:~/src/images$ picocom -b 115200 /dev/ttyUSB0 --send-cmd "sx-vv"
    picocom v1.7

    port is : /dev/ttyUSB0
    flowcontrol : none
    baudrate is : 115200
    parity is : none
    databits are : 8
    escape is : C-a
    local echo is : no
    noinit is : no
    noreset is : no
    nolock is : no
    send_cmd is : sx-vv
    receive_cmd is : rz -vv
    imap is :
    omap is :
    emap is : crcrlf,delbs,

    Terminal ready

    *** file: u-boot-spl.bin
    sx-vv u-boot-spl.bin
    sh: 1: sx-vv: not found

    *** exit status: 127

    ReplyDelete
  12. Hi Silica,

    Please try to install the following package, I hope this should resolve your issue.

    $ sudo apt-get install lrzsz

    ReplyDelete
  13. Hi,

    Unfortunatelly, this doesn't work. I still have the same problem. Is it related to picicom?

    ReplyDelete
  14. Hi Silica,

    I understand your u-boot is built successfully, copy the u-boot-spl.bin file to src/images path from where you are running picocom

    1) Make sure you have the file u-boot-spl.bin file @ the path ~/src/images/
    2) Now run the picocom, picocom -b 115200 /dev/ttyUSB0 --send-cmd "sx-vv"
    3) If this doesn't work try running as sudo, please let me know the status.

    ReplyDelete
  15. hey could I contact you with help with a project I have?

    ReplyDelete
  16. I have a BBB that ceased to boot. Connected an FDTI serial, and found that the board was outputting only the one-line SPL banner.

    I can UART boot another BBB purchased at the same time (these are early revs - A5B if it matters), so I know my images and the process are fine (though as documented here, there's no indication that while the SPL is uploaded using xmodem-1K, the second stage is supposed to be uploaded via ymodem, not xmodem).

    The problematic board will enter the UART boot mode, dumping out 'C' characters endlessly. I can push the spl to it, and it stops outputting 'C', but never shows the SPL banner or allows a subsequent image transfer until reset.

    I'd use JTAG, but the header and necessary adapter are not readily available. Plus I fear it would be more wasted money (the SAMTEC header would be soldered to a board which may be toast, and the kits don't appear to come with multiple headers).

    I'm suspecting the CPU memory has a fault.

    I booted it a few times probably in late 2013, then set it aside. I believe I'd updated the CLOUD9 image on the eMMC with an image from a couple months after I purchased the devices (the SPL banner shows a build date of Jun 19 2013), but it was certainly working at the time.

    Any ideas or confirmation?

    ReplyDelete
    Replies
    1. Hi Sean,

      Did you get acknowledgement 'C' after you loaded SPL ?

      I recently had a issue with BBB, which I have used it extensively, it ended up failing to boot as there was errors reading EEPROM on I2C-0 for board-IDs to do necessary pin muxing. I have modified code to stop reading from EEPROM and I have hard-coded the values to make it boot.

      Delete
  17. I have the same problem, I was following the instructions from a book, so I use mmc dev 1 and mmc erase 0 512 commands. I the unplugged the BeagleBoard and it just don't boo anymore. From UART connection I just get 'C' character 6 at a time. But no response. With picocom I can't get it to work Ctrl+Shift+a, it does nothing. Any idea or suggestion will be welcome.

    Thanks.

    ReplyDelete
    Replies
    1. When you see 'C' characters it shows board is alive. Please follow the steps I have mentioned to check if it boots over UART, please make sure you hold S2 & no micro-sd card inserted into BBB

      Delete
    2. I saw the character 'C' but I couldn't send the files to boot. Finally I was testing and I could do it by xmodem. Now it boots from UART but I want to recover my eMMC and SD card boot, I have to find out how. Any help will be appreciated.
      Thanks again!

      Delete
    3. Hi Bhaal, good to here you are able to boot. For micro SD boot, download the latest images from beaglebone.org flash your uSD, when you power up the board hold down the boot-button which is just above the microSD slot. Please check this link http://www.armhf.com/boards/beaglebone-black/bbb-sd-install/

      Delete
  18. I was trying Yocto deployment tool to learn how to develop an embeddded linux.

    ReplyDelete
    Replies
    1. Hi Bhaal, may be year or two back I have tried Yocto & Openwrt on Panda board, but not on BBB. When I get some time on this I will try and be in touch with you to share knowledge.

      Delete
  19. ctrl A is not working in my picocom?

    /images$ sudo picocom -b 115200 /dev/ttyUSB0 --send-cmd "sx-vv"
    picocom v1.7

    port is : /dev/ttyUSB0
    flowcontrol : none
    baudrate is : 115200
    parity is : none
    databits are : 8
    escape is : C-a
    local echo is : no
    noinit is : no
    noreset is : no
    nolock is : no
    send_cmd is : sx-vv
    receive_cmd is : rz -vv
    imap is :
    omap is :
    emap is : crcrlf,delbs,

    Terminal ready

    ReplyDelete
  20. Hi ! I have a problem to download with U-BOOT wiht UART. I follow instructions. I compile succesfully. I send u-boot-spl.bin succesfully but when I send u-boot.img it failled.If I use your Download working images of "u-boot-spl.bin", "u-boot.img" and ".config" files from this LINK, everithing work succesfully. Can you hel me

    Please check it:



    Bytes Sent: 76672 BPS:4438

    Transfer complete

    *** exit status: 0 ***

    U-Boot SPL 2019.01-rc3 (Jan 08 2019 - 11:26:24 -0500)
    Trying to boot from UART
    CCCCCC
    *** file: u-boot.img
    $ sx -vv u-boot.img
    Sending u-boot.img, 3265 blocks: Give your local XMODEM receive command now.
    Xmodem sectors/kbytes sent: 0/ 0kRetry 0: NAK on sector
    Xmodem sectors/kbytes sent: 2676/334kRetry 0: NAK on sector
    Retry 0: Cancelled

    Transfer incomplete

    *** exit status: 128 ***

    ReplyDelete