文章目录

  • 一、fastboot
  • 二、adb
  • 三、尝试
  • 1. 尝试连接到 PC
  • 2. 配置 fastboot 协议
  • 3. xhr4412 配置
  • 4. 烧写 u-boot.bin
  • 5. 找 bug
  • 5.1 MMC: no card present
  • 5.2 cannot find partition: 'kernel'
  • 四、spl
  • 五、启动效果
  • 1. boot from sd-card
  • 2. boot from emmc
  • 参考

   前面都是从 tf 卡启动,后续还是需要从 emmc 中启动才方便。

   当前源码下载:xhr4412-uboot-2020.07-emmc-boot.tar.bz2

一、fastboot

   启动首先需要能把 u-boot.bin 烧写到 emmc 中才行,所以需要 fastboot 的支持。

查看文件 cmd/Makefile

  • obj-$(CONFIG_CMD_FASTBOOT) += fastboot.o

支持 fastboot 需要该宏的支持,打开该配置。

emmc UBI 系统_嵌入式

emmc UBI 系统_u-boot_02

emmc UBI 系统_emmc UBI 系统_03

在 Device Drivers 中的 Fastboot support 中进行设置:

emmc UBI 系统_嵌入式_04

配置好以后就有 fastboot 的命令了。还应该打开 ANDROID_BOOT_IMAGE,但是没找到。

emmc UBI 系统_嵌入式_05

emmc UBI 系统_u-boot_06

二、adb

从 https://adbdownload.info/ 下载 adb 驱动并安装。

三、尝试

1. 尝试连接到 PC

   启动开发板,执行命令:fastboot 0 ,报错 g_dnl_register: failed!, error: -19

  • “g_dnl_register: failed!, error: -19”
  • Imx6 Easy Installer Error WEC2013

   经过一番研究,应该是 u-boot 没有定义 otg device,需要移植一下。

文件:board/samsung/xhr4412/xhr4412.c

#include <usb/dwc2_udc.h>
#include <log.h>

#ifdef CONFIG_XHR4412
static int s5pc210_phy_control(int on)
{
	return 0;
}

struct dwc2_plat_otg_data s5pc210_otg_data = {
	.phy_control	= s5pc210_phy_control,
	.regs_phy	= EXYNOS4X12_USBPHY_BASE,
	.regs_otg	= EXYNOS4X12_USBOTG_BASE,
	.usb_phy_ctrl	= EXYNOS4X12_USBPHY_CONTROL,
	.usb_flags	= PHY0_SLEEP,
};
#endif

int board_usb_init(int index, enum usb_init_type init)
{
#ifdef CONFIG_XHR4412
	debug("USB_udc_probe\n");
	return dwc2_udc_probe(&s5pc210_otg_data);
#else
	return 0;
#endif
}

移植后可以扫描到一下设备:

emmc UBI 系统_linux_07

2. 配置 fastboot 协议

  • uboot fastboot原理

   关于fastboot相关宏的解释,可以参考 cmd/fastboot/Kconfig 文件。下面说一下在uboot中配置支持fastboot。

  1. uboot中已实现对fastboot协议的支持:drivers/usb/gadget/fastboot.c:fastboot usb function源码;doc/README.android-fastboot:fastboot使能说明文档;doc/README.android-fastboot-protocol:fastboot协议说明文档;
  2. uboot中要使能fastboot,需要在板级配置打开以下的宏:

使能fastboot 1 CONFIG_FASTBOOT 2 CONFIG_USB_FUNCTION_FASTBOOT 3 CONFIG_CMD_FASTBOOT 4 CONFIG_ANDROID_BOOT_IMAGE 这个不需要

uboot在命令行中可以通过fastboot命令进入fastboot模式。

  1. 使能fastboot usb gadget

因为fastboot协议是基于usb gadget,所以需要打开或配置以下几个宏:

配置usb gadget 1 CONFIG_USB_GADGET_DOWNLOAD 2 CONFIG_USB_GADGET_VENDOR_NUM 3 CONFIG_USB_GADGET_PRODUCT_NUM 4 CONFIG_USB_GADGET_MANUFACTURER

   这里面指定的 VID 和 PID 必须要在fastboot client中能找到,如果没有,也可以用ubuntu fastboot命令的以下选项指定设备。

"fastboot 命令指定特定的设备"
1  -s <specific device>		"specify device serial number or path to device port"
2  -i <vendor id>			"specify a custom USB vendor id"
3  -p <product>				"specify product name"
  1. 配置缓冲区地址和大小

   fastboot需要一块大的内存区域用来下载,需要配置 CONFIG_FASTBOOT_BUF_ADDR 缓冲区的起始地址以及 CONFIG_FASTBOOT_BUF_SIZE 大小,这两个值决定了你可以通过fastboot烧写多大的镜像。

配置缓冲区地址和大小 1 CONFIG_FASTBOOT_BUF_ADDR=0x70000000 2 CONFIG_FASTBOOT_BUF_SIZE=0x100000

  1. 配置 fastboot flash 命令的支持

   如果想要通过fastboot flash命令烧写到flash上,必须打开 CONFIG_FASTBOOT_FLASH 相关的配置。比如我板子上使用的是eMMC,必须使能如下的宏:

配置支持flash 1 CONFIG_FASTBOOT_FLASH=y 2 CONFIG_FASTBOOT_FLASH_MMC=y 3 CONFIG_FASTBOOT_FLASH_MMC_DEV=0

3. xhr4412 配置

根据 itop4412 的配置改一改。

configs/itop4412_defconfig:63:CONFIG_USB_GADGET_VENDOR_NUM=0x18d1
configs/itop4412_defconfig:64:CONFIG_USB_GADGET_PRODUCT_NUM=0x4e30

改好后,终于出现了设备:

emmc UBI 系统_u-boot_08

4. 烧写 u-boot.bin

连接 fastboot 后,可以看到命令能够执行,找到开发板,但是 u-boot 似乎还没有支持 mmc。

emmc UBI 系统_linux_09

emmc UBI 系统_linux_10

移植一下设备树文件 xhr4412.dts,仍然还是无法识别到卡,还需要再移植一些 mmc 的程序。

  • env\mmc.c
  • cmd\mmc.c
  • arch\arm\mach-exynos\clock.cunsigned long get_mmc_clk(int dev_index)

5. 找 bug

5.1 MMC: no card present

   找不到 mmc。移植了上面的程序后好像已经可以识别到 emmc 了(记不清了),这个问题实际是没有识别到 sd,原因是需要注释掉一个函数指针,至于它是干嘛的,我也不清楚,但是如果该指针不为 NULL 或是返回值为 0,就不会继续去识别 sd 卡。

drivers/mmc/sdhci.c 里的这一行需要注释,找到这个 bug 真是废了不少力气。

const struct dm_mmc_ops sdhci_ops = {
        .send_cmd       = sdhci_send_command,
        .set_ios        = sdhci_set_ios,
#ifndef CONFIG_XHR4412
        .get_cd         = sdhci_get_cd,    // 一定要注释掉这一行
#endif
        .deferred_probe = sdhci_deferred_probe,
#ifdef MMC_SUPPORTS_TUNING
        .execute_tuning = sdhci_execute_tuning,
#endif
};

5.2 cannot find partition: ‘kernel’

emmc UBI 系统_fastboot_11

   这个问题会导致通过 fastboot 下载的程序无法烧写到 emmc 中,解决办法是将分区硬编码到 u-boot 中,然后通过 u-boot command 将 bin 文件烧写到 emmc。


   上面两个两个解决后,就已经可以通过 fastboot 命令将 bin 烧写到 emmc 中了,通过在 spl 点灯可以看到已经可以从 emmc 中启动了。不过还要解决最后一个问题,spl 还没有支持 emmc,完整的 u-boot 还没有正确拷贝到内存中执行。

四、spl

   经过检查,并不是 spl 还不支持 emmc,而是因为检查启动模式时有些问题,没有将开发板该 emmc 通道的模式添加上,所以之前 spl 没有将 u-boot 拷贝到内存中,添加该模式的判断后就可以从 emmc 启动了

五、启动效果

   首先将 u-boot.bin 烧写到 sd 卡,然后通过 fastboot 命令将 u-boot.bin 烧写到 emmc,命令如下:

  • 开发板上:fastboot 0
  • PC上:fastboot.exe flash bootloader xhr4412-uboot.bin

1. boot from sd-card

emmc UBI 系统_u-boot_12

2. boot from emmc

emmc UBI 系统_fastboot_13


   两种不同的启动方式,当前的 mmc 设备是不一样的,那么到这里关于 u-boot-2020.07 的移植已经算比较成功了。

   后续对最新的 linux kernel 进行移植,可能相应的也需要修改一些 u-boot 的配置。

   当前源码下载:xhr4412-uboot-2020.07-emmc-boot.tar.bz2

参考

  • exynos 4412 eMMC配置及使用方法
  • uboot fastboot原理
  • [mmc subsystem] host(第一章)——概述
  • uboot mmc命令详解
  • windows10 ADB interface驱动安装之安卓web调试
  • ADB-Driver-v1.4.2.zip
  • https://adbdownload.info/