How to generate image file and dd to SD card

We use the sdcard.sh shellScript to build a image file, which is contain in the RTEMS source code.
The file is at   rtems-src/c/src/lib/libbsp/arm/beagle/simscripts

sdcard.sh

  1. # we store all generated files here.  
  2. TMPDIR=tmp_sdcard_dir.$$  
  3.   
  4. FATIMG=$TMPDIR/bbxm_boot_fat.img  
  5. SIZE=65536  
  6. OFFSET=2048  
  7. FATSIZE=`expr $SIZE - $OFFSET`  
  8. UENV=uEnv.txt  
  9.   
  10. rm -rf $TMPDIR  
  11. mkdir -p $TMPDIR  
  12.   
  13. if [ $# -ne 2 ]  
  14. then    echo "Usage: $0 <RTEMS prefix> <RTEMS executable>"  
  15.     exit 1  
  16. fi  
  17.   
  18. PREFIX=$1  
  19.   
  20. if [ ! -d "$PREFIX" ]  
  21. then    echo "This script needs the RTEMS tools bindir as the first argument."  
  22.     exit 1  
  23. fi  
  24.   
  25. executable=$2  
  26.   
  27. case "$2" in  
  28.     *beagleboard*)  
  29.         ubootcfg=omap3_beagle  
  30.         imgtype=bb  
  31.         ;;  
  32.     *beaglebone*)  
  33.         ubootcfg=am335x_evm  
  34.         imgtype=bone  
  35.         ;;  
  36.     *)  
  37.         echo "Can't guess which uboot to use - please specify full path to executable."  
  38.         exit 1  
  39.         ;;  
  40. esac  
  41.   
  42. app=rtems-app.img  
  43.   
  44. if [ ! -f "$executable" ]  
  45. then    echo "Expecting RTEMS executable as arg; $executable not found."  
  46.     exit 1  
  47. fi  
  48.   
  49. set -e  
  50.   
  51. IMG=${imgtype}_`basename $2`-sdcard.img  
  52.   
  53. # Make an empty image  
  54. dd if=/dev/zero of=$IMG bs=512 seek=`expr $SIZE - 1` count=1  
  55. dd if=/dev/zero of=$FATIMG bs=512 seek=`expr $FATSIZE - 1` count=1  
  56.   
  57. # Make an ms-dos FS on it  
  58. $PREFIX/bin/newfs_msdos -r 1 -m 0xf8 -c 4 -F16  -h 64 -u 32 -S 512 -s $FATSIZE -o 0 ./$FATIMG  
  59.   
  60. # Prepare the executable.  
  61. base=`basename $executable`  
  62. $PREFIX/bin/arm-rtems4.12-objcopy $executable -O binary $TMPDIR/$base.bin  
  63. gzip -9 $TMPDIR/$base.bin  
  64. $PREFIX/bin/mkimage -A arm -O rtems -T kernel -a 0x80000000 -e 0x80000000 -n RTEMS -d $TMPDIR/$base.bin.gz $TMPDIR/$app  
  65. echo "setenv bootdelay 5  
  66. uenvcmd=run boot  
  67. boot=fatload mmc 0 0x80800000 $app ; bootm 0x80800000" >$TMPDIR/$UENV  
  68.   
  69. # Copy the uboot and app image onto the FAT image  
  70. $PREFIX/bin/mcopy -bsp -i $FATIMG $PREFIX/uboot/$ubootcfg/MLO ::MLO  
  71. $PREFIX/bin/mcopy -bsp -i $FATIMG $PREFIX/uboot/$ubootcfg/u-boot.img ::u-boot.img  
  72. $PREFIX/bin/mcopy -bsp -i $FATIMG $TMPDIR/$app ::$app  
  73. $PREFIX/bin/mcopy -bsp -i $FATIMG $TMPDIR/$UENV ::$UENV  
  74.   
  75. # Just a single FAT partition (type C) that uses all of the image  
  76. $PREFIX/bin/partition -m $IMG $OFFSET c:${FATSIZE}\*  
  77.   
  78. # Put the FAT image into the SD image  
  79. dd if=$FATIMG of=$IMG seek=$OFFSET  
  80.   
  81. # cleanup  
  82. rm -rf $TMPDIR  
  83.   
  84. echo "Result is in $IMG."  




We build a hello world image fisrt:

 cd $HOME/development/rtems/rtems-src/c/src/lib/libbsp/arm/beagle/simscripts

sh sdcard.sh $HOME/development/rtems/4.12 $HOME/development/rtems/b-beagle/arm-rtems4.12/c/beagleboneblack/testsuites/samples/hello/hello.exe

the first path is the some file path such as u-boot, the second path is hello.exe

then you will get the info:

Result is in bone_hello.exe-sdcard.img.

So the image file is stored in the current directory, which is the directory in which the script is located




Next is to write the image file to the SD card,  I prepare a 8G SD card:

dd if=bone_hello.exe-sdcard.img of=/dev/sdb bs=4096

then you can get the info:



Then we can boot from the SD card:

the boot info as follow:

# picocom -b 115200 /dev/ttyUSB0
    U-Boot SPL 2014.04-00015-gb4422bd (Apr 22 2014 - 13:24:29)
    reading args
    spl_load_image_fat_os: error reading image args, err - -1
    reading u-boot.img
    reading u-boot.img


    U-Boot 2014.04-00015-gb4422bd (Apr 22 2014 - 13:24:29)

    I2C:   ready
    DRAM:  512 MiB
    NAND:  0 MiB
    MMC:   OMAP SD/MMC: 0, OMAP SD/MMC: 1
    *** Warning - readenv() failed, using default environment

    Net:   <ethaddr> not set. Validating first E-fuse MAC
    cpsw, usb_ether
    Hit any key to stop autoboot:  0 
    gpio: pin 53 (gpio 53) value is 1
    mmc0 is current device
    gpio: pin 54 (gpio 54) value is 1
    SD/MMC found on device 0
    reading uEnv.txt
    99 bytes read in 5 ms (18.6 KiB/s)
    gpio: pin 55 (gpio 55) value is 1
    Loaded environment from uEnv.txt
    Importing environment from mmc ...
    Checking if uenvcmd is set ...
    gpio: pin 56 (gpio 56) value is 1
    Running uenvcmd ...
    reading rtems-app.img
    58629 bytes read in 11 ms (5.1 MiB/s)
    ## Booting kernel from Legacy Image at 80800000 ...
       Image Name:   RTEMS
       Image Type:   ARM RTEMS Kernel Image (gzip compressed)
       Data Size:    58565 Bytes = 57.2 KiB
       Load Address: 80000000
       Entry Point:  80000000
       Verifying Checksum ... OK
       Uncompressing Kernel Image ... OK
    ## Transferring control to RTEMS (at address 80000000) ...

    RTEMS Beagleboard: am335x-based


    *** BEGIN OF TEST HELLO WORLD ***
    Hello World
    *** END OF TEST HELLO WORLD ***

评论

此博客中的热门博文

RTEMS-libbsd generates drive device firmware

RTEMS Network Transplantation - rtems system initialization process analysis

Add wpa_supplicant_fork command on RTEMS-libbsd