This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Customizing U-Boot



Hello,

I am currently working with the AM335x Evaluation board, and would like to know where does U-Boot get all the necessary parameters for initializing the system. I did read through few documents which indicate that there is a 2 stage loading. The X-loader which is based on a strip down version of U-Boot gets loaded first (also called the SPL) and then the U-boot is loaded by this X-loader into RAM and it executes from RAM.

1. Are there documents that clearly indicate which peripherals are initialized by the X-loader and which are initialized by the U-boot?

2. What are the specific functions of U-boot and X-loader, how to build drivers for only those peripherals that are needed?

When I go through the forum everyone seems to have already passed the first two stages, which tells me that I may be missing something trivial. Are there documents that clearly mention how to do these and I haven't read them??

Thanks in advance for your replies.

Regards

Santhosh

  • the most important job of x-load is to initialize external SDRAM because uboot is too big to fit in On Chip Memory. Other than that xload also initializes pin mux and some clock domains.

  • Hi Santosh,

    In general the job of Secondary stage loader (SPL/X-loader), is to setup the minimum level, like setting up the pll controllers, setting up the DDR, etc and load the U-boot Image to RAM and final jump to U-boot. Even before SPL the RBL comes up when you turn on the switch first and tries to load the second stage loader.

    And the job U-boot in general is to setup the flashes, EMAC , load the linux image to RAM and jump to this address finally. For AM335XX I can see the SPL code for it is present in the U-boot source refer this link http://processors.wiki.ti.com/index.php/AMSDK_u-boot_User%27s_Guide#Compiling_MLO_and_u-boot

    Thx,

    --Prabhakar Lad

    http://in.linkedin.com/pub/prabhakar-lad/19/92b/955

  • Hello Prabhakar, Mayank,

    Thank you for the quick response, I see that I should have given more information about the situation. I have read through the document links you have posted. I am mainly interested in finding out which files I need to edit and/or read through to understand how the initialization is done (in the SPL and U-Boot). I would like to make minor tweaks to the EVM code for testing and then later on make major modifications when we develop our custom board.

    Although there are documents that clearly indicate how to compile them, which I have read through and have compiled these, there are none specifying how and/or what to modify. On previous occasions of using TI's software package (namely Stellarisware) the code was well documented and the Application notes made it easier to understand and make changes as required.

    The Linux variant seems all cryptic to a relatively new user - I am not completely new to Linux - just haven't worked with TI's SDK. Is there a getting started guide - I have read through most documents on the wiki page; I am looking for something more in depth and detailed - not just how to compile and download code.

    Thank you for your patience.

    Regards

    Santhosh

  • Hello,

    I have been ploughing through the U-Boot code and have found most definitions for the EVM board in am335x_evm.h. I have few questions regarding some of the definitions in this file:

    1. CONFIG_SYS_NAND_U_BOOT_START - Is defined as 'CONFIG_SYS_TEXT_BASE' which in turn is defined to be 8MB from the start of the DRAM. What does this definition mean and where and how is it used??

    2. Similar question regarding CONFIG_SYS_NAND_U_BOOT_OFFS.

    There are many definitions in this file which are difficult to understand - since they are specific to the EVM and there are no specific hits in google. Is there a document that explains how and why these definitions are used as such?

    Thank you

    Regards

    Santhosh

  • Hi,

    The file am335x_evm.h which is found in include/configs/ is like a configuration file for your board.

    1. CONFIG_SYS_NAND_U_BOOT_START - Is defined as 'CONFIG_SYS_TEXT_BASE' which in turn is defined to be 8MB from the start of the DRAM. What does this definition mean and where and how is it used??

    'CONFIG_SYS_NAND_U_BOOT_START' This config tells that U-boot image

    is present at this address in RAM, so when SPL has done its job it

    finally jumps to this address in RAM where U-boot image is present.

    2. Similar question regarding CONFIG_SYS_NAND_U_BOOT_OFFS.

    As I have told the task performed SPL, this config

    'CONFIG_SYS_NAND_U_BOOT_OFFS' tells the SPL to Load U-Boot image from

    NAND into RAM at this addreess.

    If you notice this address is same as ''CONFIG_SYS_NAND_U_BOOT_START'

    this is just the naming convention.

    Hope that clears your doubt..

    Thx,

    --Prabhakar Lad

  • Hello Prabhakar,

    Thank you for your response, I clearly understood the first part but have some difficulty understanding the second one. From the file it seems the value of the U-Boot offset is wrong. This is what I found in the file

    #define CONFIG_SYS_NAND_U_BOOT_OFFS    0x80000

    /*
     * 8MB into the SDRAM to allow for SPL's bss at the beginning of SDRAM.
     * 64 bytes before this address should be set aside for u-boot.img's
     * header. That is 0x807FFFC0--0x80800000 should not be used for any
     * other needs.
     */
    #define CONFIG_SYS_TEXT_BASE        0x80800000

    Could you please clarify - the U-Boot offset seems to be 512KB where as the Text Base is at 8MB. Also the comments indicate that it is the start address for the SPL's bss - this is what is confusing.

    Thank you for your patience.

    Regards

    Santhosh

  • Hi,

    #define CONFIG_SYS_NAND_U_BOOT_OFFS    0x80000

    /*
     * 8MB into the SDRAM to allow for SPL's bss at the beginning of SDRAM.
     * 64 bytes before this address should be set aside for u-boot.img's
     * header. That is 0x807FFFC0--0x80800000 should not be used for any
     * other needs.
     */
    #define CONFIG_SYS_TEXT_BASE        0x80800000

    Could you please clarify - the U-Boot offset seems to be 512KB where as the Text Base is at 8MB. Also the comments indicate that it is the start address for the SPL's bss - this is what is confusing.

    "CONFIG_SYS_NAND_U_BOOT_OFFS" -->> This offset indicates that your U-boot image is present in this location in NAND flash. So in your case the u-boot image is present at 512KB in NAND flash. This u-boot image is flashed ti NAND using to some tool , you can check out it writes at 0x80000 in your case.

    "CONFIG_SYS_TEXT_BASE "-->> This offset indicates, finally when SPL has read the u-boot image from some flash in you case from nand. So at this address in RAM your u-boot image is copied and finally after copying the SPL jumps to this address so now your U-boot starts executing.

    Thx,

    --Prabhakar Lad

  • Hello Prabhakar,

    Thank you again, yes that makes sense now;  just got a little confused due to the naming convention. I read through U-Boot User's Guide and found that there are 4 copies of SPL totaling upto 512KB and then U-Boot is placed after that section. Could you please answer few more questions for me? Thank you so much for your patience.

    I was reading through the document u-boot-spl.lds and I am trying to co-relate the bss definition in the am335x_evm.h.

    U-BOOT-SPL.LDS

    MEMORY { .sdram : ORIGIN = CONFIG_SPL_BSS_START_ADDR, \
            LENGTH = CONFIG_SPL_BSS_MAX_SIZE }

    AM335X_EVM.H

    #define CONFIG_SPL_BSS_START_ADDR    0x80000000 
    #define CONFIG_SPL_BSS_MAX_SIZE        0x80000        /* 512 KB */

    How are these 2 related - because if there is only 512KB of bss data for the SPL - then couldn't the U-Boot image start before the 8MB boundary. Does the U-Boot copy the Linux kernel to the start of SDRAM (0x80000000) and hence is located 8MB below the starting location. I am justing trying to understand the logic and layout of the individual parts. I understand that some of the questions may be dumb - but I am not able to find any sources where I can get such basic information.

    Once again thanks for your patience.

    Thank you

    Regards

    Santhosh

  • Hi,

    U-BOOT-SPL.LDS

    MEMORY { .sdram : ORIGIN = CONFIG_SPL_BSS_START_ADDR, \
            LENGTH = CONFIG_SPL_BSS_MAX_SIZE }

    AM335X_EVM.H

    #define CONFIG_SPL_BSS_START_ADDR    0x80000000 
    #define CONFIG_SPL_BSS_MAX_SIZE        0x80000        /* 512 KB */

    How are these 2 related - because if there is only 512KB of bss data for the SPL - then couldn't the U-Boot image start before the 8MB boundary. Does the U-Boot copy the Linux kernel to the start of SDRAM (0x80000000) and hence is located 8MB below the starting location. I am justing trying to understand the logic and layout of the individual parts. I understand that some of the questions may be dumb - but I am not able to find any sources where I can get such basic information.

    Agreed the size of the BSS is only 512KB, but the size of the SPL is

    CONFIG_SPL_MAX_SIZE (46 * 1024) in your case. The U-Boot copies linux at

    CONFIG_SYS_LOAD_ADDR (0x81000000 in your case). Not sure why 8Mb is left

    never worked on this board :( May be you can find it out in AM335x boot docs.

    Thx,

    --Prabhakar Lad

  • Hello Prabhakar,

    Thanks again for your reply. Do you know what is the use of the BSS segment for SPL. Also have you worked with booting from SD Card on other boards, if so, can you please explain how the following definitions work:

    #define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR    0x300 /* address 0x60000 */
    #define CONFIG_SYS_U_BOOT_MAX_SIZE_SECTORS    0x200 /* 256 KB */

    I didn't understand the Boot_Sector definition, how is it used?

    Thanks again for your replies :)

    Regards

    Santhosh

  • Hi,

    Do you know what is the use of the BSS segment for SPL.

    Its used for the same purpose as  in general.  It  contains all global

    variables and static variables that are initialized to zero or do not have

    explicit initialization in source code.

    you please explain how the following definitions work:

    #define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR    0x300 /* address 0x60000 */
    #define CONFIG_SYS_U_BOOT_MAX_SIZE_SECTORS    0x200 /* 256 KB */

    I didn't understand the Boot_Sector definition, how is it used?

    CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR is the address in MMC/SD card

    CONFIG_SYS_U_BOOT_MAX_SIZE_SECTORS is the size.

    If you notice you can also find CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION this tells

    in which partition to look for.

    These configs are used to  load U-Boot from when the MMC is being used in raw mode.

    Thx,

    --Prabhakar Lad

    -------------------------------------------------------------------------------

    Please click the Verify Answer button on this post if it answers your question.
    --------------------------------------------------------------------------------

  • Hello Prabhakar,

    Thanks again for your reply. I understand the definitions for sector size and partition, but if the starting address of U-Boot is provided does it mean that the script which is used to generate the SD Card images (U-boot.bin, MLO, Kernel image etc.) places each of these files in a specific location? I was under the impression that the U-Boot file is picked up by file name, u-boot.img. Am I missing something?

    Also, if the starting address is defined, then where in the file generation script does it specific which sector to place it in? I tried looking at the SD Card image but I couldn't see any indications. May be I am looking at the wrong place?

    Thank you for all your replies and patience :)

    Regards

    Santhosh

  • Hi,

    I am not so sure on AM335x, but usually the case is the the flasher tool flashes to some specific address in the

    MMC/SD card and this address is given to SPL to load the U-boot image.

    Since you can any day change the address to be flashed of the U-boot image, because of which

    this is the config in your am335x configuration file.

    Thx,

    --Prabhakar Lad

  • Hello Prabhakar,

    Can you please point me to any document that will help me find out more about this; I tried looking for the way the address is used but couldn't find any reference. If you have used this with a different device then can you point me to information about that, may be I will be able to co-relate.

    thanks

    Regards

    Santhosh

  • Hi,

    If you can point to me your script which configures the MMC card I'll help you with the same.

    Thx,

    --Prabhakar Lad

  • Hello Prabhakar,

    The path for the file (create-sdcard.sh) is ti-sdk-am335x-evm-05.04.01.00/bin - it does not allow me to attach a linker file - so I am pasting it at the end of the email.

    Thanks a lot for all your help.

    Regards

    Santhosh

    #!/bin/bash
    # Authors:
    #    LT Thomas <ltjr@ti.com>
    #    Chase Maupin
    # create-sdcard.sh v0.3
    #
    #Permission is hereby granted, free of charge, to any person obtaining a copy
    #of this software and associated documentation files (the "Software"), to deal
    #in the Software without restriction, including without limitation the rights
    #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    #copies of the Software, and to permit persons to whom the Software is
    #furnished to do so, subject to the following conditions:
    #
    #The above copyright notice and this permission notice shall be included in
    #all copies or substantial portions of the Software.
    #
    #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    #THE SOFTWARE.

    # Determine the absolute path to the executable
    # EXE will have the PWD removed so we can concatenate with the PWD safely
    PWD=`pwd`
    EXE=`echo $0 | sed s=$PWD==`
    EXEPATH="$PWD"/"$EXE"
    clear
    cat << EOM

    ################################################################################

    This script will create a bootable SD card from custom or pre-built binaries.

    The script must be run with root permissions and from the bin directory of
    the SDK

    Example:
     $ sudo ./create-sdcard.sh

    Formatting can be skipped if the SD card is already formatted and
    partitioned properly.

    ################################################################################

    EOM

    AMIROOT=`whoami | awk {'print $1'}`
    if [ "$AMIROOT" != "root" ] ; then
        
        echo "    **** Error *** must run script with sudo"
        echo ""
        exit    
    fi

    THEPWD=$EXEPATH
    PARSEPATH=`echo $THEPWD | grep -o '.*ti-sdk.*.[0-9]/'`

    if [ "$PARSEPATH" != "" ] ; then
    PATHVALID=1
    else
    PATHVALID=0
    fi

    #Precentage function
    untar_progress ()
    {
        TARBALL=$1;
        DIRECTPATH=$2;
        BLOCKING_FACTOR=$(($(gzip --list ${TARBALL} | sed -n -e "s/.*[[:space:]]\+[0-9]\+[[:space:]]\+\([0-9]\+\)[[:space:]].*$/\1/p") / 51200 + 1));
        tar --blocking-factor=${BLOCKING_FACTOR} --checkpoint=1 --checkpoint-action='ttyout=Written %u%  \r' -zxf ${TARBALL} -C ${DIRECTPATH}
    }

    #copy/paste programs
    cp_progress ()
    {
        CURRENTSIZE=0
        while [ $CURRENTSIZE -lt $TOTALSIZE ]
        do
            TOTALSIZE=$1;
            TOHERE=$2;
            CURRENTSIZE=`sudo du -c $TOHERE | grep total | awk {'print $1'}`
            echo -e -n "$CURRENTSIZE /  $TOTALSIZE copied \r"
            sleep 1
        done
    }

    populate_3_partitions() {
        ENTERCORRECTLY="0"
        while [ $ENTERCORRECTLY -ne 1 ]
        do
            read -e -p 'Enter path where SD card tarballs were downloaded : '  TARBALLPATH
                    
            echo ""
            ENTERCORRECTLY=1
            if [ -d $TARBALLPATH ]
            then
                echo "Directory exists"
                echo ""
                echo "This directory contains:"
                ls $TARBALLPATH
                echo ""
                read -p 'Is this correct? [y/n] : ' ISRIGHTPATH
                    case $ISRIGHTPATH in
                    "y" | "Y") ;;
                    "n" | "N" ) ENTERCORRECTLY=0;continue;;
                    *)  echo "Please enter y or n";ENTERCORRECTLY=0;continue;;
                    esac
            else
                echo "Invalid path make sure to include complete path"
                ENTERCORRECTLY=0
                continue
            fi
            # Check that tarballs were found
            if [ ! -e "$TARBALLPATH""/boot_partition.tar.gz" ]
            then
                echo "Could not find boot_partition.tar.gz as expected.  Please"
                echo "point to the directory containing the boot_partition.tar.gz"
                ENTERCORRECTLY=0
                continue
            fi

            if [ ! -e "$TARBALLPATH""/rootfs_partition.tar.gz" ]
            then
                echo "Could not find rootfs_partition.tar.gz as expected.  Please"
                echo "point to the directory containing the rootfs_partition.tar.gz"
                ENTERCORRECTLY=0
                continue
            fi

            if [ ! -e "$TARBALLPATH""/start_here_partition.tar.gz" ]
            then
                echo "Could not find start_here_partition.tar.gz as expected.  Please"
                echo "point to the directory containing the start_here_partition.tar.gz"
                ENTERCORRECTLY=0
                continue
            fi
        done

            # Make temporary directories and untar mount the partitions
            mkdir $PWD/boot
            mkdir $PWD/rootfs
            mkdir $PWD/start_here
            mkdir $PWD/tmp

            mount -t vfat "/dev/""$DEVICEDRIVENAME""1" boot
            mount -t ext3 "/dev/""$DEVICEDRIVENAME""2" rootfs
            mount -t ext3 "/dev/""$DEVICEDRIVENAME""3" start_here

            # Remove any existing content in case the partitions were not
            # recreated
            sudo rm -rf boot/*
            sudo rm -rf rootfs/*
            sudo rm -rf start_here/*

            # Extract the tarball contents.
    cat << EOM

    ################################################################################
            Extracting boot partition tarball

    ################################################################################
    EOM
            untar_progress $TARBALLPATH/boot_partition.tar.gz tmp/
            if [ -e "./tmp/MLO" ]
            then
                cp ./tmp/MLO boot/
            fi
            cp -rf ./tmp/* boot/

    cat << EOM

    ################################################################################
            Extracting rootfs partition tarball

    ################################################################################
    EOM
            untar_progress $TARBALLPATH/rootfs_partition.tar.gz rootfs/

    cat << EOM

    ################################################################################
            Extracting start_here partition to temp directory

    ################################################################################
    EOM
            rm -rf tmp/*
            untar_progress $TARBALLPATH/start_here_partition.tar.gz tmp/

    cat << EOM

    ################################################################################
            Extracting CCS tarball

    ################################################################################
    EOM
            mv tmp/CCS-5*.tar.gz .
            untar_progress CCS-5*.tar.gz tmp/
            rm CCS-5*.tar.gz

    cat << EOM

    ################################################################################
            Copying Contents to START_HERE

    ################################################################################
    EOM

            TOTALSIZE=`sudo du -c tmp/* | grep total | awk {'print $1'}`
            cp -rf tmp/* start_here/ &
            cp_progress $TOTALSIZE start_here/
            sync;sync
            # Fix up the START_HERE partitoin permissions
            chown nobody -R start_here
            chgrp nogroup -R start_here
            chmod -R g+r+x,o+r+x start_here/CCS

            umount boot rootfs start_here
            sync;sync

            # Clean up the temp directories
            rm -rf boot rootfs start_here tmp
    }


    # find the avaible SD cards
    echo " "
    echo "Availible Drives to write images to: "
    echo " "
    ROOTDRIVE=`mount | grep 'on / ' | awk {'print $1'} |  cut -c6-8`
    echo "#  major   minor    size   name "
    cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>' | grep -n ''
    echo " "
        
    ENTERCORRECTLY=0
    while [ $ENTERCORRECTLY -ne 1 ]
    do
        read -p 'Enter Device Number: ' DEVICEDRIVENUMBER
        echo " "
        DEVICEDRIVENAME=`cat /proc/partitions | grep -v 'sda' | grep '\<sd.\>' | grep -n '' | grep "${DEVICEDRIVENUMBER}:" | awk '{print $5}'`

        DRIVE=/dev/$DEVICEDRIVENAME
        DEVICESIZE=`cat /proc/partitions | grep -v 'sda' | grep '\<sd.\>' | grep -n '' | grep "${DEVICEDRIVENUMBER}:" | awk '{print $4}'`


        if [ -n "$DEVICEDRIVENAME" ]
        then
            ENTERCORRECTLY=1
        else
            echo "Invalid selection"    
        fi

        echo ""
    done

    echo "$DEVICEDRIVENAME was selected"
    #Check the size of disk to make sure its under 16GB
    if [ $DEVICESIZE -gt 17000000 ] ; then
    cat << EOM

    ################################################################################

            **********WARNING**********

        Selected Device is greater then 16GB
        Continuing past this point will erase data from device
        Double check that this is the correct SD Card

    ################################################################################

    EOM
        ENTERCORRECTLY=0
        while [ $ENTERCORRECTLY -ne 1 ]
        do
            read -p 'Would you like to continue [y/n] : ' SIZECHECK
            echo ""
            echo " "
            ENTERCORRECTLY=1
            case $SIZECHECK in
            "y")  ;;
            "n")  exit;;
            *)  echo "Please enter y or n";ENTERCORRECTLY=0;;
            esac
            echo ""
        done

    fi

    echo ""



    DRIVE=/dev/$DEVICEDRIVENAME

    echo "Checking the device is unmounted"
    #unmount drives if they are mounted
    unmounted1=`df | grep '\<'$DEVICEDRIVENAME'1\>' | awk '{print $1}'`
    unmounted2=`df | grep '\<'$DEVICEDRIVENAME'2\>' | awk '{print $1}'`
    unmounted3=`df | grep '\<'$DEVICEDRIVENAME'3\>' | awk '{print $1}'`
    if [ -n "$unmounted1" ]
    then
        echo " unmounted ${DRIVE}1"
        sudo umount -f ${DRIVE}1
    fi
    if [ -n "$unmounted2" ]
    then
        echo " unmounted ${DRIVE}2"
        sudo umount -f ${DRIVE}2
    fi
    if [ -n "$unmounted3" ]
    then
        echo " unmounted ${DRIVE}3"
        sudo umount -f ${DRIVE}3
    fi
    echo ""
    # check to see if the device is already partitioned
    SIZE1=`cat /proc/partitions | grep -v 'sda' | grep '\<'$DEVICEDRIVENAME'1\>'  | awk '{print $3}'`
    SIZE2=`cat /proc/partitions | grep -v 'sda' | grep '\<'$DEVICEDRIVENAME'2\>'  | awk '{print $3}'`
    SIZE3=`cat /proc/partitions | grep -v 'sda' | grep '\<'$DEVICEDRIVENAME'3\>'  | awk '{print $3}'`
    SIZE4=`cat /proc/partitions | grep -v 'sda' | grep '\<'$DEVICEDRIVENAME'4\>'  | awk '{print $3}'`
    echo "${DEVICEDRIVENAME}1  ${DEVICEDRIVENAME}2   ${DEVICEDRIVENAME}3"
    echo $SIZE1 $SIZE2 $SIZE3 $SIZE4
    echo ""

    if [ -n "$SIZE1" -a -n "$SIZE2" ] ; then
        if  [ "$SIZE1" -gt "72000" -a "$SIZE2" -gt "900000" ]
        then
            PARTITION=1

            if [ -z "$SIZE3" -a -z "$SIZE4" ]
            then
                #Detected 2 partitions
                PARTS=2

            elif [ "$SIZE3" -gt "1000" -a -z "$SIZE4" ]
            then
                #Detected 3 partitions
                PARTS=3
            
            else
                echo "SD Card is not correctly partitioned"
                PARTITION=0
            fi
        fi
    else
        echo "SD Card is not correctly partitioned"
        PARTITION=0
        PARTS=0
    fi


    #Partition is found
    if [ "$PARTITION" -eq "1" ]
    then
    cat << EOM

    ################################################################################

       Detected device has $PARTS partitions already

       Re-partitioning will allow the choice of 2 or 3 partitions

    ################################################################################

    EOM
        
        ENTERCORRECTLY=0
        while [ $ENTERCORRECTLY -ne 1 ]
        do
            read -p 'Would you like to re-partition the drive anyways [y/n] : ' CASEPARTITION
            echo ""
            echo " "
            ENTERCORRECTLY=1
            case $CASEPARTITION in
            "y")  echo "Now partitioning $DEVICEDRIVENAME ...";PARTITION=0;;
            "n")  echo "Skipping partitioning";;
            *)  echo "Please enter y or n";ENTERCORRECTLY=0;;
            esac
            echo ""
        done

    fi

    #Partition is not found, choose to partition 2 or 3 segments
    if [ "$PARTITION" -eq "0" ]
    then
    cat << EOM

    ################################################################################

        Select 2 partitions if only need boot and rootfs (most users)
        Select 3 partitions if need SDK & CCS on SD card.  This is usually used
            by device manufacturers with access to partition tarballs.

        ****WARNING**** continuing will erase all data on $DEVICEDRIVENAME

    ################################################################################

    EOM
        ENTERCORRECTLY=0
        while [ $ENTERCORRECTLY -ne 1 ]
        do

            read -p 'Number of partitions needed [2/3] : ' CASEPARTITIONNUMBER
            echo ""
            echo " "
            ENTERCORRECTLY=1
            case $CASEPARTITIONNUMBER in
            "2")  echo "Now partitioning $DEVICEDRIVENAME with 2 partitions...";PARTITION=2;;
            "3")  echo "Now partitioning $DEVICEDRIVENAME with 3 partitions...";PARTITION=3;;
            "n")  exit;;
            *)  echo "Please enter 2 or 3";ENTERCORRECTLY=0;;
            esac
            echo " "
        done
    fi



    #Section for partitioning the drive

    #create 3 partitions
    if [ "$PARTITION" -eq "3" ]
    then

    # set the PARTS value as well
    PARTS=3

    cat << EOM

    ################################################################################

            Now making 3 partitions

    ################################################################################

    EOM

    dd if=/dev/zero of=$DRIVE bs=1024 count=1024

    SIZE=`fdisk -l $DRIVE | grep Disk | awk '{print $5}'`

    echo DISK SIZE - $SIZE bytes

    CYLINDERS=`echo $SIZE/255/63/512 | bc`

    sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE << EOF
    ,9,0x0C,*
    10,115,,-
    126,,,-
    EOF

    cat << EOM

    ################################################################################

            Partitioning Boot

    ################################################################################
    EOM
        mkfs.vfat -F 32 -n "boot" ${DRIVE}1
    cat << EOM

    ################################################################################

            Partitioning Rootfs

    ################################################################################
    EOM
        mkfs.ext3 -L "rootfs" ${DRIVE}2
    cat << EOM

    ################################################################################

            Partitioning START_HERE

    ################################################################################
    EOM
        mkfs.ext3 -L "START_HERE" ${DRIVE}3
        sync
        sync

    #create only 2 partitions
    elif [ "$PARTITION" -eq "2" ]
    then

    # Set the PARTS value as well
    PARTS=2
    cat << EOM

    ################################################################################

            Now making 2 partitions

    ################################################################################

    EOM
    dd if=/dev/zero of=$DRIVE bs=1024 count=1024

    SIZE=`fdisk -l $DRIVE | grep Disk | awk '{print $5}'`

    echo DISK SIZE - $SIZE bytes

    CYLINDERS=`echo $SIZE/255/63/512 | bc`

    sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE << EOF
    ,9,0x0C,*
    10,,,-
    EOF

    cat << EOM

    ################################################################################

            Partitioning Boot

    ################################################################################
    EOM
        mkfs.vfat -F 32 -n "boot" ${DRIVE}1
    cat << EOM

    ################################################################################

            Partitioning rootfs

    ################################################################################
    EOM
        mkfs.ext3 -L "rootfs" ${DRIVE}2
        sync
        sync
        INSTALLSTARTHERE=n
    fi



    #Break between partitioning and installing file system
    cat << EOM


    ################################################################################

       Partitioning is now done
       Continue to install filesystem or select 'n' to safe exit

       **Warning** Continuing will erase files any files in the partitions

    ################################################################################


    EOM
    ENTERCORRECTLY=0
    while [ $ENTERCORRECTLY -ne 1 ]
    do
        read -p 'Would you like to continue? [y/n] : ' EXITQ
        echo ""
        echo " "
        ENTERCORRECTLY=1
        case $EXITQ in
        "y") ;;
        "n") exit;;
        *)  echo "Please enter y or n";ENTERCORRECTLY=0;;
        esac
    done

    # If this is a three partition card then we will jump to a function to
    # populate the three partitions and then exit the script.  If not we
    # go on to prompt the user for input on the two partitions
    if [ "$PARTS" -eq "3" ]
    then
        populate_3_partitions
        exit 0
    fi

    #Add directories for images
    export START_DIR=$PWD
    mkdir $START_DIR/tmp
    export PATH_TO_SDBOOT=boot
    export PATH_TO_SDROOTFS=rootfs
    export PATH_TO_TMP_DIR=$START_DIR/tmp


    echo " "
    echo "Mount the partitions "
    mkdir $PATH_TO_SDBOOT
    mkdir $PATH_TO_SDROOTFS

    sudo mount -t vfat ${DRIVE}1 boot/
    sudo mount -t ext3 ${DRIVE}2 rootfs/



    echo " "
    echo "Emptying partitions "
    echo " "
    sudo rm -rf  $PATH_TO_SDBOOT/*
    sudo rm -rf  $PATH_TO_SDROOTFS/*

    echo ""
    echo "Syncing...."
    echo ""
    sync
    sync
    sync

    cat << EOM
    ################################################################################

        Choose file path to install from

        1 ) Install pre-built images from SDK
        2 ) Enter in custom boot and rootfs file paths

    ################################################################################

    EOM
    ENTERCORRECTLY=0
    while [ $ENTERCORRECTLY -ne 1 ]
    do
        read -p 'Choose now [1/2] : ' FILEPATHOPTION
        echo ""
        echo " "
        ENTERCORRECTLY=1
        case $FILEPATHOPTION in
        "1") echo "Will now install from SDK pre-built images";;
        "2") echo "";;
        *)  echo "Please enter 1 or 2";ENTERCORRECTLY=0;;
        esac
    done

    # SDK DEFAULTS
    if [ $FILEPATHOPTION -eq 1 ] ; then

        #check that in the right directory
        
        THEEVMSDK=`echo $PARSEPATH | grep -o 'ti-sdk-.*[0-9]'`

        if [ $PATHVALID -eq 1 ]; then
        echo "now installing:  $THEEVMSDK"
        else
        echo "no SDK PATH found"
        ENTERCORRECTLY=0
            while [ $ENTERCORRECTLY -ne 1 ]
            do
                read -e -p 'Enter path to SDK : '  SDKFILEPATH
                    
                echo ""
                ENTERCORRECTLY=1
                if [ -d $SDKFILEPATH ]
                then
                    echo "Directory exists"
                    echo ""
                    PARSEPATH=`echo $SDKFILEPATH | grep -o '.*ti-sdk.*.[0-9]/'`
                    #echo $PARSEPATH

                    if [ "$PARSEPATH" != "" ] ; then
                    PATHVALID=1
                    else
                    PATHVALID=0
                    fi
                    #echo $PATHVALID
                    if [ $PATHVALID -eq 1 ] ; then
                
                    THEEVMSDK=`echo $SDKFILEPATH | grep -o 'ti-sdk-.*[0-9]'`
                    echo "Is this the correct SDK: $THEEVMSDK"
                    echo ""
                    read -p 'Is this correct? [y/n] : ' ISRIGHTPATH
                        case $ISRIGHTPATH in
                        "y") ;;
                        "n") ENTERCORRECTLY=0;;
                        *)  echo "Please enter y or n";ENTERCORRECTLY=0;;
                        esac
                    else
                    echo "Invalid SDK path make sure to include ti-sdk-xxxx"
                    ENTERCORRECTLY=0
                    fi
                
                else
                    echo "Invalid path make sure to include complete path"
                
                    ENTERCORRECTLY=0
                fi
            done
        fi



        #check that files are in SDK
        BOOTFILEPATH="$PARSEPATH/board-support/prebuilt-images"
        MLO=`ls $BOOTFILEPATH | grep MLO | awk {'print $1'}`
        UIMAGE=`ls $BOOTFILEPATH | grep uImage | awk {'print $1'}`
        BOOTIMG=`ls $BOOTFILEPATH | grep u-boot | grep .img | awk {'print $1'}`
        BOOTBIN=`ls $BOOTFILEPATH | grep u-boot | grep .bin | awk {'print $1'}`
        #rootfs
        ROOTFILEPARTH="$PARSEPATH/filesystem"
        #ROOTFSTAR=`ls  $ROOTFILEPARTH | grep tisdk-rootfs | awk {'print $1'}`
        
        #Make sure there is only 1 tar
        CHECKNUMOFTAR=`ls $ROOTFILEPARTH | grep "tisdk-rootfs" | grep 'tar.gz' | grep -n '' | grep '2:' | awk {'print $1'}`
        if [ -n "$CHECKNUMOFTAR" ]
        then
    cat << EOM

    ################################################################################

       Multiple rootfs Tarballs found

    ################################################################################

    EOM
            ls $ROOTFILEPARTH | grep "tisdk-rootfs" | grep 'tar.gz' | grep -n '' | awk {'print "    " , $1'}
            echo ""
            read -p "Enter Number of rootfs Tarball: " TARNUMBER
            echo " "
            FOUNDTARFILENAME=`ls $ROOTFILEPARTH | grep "rootfs" | grep 'tar.gz' | grep -n '' | grep "${TARNUMBER}:" | cut -c3- | awk {'print$1'}`
            ROOTFSTAR=$FOUNDTARFILENAME

        else
            ROOTFSTAR=`ls  $ROOTFILEPARTH | grep tisdk-rootfs | awk {'print $1'}`
        fi

        ROOTFSUSERFILEPATH=$ROOTFILEPARTH/$ROOTFSTAR
        BOOTPATHOPTION=1
        ROOTFSPATHOPTION=2

    elif [ $FILEPATHOPTION -eq 2  ] ; then
    cat << EOM
    ################################################################################

      For Boot partition

      If files are located in Tarball write complete path including the file name.
          e.x. $:  /home/user/MyCustomTars/boot.tar.gz

      If files are located in a directory write the directory path
          e.x. $: /ti-sdk/board-support/prebuilt-images/

      and the beginning of the files should be labeled with MLO, u-boot, uImage
          i.e.   test_MLO_image must be labeled as MLO_test_image

      NOTE: Not all platforms will have an MLO file and this file can
            be ignored for platforms that do not support an MLO
    ################################################################################

    EOM
        ENTERCORRECTLY=0
        while [ $ENTERCORRECTLY -ne 1 ]
        do
            read -e -p 'Enter path for Boot Partition : '  BOOTUSERFILEPATH
                    
            echo ""
            ENTERCORRECTLY=1
            if [ -f $BOOTUSERFILEPATH ]
            then
                echo "File exists"
                echo ""
            elif [ -d $BOOTUSERFILEPATH ]
            then
                echo "Directory exists"
                echo ""
                echo "This directory contains:"
                ls $BOOTUSERFILEPATH
                echo ""
                read -p 'Is this correct? [y/n] : ' ISRIGHTPATH
                    case $ISRIGHTPATH in
                    "y") ;;
                    "n") ENTERCORRECTLY=0;;
                    *)  echo "Please enter y or n";ENTERCORRECTLY=0;;
                    esac
            else
                echo "Invalid path make sure to include complete path"
                
                ENTERCORRECTLY=0
            fi
        done

    cat << EOM


    ################################################################################

       For Rootfs partition

       If files are located in Tarball write complete path including the file name.
          e.x. $:  /home/user/MyCustomTars/rootfs.tar.gz

      If files are located in a directory write the directory path
          e.x. $: /ti-sdk/targetNFS/

    ################################################################################

    EOM
        ENTERCORRECTLY=0
        while [ $ENTERCORRECTLY -ne 1 ]
        do
            read -e -p 'Enter path for Rootfs Partition : ' ROOTFSUSERFILEPATH
            echo ""
            ENTERCORRECTLY=1
            if [ -f $ROOTFSUSERFILEPATH ]
            then
                echo "File exists"
                echo ""
            elif [ -d $ROOTFSUSERFILEPATH ]
            then
                echo "This directory contains:"
                ls $ROOTFSUSERFILEPATH
                echo ""
                read -p 'Is this correct? [y/n] : ' ISRIGHTPATH
                    case $ISRIGHTPATH in
                    "y") ;;
                    "n") ENTERCORRECTLY=0;;
                    *)  echo "Please enter y or n";ENTERCORRECTLY=0;;
                    esac
                
            else
                echo "Invalid path make sure to include complete path"
                
                ENTERCORRECTLY=0
            fi
        done
        echo ""


        # Check if user entered a tar or not for Boot
        ISBOOTTAR=`ls $BOOTUSERFILEPATH | grep .tar.gz | awk {'print $1'}`
        if [ -n "$ISBOOTTAR" ]
        then
            BOOTPATHOPTION=2
        else
            BOOTPATHOPTION=1
            BOOTFILEPATH=$BOOTUSERFILEPATH
            MLO=`ls $BOOTFILEPATH | grep MLO | awk {'print $1'}`
            UIMAGE=`ls $BOOTFILEPATH | grep uImage | awk {'print $1'}`
            BOOTIMG=`ls $BOOTFILEPATH | grep u-boot | grep .img | awk {'print $1'}`
            BOOTBIN=`ls $BOOTFILEPATH | grep u-boot | grep .bin | awk {'print $1'}`
        fi

        #Check if user entered a tar or not for Rootfs
        ISROOTFSTAR=`ls $ROOTFSUSERFILEPATH | grep .tar.gz | awk {'print $1'}`
        if [ -n "$ISROOTFSTAR" ]
        then
            ROOTFSPATHOPTION=2
        else
            ROOTFSPATHOPTION=1
            ROOTFSFILEPATH=$ROOTFSUSERFILEPATH
        fi
    fi

    cat << EOM
    ################################################################################

        Copying files now... will take minutes

    ################################################################################

    Copying boot partition
    EOM


    if [ $BOOTPATHOPTION -eq 1 ] ; then

        echo ""
        #copy boot files out of board support
        if [ "$MLO" != "" ] ; then
            cp $BOOTFILEPATH/$MLO $PATH_TO_SDBOOT/MLO
            echo "MLO copied"
        else
            echo "MLO file not found"
        fi

        echo ""

        if [ "$BOOTBIN" != "" ] ; then
            cp $BOOTFILEPATH/$BOOTBIN $PATH_TO_SDBOOT/u-boot.bin
            echo "u-boot.bin copied"
        else
            echo "u-boot.bin file not found"
        fi

        echo ""

        if [ "$BOOTIMG" != "" ] ; then
            cp $BOOTFILEPATH/$BOOTIMG $PATH_TO_SDBOOT/u-boot.img
            echo "u-boot.img copied"
        else
            echo "u-boot.img file not found"
        fi

        echo ""

        if [ "$UIMAGE" != "" ] ; then
            cp $BOOTFILEPATH/$UIMAGE $PATH_TO_SDBOOT/uImage
            echo "uImage copied"
        else
            echo "uImage file not found"
        fi

    elif [ $BOOTPATHOPTION -eq 2  ] ; then
        untar_progress $BOOTUSERFILEPATH $PATH_TO_TMP_DIR
        cp -rf $PATH_TO_TMP_DIR/* $PATH_TO_SDBOOT
        echo ""

    fi

    echo ""
    sync

    echo "Copying rootfs System partition"
    if [ $ROOTFSPATHOPTION -eq 1 ] ; then
        TOTALSIZE=`sudo du -c $ROOTFSUSERFILEPATH/* | grep total | awk {'print $1'}`
        sudo cp -r $ROOTFSUSERFILEPATH/* $PATH_TO_SDROOTFS & cp_progress $TOTALSIZE $PATH_TO_SDROOTFS

    elif [ $ROOTFSPATHOPTION -eq 2  ] ; then    
        untar_progress $ROOTFSUSERFILEPATH $PATH_TO_SDROOTFS
    fi

    echo ""
    echo ""
    echo "Syncing..."
    sync
    sync
    sync
    sync
    sync
    sync
    sync
    sync


    echo " "
    echo "Un-mount the partitions "
    sudo umount -f $PATH_TO_SDBOOT
    sudo umount -f $PATH_TO_SDROOTFS


    echo " "
    echo "Remove created temp directories "
    sudo rm -rf $PATH_TO_TMP_DIR
    sudo rm -rf $PATH_TO_SDROOTFS
    sudo rm -rf $PATH_TO_SDBOOT


    echo " "
    echo "Operation Finished"
    echo " "


  • Hi,

    To huge script on quick search dnt find the address, One simple thing you can do is flash

    the u-boot to MMC/SD card using this script once done you can compare the hex values of

    u-boot.bin and the content flashed into MMC this will confirm you that its flashed at

    CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR address.

    Thx,

    --Prabhakar Lad

    ------------------------------------------------------------------------------

    Please click the Verify Answer button on this post if it answers your question.
    -------------------------------------------------------------------------------

  • Hello Prabhakar,

    Yes I did compare the .bin and the .img file, the only difference is the header - which is a requirement for the SPL. But I didn't understand how that confirms that it is flashed at a specific address. The wiki site just says copy the files to the SD Card doesn't say at what specific locations. 

    Could you explain how to verify this?

    thanks

    Regards

    Santhosh

  • Hi,

    This is what you can do,

    1: build a SPL, which looks for u-boot in MMC card and flash the spl and

    insert a MMC which is empty, Its obvious that only SPL will come and U-boot wont come.

    2:Build a SPL which looks U-boot into MMC flash u-boot to MMC. (Enable MMC commands in U-boot)

    Finally when your U-Boot comes using the MMC commands you can read the contents of MMC

    @specified address in MMC and then compare the HEX value at this address with U-boot.bin image.

    Thx,

    --Prabhakar Lad

  • Hi Santhosh,

    The images generated after each stage and need to booting  are MLO,u-boot.img,uImage. Thease images just put in the MMC card fat partition. I think the script you have , its for generate the partitions for boot and rootfs. (because if your script of generated images means you have to compile u-boot and kernel and insert the images on SD card).

    If you want to change the boot address, as prabhakar's suggetion , you just change the config file of board am335x.

     

     

    //Surendra

  • You Just follow simple steps.

    1) Just creat the MMC Card with 3 partitions.

    2) Creat your custom images like MLO,u-boot.img,uImage.

    (if you want to change the any specific boot address , change in config file)

    3) Copy the images in boot partitions i.e fat.

    4) Insert the MMC in the am335x board,

    5) From the debug log , you understand the boot address if you modified.

     

    //Surendra.