【TINY4412】U-BOOT移植笔记:(18)eMMC启动U-BOOT

【TINY4412】U-BOOT移植笔记:(18)eMMC启动U-BOOT

宿主机 : 虚拟机 Ubuntu 16.04 LTS / X64
目标板[底板]: Tiny4412SDK - 1506
目标板[核心板]: Tiny4412 - 1412
U-BOOT版本: 2017.03
交叉编译器: gcc-arm-none-eabi-5_4-2016q3
日期: 2017-6-25 12:54:27
作者: SY

简介

  • 从SD卡启动U-BOOT时,需要使用烧录脚本将制定文件,烧录到SD卡特定的位置。芯片上电后,通过调用固化在ROM中的驱动,读取SD卡的文件,执行U-BOOT。
  • eMMC就是一个带有控制器的Nand Flash芯片,相比SD卡只有4根数据总线,eMMC拥有8条数据总线,数据传输速度更高!
  • 类似于SD卡启动U-BOOT,我们只需要将文件,从SD卡拷贝到eMMC的制定位置,即可从eMMC启动U-BOOT

eMMC分区

分区名称描述
0x0No access to boot partition(default)不可访问分区
0x1R/W boot partition 1读写引导分区1
0x2R/W boot partition 2读写引导分区2
0x3R/W Replace Protect Memory Block(RPMB)读写重发保护存储器块
0x4Access to General Purpose Partition 1访问通用分区 1
0x5Access to General Purpose Partition 2访问通用分区 2
0x6Access to General Purpose Partition 3访问通用分区 3
0x7Access to General Purpose Partition 4访问通用分区 4

+ R/W boot partition 1/2:此分区主要是为了支持从 eMMC 启动系统而设计的。大小为:4MB
+ RPMB:在实际应用中,RPMB 分区通常用来保存安全相关的数据,例如指纹数据、安全支付相关的密钥等。大小为:512KB
+ General Purpose Partition 1/2/3/4:此区域则主要用于存储系统或者用户数据。
+ User Data Area: 此区域则主要用于存储系统或者用户数据。

移植

arch/arm/dts/exynos4412-tiny4412.dts
 @@ -38,8 +38,9 @@
        serial0 = "/serial@13800000";
        console = "/serial@13800000";

 -      mmc0 = "/sdhci@12530000";
 -      mmc1 = "/dwmmc@12550000";
 +      mmc2 = "/sdhci@12530000";
 +      mmc4 = "/dwmmc@12550000";
 +
    };

    serial@13800000 {

11  arch/arm/mach-exynos/clock_init_exynos4412.c
 @@ -548,3 +548,14 @@ void system_clock_init(void)
     while (readl(&clk->mux_stat_cpu) & MUX_STAT_CPU_CHANGING)
         continue;
  }
 +
 +/*
 + * Set clock divisor value for booting from EMMC.
 + * Set DWMMC channel-0 clk div to operate mmc0 device at 50MHz.
 + */
 +void emmc_boot_clk_div_set(void)
 +{
 +  ; //clock already setting!
 +}
 +
 +

7  board/samsung/tiny4412/tiny4412.c
 @@ -31,6 +31,13 @@ static void board_gpio_init(void)
  {
    /* USB复位 */
    gpio_request(EXYNOS4X12_GPIO_M24, "USB4604 Reset");
 +
 +  /* KEY */
 +  gpio_request(EXYNOS4X12_GPIO_X32, "KEY 1");
 +  gpio_request(EXYNOS4X12_GPIO_X33, "KEY 2");
 +  gpio_request(EXYNOS4X12_GPIO_X34, "KEY 3");
 +  gpio_request(EXYNOS4X12_GPIO_X35, "KEY 4");
 +  
  }

  int exynos_init(void)
View  
1  drivers/usb/gadget/dwc2_udc_otg_phy.c
 @@ -67,7 +67,6 @@ void otg_phy_init(struct dwc2_udc *dev)
    else
        writel((readl(&phy->phyclk) & ~(ID_PULLUP0 | COMMON_ON_N0)) |
               CLK_SEL_24MHZ, &phy->phyclk); /* PLL 24Mhz */
 -
    writel((readl(&phy->rstcon) &~(LINK_SW_RST | PHYLNK_SW_RST))
           | PHY_SW_RST0, &phy->rstcon);
    udelay(10);
View  
23  include/configs/tiny4412.h
 @@ -14,7 +14,7 @@
  /* High Level Configuration Options */
  #define CONFIG_EXYNOS4412         1    /* which is a EXYNOS4412 SoC */
  #define CONFIG_TINY4412               1    /* working with TINY4412 */
 -
 +#define CONFIG_SUPPORT_EMMC_BOOT  1    /* support u-boot in eMMC */

  /* DEBUG UART */
  #if ! defined(CONFIG_SPL_BUILD)
 @@ -126,22 +126,23 @@

  /*
   *    SD MMC layout:
 - *    +------------+------------------------------------------------------------+
 - *    |                                                                         |
 - *    |            |            |               |              |                |
 - *    |   512B     |   8K(bl1)  |    16k(bl2)   |   16k(ENV)   |  512k(u-boot)  |
 - *    |            |            |               |              |                |
 - *    |                                                                         |
 - *    +------------+------------------------------------------------------------+
 + *    +------------------------------------------------------------------------------------------+
 + *    |                                                                                          |
 + *    |            |            |               |              |                |                |
 + *    |   512B     |   8K(bl1)  |    16k(bl2)   |  1M(u-boot)  |    92k(TZSW)   |    16K(ENV)    |
 + *    |            |            |               |              |                |                |
 + *    |                                                                                          |
 + *    +------------------------------------------------------------------------------------------+
   *
   */
  #define CONFIG_ENV_IS_IN_MMC
 -#define CONFIG_SYS_MMC_ENV_DEV    0
 +#define CONFIG_SYS_MMC_ENV_DEV    (4)         /* Need match dts of mmc id */
  #define CONFIG_ENV_SIZE           (16 << 10)  /* 16 KB */
 -#define RESERVE_BLOCK_SIZE        (512)
  #define RESERVE_BLOCK_SIZE        (0)
  #define BL1_SIZE              (8 << 10)   /* 8K reserved for BL1*/
  #define BL2_SIZE              (16 << 10)  /* 16K reserved for BL2 */
 -#define CONFIG_ENV_OFFSET     (RESERVE_BLOCK_SIZE + BL1_SIZE + BL2_SIZE)
 +#define TZSW_SIZE             (92 << 10)  /* 92K tzsw size */
 +#define CONFIG_ENV_OFFSET     (RESERVE_BLOCK_SIZE + BL1_SIZE + BL2_SIZE + COPY_BL2_SIZE + TZSW_SIZE)

  #define CONFIG_SPL_LDSCRIPT   "board/samsung/common/exynos-uboot-spl.lds"
  #define CONFIG_SPL_MAX_FOOTPRINT  (14 * 1024)
 @@ -150,7 +151,7 @@

  /* U-Boot copy size from boot Media to DRAM.*/
  #define COPY_BL2_SIZE     0x100000
 -#define BL2_START_OFFSET  ((CONFIG_ENV_OFFSET + CONFIG_ENV_SIZE)/512)
 +#define BL2_START_OFFSET  ((RESERVE_BLOCK_SIZE + BL1_SIZE + BL2_SIZE)/512)
  #define BL2_SIZE_BLOC_COUNT   (COPY_BL2_SIZE/512)
  #endif    /* __CONFIG_H */

View  
84  sd_fuse/tiny4412/fast_fuse.sh.bkp
@@ -1,84 +0,0 @@
 -#
 -# Copyright (C) 2011 Samsung Electronics Co., Ltd.
 -#              http://www.samsung.com/
 -#
 -# This program is free software; you can redistribute it and/or modify
 -# it under the terms of the GNU General Public License version 2 as
 -# published by the Free Software Foundation.
 -#
 -####################################
 -
 -if [ -z $1 ]
 -then
 -    echo "usage: ./sd_fusing.sh <SD Reader's device file>"
 -    exit 0
 -fi
 -
 -if [ -b $1 ]
 -then
 -    echo "$1 reader is identified."
 -else
 -    echo "$1 is NOT identified."
 -    exit 0
 -fi
 -
 -####################################
 -#<verify device>
 -
 -BDEV_NAME=`basename $1`
 -BDEV_SIZE=`cat /sys/block/${BDEV_NAME}/size`
 -
 -if [ ${BDEV_SIZE} -le 0 ]; then
 -  echo "Error: NO media found in card reader."
 -  exit 1
 -fi
 -
 -if [ ${BDEV_SIZE} -gt 32000000 ]; then
 -  echo "Error: Block device size (${BDEV_SIZE}) is too large"
 -  exit 1
 -fi
 -
 -####################################
 -# check files
 -
 -E4412_UBOOT=../../u-boot.bin
 -MKBL2=../mkbl2
 -
 -if [ ! -f ${E4412_UBOOT} ]; then
 -  echo "Error: u-boot.bin NOT found, please build it & try again."
 -  exit -1
 -fi
 -
 -if [ ! -f ${MKBL2} ]; then
 -  echo "Error: can not find host tool - mkbl2, stop."
 -  exit -1
 -fi
 -
 -#<make bl2>
 -${MKBL2} ${E4412_UBOOT} bl2.bin 14336
 -
 -####################################
 -# fusing images
 -
 -bl2_position=17
 -uboot_position=49
 -
 -#<BL2 fusing>
 -echo "---------------------------------------"
 -echo "BL2 fusing"
 -dd iflag=dsync oflag=dsync if=./bl2.bin of=$1 seek=$bl2_position
 -
 -#<u-boot fusing>
 -echo "---------------------------------------"
 -echo "u-boot fusing"
 -dd iflag=dsync oflag=dsync if=${E4412_UBOOT} of=$1 seek=$uboot_position
 -
 -#<flush to disk>
 -sync
 -
 -####################################
 -#<Message Display>
 -echo "---------------------------------------"
 -echo "U-boot image is fused (at `date +%T`) successfully."
 -echo "Eject SD card and insert it again."
 -
View  
4  sd_fuse/tiny4412/fast_fusing.sh
 @@ -62,8 +62,8 @@ ${MKBL2} ${E4412_UBOOT} bl2.bin 14336

  signed_bl1_position=1
  bl2_position=17
 -uboot_position=81
 -tzsw_position=1105
 +uboot_position=49
 +tzsw_position=2097

  #<BL1 fusing>
  #echo "---------------------------------------"
View  
4  sd_fuse/tiny4412/sd_fusing.sh
 @@ -62,8 +62,8 @@ ${MKBL2} ${E4412_UBOOT} bl2.bin 14336

  signed_bl1_position=1
  bl2_position=17
 -uboot_position=81
 -tzsw_position=1105
 +uboot_position=49
 +tzsw_position=2097

  #<BL1 fusing>
  echo "---------------------------------------"
View  
2  tiny4412_config
 @@ -244,7 +244,7 @@ CONFIG_BOOTSTAGE_STASH_SIZE=4096
  # CONFIG_ONENAND_BOOT is not set
  # CONFIG_QSPI_BOOT is not set
  # CONFIG_SATA_BOOT is not set
 -# CONFIG_SD_BOOT is not set
 +CONFIG_SD_BOOT=y
  # CONFIG_SPI_BOOT is not set
  CONFIG_BOOTDELAY=2

注意:使用eMMC作为存储设备时,需要设置

#define CONFIG_SYS_MMC_ENV_DEV  (4)
#define RESERVE_BLOCK_SIZE      (0)

如果使用SD卡作为存储设备时,需要设置

#define CONFIG_SYS_MMC_ENV_DEV  (2)
#define RESERVE_BLOCK_SIZE      (512)

综上所述:

#if (0)
        #define CONFIG_SYS_MMC_ENV_DEV  (2)                     /* Need match dts of mmc id */
        #define RESERVE_BLOCK_SIZE      (512)
#else
        #define CONFIG_SYS_MMC_ENV_DEV  (4)                     /* Need match dts of mmc id */
        #define RESERVE_BLOCK_SIZE      (0)
#endif

make生成烧录文件u-boot.bintiny4412-spl.bin,将这两个文件和E4412_N.bl1.binE4412_tzsw.bin拷贝到SD卡FAT32分区

U-BOOT 拷贝

SD卡插入开发板,拨码开关拨到SD卡端,上电:

U-Boot 2017.03-gff1b95e-dirty (Aug 06 2017 - 10:45:18 +0800) for TINY4412

CPU:   Exynos4412 @ 1.4 GHz
Model: Tiny4412 based on Exynos4412
Board: Tiny4412 based on Exynos4412
DRAM:  1 GiB
WARNING: Caches not enabled
MMC:   SAMSUNG SDHCI: 2, EXYNOS DWMMC: 4
Net:   No ethernet found.
Hit any key to stop autoboot:  0 
TINY4412 # mmc list
SAMSUNG SDHCI: 2 (SD)
EXYNOS DWMMC: 4

当前包含2mmc设备

TINY4412 # mmc partconf 4 1 1 1
TINY4412 # mmc dev 4 1
switch to partitions #1, OK
mmc4(part 1) is current device

选择并切换到eMMC1个分区,写入E4412_N.bl1.bin

TINY4412 # fatload mmc 2:1 0x50000000 E4412_N.bl1.bin
reading E4412_N.bl1.bin
8192 bytes read in 14 ms (571.3 KiB/s)
TINY4412 # mmc write 0x50000000 0 0x10

MMC write: dev # 4, block # 0, count 16 ... 16 blocks written: OK

写入tiny4412-spl.bin

TINY4412 # fatload mmc 2:1 0x50000000 tiny4412-spl.bin
reading tiny4412-spl.bin
16384 bytes read in 14 ms (1.1 MiB/s)
TINY4412 # mmc write 0x50000000 0x10 0x20             

MMC write: dev # 4, block # 16, count 32 ... 32 blocks written: OK

写入u-boot.bin

TINY4412 # fatload mmc 2:1 0x50000000 u-boot.bin      
reading u-boot.bin
477329 bytes read in 32 ms (14.2 MiB/s)
TINY4412 # mmc write 0x50000000 0x30 0x800      

MMC write: dev # 4, block # 48, count 2048 ... 2048 blocks written: OK

写入E4412_tzsw.bin

TINY4412 # fatload mmc 2:1 0x50000000 E4412_tzsw.bin
reading E4412_tzsw.bin
94208 bytes read in 17 ms (5.3 MiB/s)
TINY4412 # mmc write 0x50000000 0x830 0xB8          

MMC write: dev # 4, block # 2096, count 184 ... 184 blocks written: OK

全部写入完成!

上电测试

U-Boot 2017.03-gff1b95e-dirty (Aug 06 2017 - 11:39:04 +0800) for TINY4412

CPU:   Exynos4412 @ 1.4 GHz
Model: Tiny4412 based on Exynos4412
Board: Tiny4412 based on Exynos4412
DRAM:  1 GiB
WARNING: Caches not enabled
MMC:   SAMSUNG SDHCI: 2, EXYNOS DWMMC: 4
Net:   No ethernet found.
Hit any key to stop autoboot:  0 
TINY4412 # 
TINY4412 # 
TINY4412 # mmc list
SAMSUNG SDHCI: 2
EXYNOS DWMMC: 4 (eMMC)

总结

  • SD卡最开始的512字节是DBR(分区的引导记录),位于整个SD分区的0号扇区(对应的物理扇区就是0x2000)固定512字节,其中记录着FAT文件系统的相关信息
  • 而eMMC没有512字节的保留分区,需要将偏移量设置为0

  • 注意:环境变量不能通过从SD拷贝出来,粘贴到eMMC中替换

  • 2
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值