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.

解决AM335 u-boot 2013.10 SD卡不能启动u-boot的bug



使用create-sdcard.sh进行分区,分区后boot分区大小为72M

复制MLO和u-boot到SD卡中,启动时打印:

boot from SD card...
spl: fat register err - -1

检查u-boot源码发现,fat注册的代码有bug

首先确保Ti_armv7_common.h (include\configs)中,sd卡分区号定义如下:

/* FAT sd card locations. */
#define CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION    1               //不能定义为0,否则当SD卡存在MBR就不能加载FAT。
#define CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME    "u-boot.img"

再看

int fat_register_device(block_dev_desc_t *dev_desc, int part_no)
{
    disk_partition_t info;

    /* First close any currently found FAT filesystem */
    cur_dev = NULL;

    /* Read the partition table, if present */
    // get_partition_info( ,0 , )
    if (get_partition_info(dev_desc, part_no, &info)) {
        printf("get_partition_info(dev_desc, part_no, &info) failed\n");//richard
//        if (part_no != 0) {
//            printf("** Partition %d not valid on device %d **\n",
//                    part_no, dev_desc->dev);
//            return -1;
//        }

        info.start = 0;
        info.size = dev_desc->lba;
        info.blksz = dev_desc->blksz;
        info.name[0] = 0;
        info.type[0] = 0;
        info.bootable = 0;
#ifdef CONFIG_PARTITION_UUIDS
        info.uuid[0] = 0;
#endif
    }

    return fat_set_blk_dev(dev_desc, &info);
}

我把红色代码注释掉了,如果不注释掉,当SD卡不存在MBR时(即SD卡此时作为超级软盘),当执行if (get_partition_info(dev_desc, part_no, &info)分支时就会直接返回错误,串口打印spl: fat register err - -1错误。

而注释掉红色代码后,如果SD卡不存在MBR,就会执行fat_set_blk_dev,检查0号扇区上的DBR,这时SD卡就能启动了。此时不管你的SD卡之前是用什么工具格式化的,都能正常启动u-boot了。

后来看了2015.04的代码,denx依然没有修复这个bug。

  • 请问您是在TI的demo板上还是自己的板子上测试的?我们在demo板上测试过没发现类似问题啊

  • 我是在自己的板子上测试的,这个bug和硬件无关。我上面写错了,create-sdcard.sh正常情况下一定会产生MBR的,应当说假如使用某个工具对SD卡格式化时,有可能格式化成没有MBR的SD卡,此时一定会打印spl: fat register err - -1的,但是这样的SD卡插入电脑是能正常显示分区的,只能说u-boot本身对文件系统的识别不够完善。

    您想测试这个问题的话,可以用dd命令将SD卡的MBR清除掉,再使用mkfs.vfat将sdb格式化为fat32格式,就能检测到这个问题了。

    当然,如果使用sfdisk工具分区的话,正常情况下是会产生MBR的,但是我有时候会使用windows下的工具进行格式化,如diskgenius。且sfdisk有时也会不正常工作。

  • 感谢提供这么好的文档,可以进FAQ了