Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9479
  • 博文数量: 1
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 10
  • 用 户 组: 普通用户
  • 注册时间: 2014-09-15 11:17
文章分类
文章存档

2014年(1)

我的朋友

分类: LINUX

2014-09-15 11:19:00

硬件: OK6410 + SDHC (8G)
TQ2440有两块flash,nor_flash与nand_flash,当需要烧写uboot的时候,只需要把开关切到nor_flash启动,在 nor_flash的uboot中就可以烧写uboot到nand_flash,非常方便。但是现在的6410没有nor_flash,每次烧写 nand_flash中的uboot的时候非常麻烦,那有没有一种方法使SD卡提供以前nor_flash的功能呢?
一、确定SD_Writer.exe写SD卡的位置
1.1 思路
     利用6410提供了SD_Writer.exe工具将mmc_ram256.bin烧到SD卡中是可以直接从SD卡启动的,然后从SD卡中导出数据分析BL1与BL2的具体位置.


                        图出自
从上图可以看出:
        SDHC卡的 BL1是在:Total_sector-Reserved-sigature-BL1=倒数第1042个扇区中
        SDHC卡的 BL1是在:Total_sector-Reserved-sigature-BL1-BL2=倒数第1042+BL2个扇区中
1.2 确定SDHC卡的总扇区数
  1. sun@ubuntu:/work/6410/uboot1.1.6$ sudo fdisk -l /dev/sdb
  2. Disk /dev/sdb: 7948 MB, 7948206080 bytes
  3. 240 heads, 32 sectors/track, 2021 cylinders, total 15523840 sectors
  4. Units = sectors of 1 * 512 = 512 bytes
  5. Sector size (logical/physical): 512 bytes / 512 bytes
  6. I/O size (minimum/optimal): 512 bytes / 512 bytes
  7. Disk identifier: 0x9139e7a9

  8.    Device Boot Start End Blocks Id System
  9. /dev/sdb1 2048 15523839 7760896 b W95 FAT32
那么BL1=Total_sector-Reserved-sigature-BL1=15523840-1042=15522798
那么BL2=Total_sector-Reserved-sigature-BL1-BL2=倒数第1042+512=1554个扇区中(这儿不能确定BL2是多大,初步定为256K)=15523840-1554=15522286
将数据从SDHC卡中导出:
  1. total_sectors=15523840
  2. 将bl1写到sd卡15523840-1042=15522798,大小为8K
  3.     sudo dd if=./bl1.bin of=/dev/sdb seek=15522798 bs=512 count=16
  4. 将bl2写到sd卡15523840-1554=15522286, 大小为512
  5.     sudo dd if=./bl2.bin of=/dev/sdb seek=15522286 bs=512 count=512
将生成的bl1.bin与mmc_ram256.bin相比较发现,的确是前8K
将生成的bl2.bin与mmc_ram256.bin相比较发现不正确,好像是少了点什么.
经过多次试验发现,少了32个sector, 这个在u-boot中定义为MOVI_ENV_BLKCNT
1.3 确认BL1与BL2的位置
将SDHC卡的BL1与BL2清除,然后从mmc_ram256.bin中分割出BL1.bin与BL2.bin,最后烧到SDHC卡的相应位置上,看是否能够正常启动,如果能启动,说明位置找对了.
  1. a. 清除sd卡的bl1 bl2
  2.     sudo dd if=/dev/zero of=/dev/sdb seek=15522254 bs=512 count=544
  3. b. 查看bl2与bl1(544+16=560)
  4.     sudo dd if=/dev/sdb of=bl.bin skip=15522254 bs=512 count=560
  5. c. 将mmc_ram256.bin分割为bl1 bl2
  6.     分出BL1:  sudo dd if=mmc_ram256.bin of=bl1.bin skip=544 bs=512 count=16
  7.     分出BL2:  sudo dd if=mmc_ram256.bin of=bl2.bin bs=512 count=544
  8. d. 将分出的BL1与BL2烧到相应的位置上
  9.     将bl1写到sd卡15523840-1042=15522798,大小为8K
            sudo dd if=./bl1.bin of=/dev/sdb seek=15522798 bs=512 count=16
        将bl2写到sd卡15523840-1586=15522254, 大小为256+16k=544 (1586=1042+512+32)
            sudo dd if=./bl2.bin of=/dev/sdb seek=15522254 bs=512 count=544
经验证正常启动
结论:  SDHC中BL1的位置是TOTAL_SECTOR-1042
         SDHC中BL2的位置是TOTAL_SECTOR-1042-BL2_Sector-ENV_sector=TOTAL_SECTOR-1586

二、烧写uboot到SD卡
make forlinx_sd_ram256_config
make
生成u-boot.bin
  1. a. 将u-boot.bin分割成bl1与bl2
  2.     分出BL1 sudo dd if=u-boot.bin of=bl1.bin bs=512 count=16
  3.     分出BL2 就是u-boot.bin
  4. b. 将分割好后的bl1 bl2写到sd卡中
  5.     写bl1:  sudo dd if=./bl1.bin of=/dev/sdb seek=15522798 bs=512 count=16            
  6.     写bl2:  sudo dd if=./u-boot.bin of=/dev/sdb seek=15522254 bs=512 count=544
  7. 注:上述命令中 /dev/sdb在不同机子可能不一样
发现一个问题:
OK6410 给的uboot虽然可以支持SDHC卡启动的,但是uboot中拷贝BL2的部分却有一点想不明白:
start.S --> movi_bl2_copy --> CopyMovitoMem(HSMMC_CHANNEL, MOVI_BL2_POS, MOVI_BL2_BLKCNT+MOVI_ENV_BLKCNT, (uint *)BL2_BASE, MOVI_INIT_REQUIRED);
中的 MOVI_BL2_POS
按照上图来说是: MOVI_BL2_POS=total_sector_fdisk -BL2-ENV-BL1-1026
而uboot中却是:
MOVI_BL2_POS=total_sector_uboot -BL2-ENV-BL1-(eFUSE_SIZE / MOVI_BLKSIZE)=MOVI_BL2_POS=total_sector -BL2-ENV-BL1-2
这两个都能得到正确的BL2的位置,因为在UBOOT中total_sector_uboot 比 total_sector_fdisk少了1024个.
不知道为什么total_sector_uboot比total_sector_fdisk少1024个?

三、补充2G

最近找了一张2G的SD卡,测试了一下
  1. 卡的信息如下:
  2.     SD 2.0 / Manufacturer: 0x03,OEM: "SD/SD02G",REV: 8.0,S/N: 1889267482,DATE: 2009/6 MMC/SD size: 1886 MiB
  3. fdisk中查看到的sector: total 3862528 sectors
  4. 打印MOVI_TOTAL_BLKCNT是: 3AF000=3862528
uboot不作任何修改,并将生成的uboot.bin写到SD卡中
  1. #!/bin/sh
  2. sudo dd if=u-boot.bin of=bl1.bin bs=512 count=16
  3. sudo dd if=./bl1.bin of=/dev/sdb seek=3862510 bs=512 count=16
  4. sudo dd if=./u-boot.bin of=/dev/sdb seek=3861966 bs=512 count=544
  5. sync

  6. #total=3862528
  7. #BL1=total-reserv-BL1=3862528-2-16=3862510
  8. #BL2=total-reserv-BL1-ENV-BL2=3862528-2-16-32-256*2=3861966
OK,正常启动,就是说这个u-boot.bin既支持SD卡又支持SDHC卡。
个人私下里猜测:三星的irom内部对SDHC卡偷偷的减了1024个扇区,就是为了u-boot能够支持多种卡,真是太替人着想了。


【参考文章】
1. 使uboot支持S3C6410的SD启动
2.s3c6410开发板研究笔记(一)从SD卡启动UBOOT
3. S3C6410开发全记录(一)《还原SD卡启动的真相》
阅读(1259) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:没有了

给主人留下些什么吧!~~