OrangePIPC2---uboot flash的适配

下载uboot源码

去我的github上下载源码,或者官方uboot都行,由于我还没装git所以先临时下载用用。
在这里插入图片描述

解压

unzip XXX.zip即可

编译

export CROSS_COMPILE=aarch64-linux-gnu-
make orangepi_pc2_defconfig
make

错误

‘swig’

在这里插入图片描述
apt-get install swig

编译正常

警告不影响,反正用我们自己提供的bl31文件
在这里插入图片描述

下载测试

sunxi-fel -v -p spl sunxi-h5-spl32-ddr3.bin write 0x44000 bl31uboot.bin write 0x4a000000 u-boot.bin reset64 0x44000
发现新编译的uboot运行成功,但是有mmc的报错,不打紧我们想要的是适配nand,让这个uboot可以使用nand。在这里插入图片描述

nand适配

nand命令支持

  1. 打开配置
    export CROSS_COMPILE=aarch64-linux-gnu-
    make menuconfig
    Device Drivers -》
    在这里插入图片描述
    发现没有现成的nand flash器件直接选着,那就先实现nand命令,后续表里添加你用的flash器件。

  2. 添加命令
    先添加设备支持Device Drivers —>NAND Device Support —> Support for NAND on Allwinner SoCs
    如果没有这个界面需要在drivers\mtd\nand\Kconfig下添加
    MACH_SUN50I_H5设备,如下文中所示在这里插入图片描述
    nand 命令支持
    Command line interface —> Device access commands —> [*] nand
    在这里插入图片描述

  3. make编译
    发现编译报错
    我们这里是因为没定义,报错,我们在uboot\include\configs\sunxi-common.h 里面定义下,因为不知道啥h5代号就先加载comm里,这里提下代号是CONFIG_MACH_SUN50I_H5
    在这里插入图片描述
    继续定义 查看数据手册得到的nand控制器基地址
    #define CONFIG_SYS_NAND_BASE 0x01C03000

还报错,原因NAND_SUNXI没定义,没有h5的设备代号,
在这里插入图片描述
加上
在这里插入图片描述
在编译
在这里插入图片描述
查看clock.h发现CONFIG_MACH_SUN50I用的是asm/arch/clock_sun6i.h,他的源文件是这个asm/arch/clock_sun6i.h,添加下定义即可
加上nand相关的bit定义
在这里插入图片描述
编译后发现生成的东西太大了,裁剪了下配置把一些文件系统支持去掉了,
4. nand信息匹配
修改代码,查看下他嫩不能读到id在这里插入图片描述

后记

本来以为norflash的焊盘可以直接替换nandflash 后来发现自己还是太年轻了,本来以为h5支持nand以为就是spi-nand,查看手册发现,支持的是并口的nand,所以调试norflash去

2.1.3.3. NAND Flash
  Compliant with ONFI 2.3 and Toggle 1.0
  Up to 2 flash chips
  8-bit data bus width
  Up to 64-bit ECC per 1024 bytes
  Supports 1024, 2048, 4096, 8192, 16K bytes size per page
  Supports SLC/MLC/TLC flash and EF-NAND memory
  Supports SDR, ONFI DDR and Toggle DDR NAND
  Embedded DMA to do data transfer
  Supports data transfer together with normal DMA

nor适配

  1. 打开配置
    export CROSS_COMPILE=aarch64-linux-gnu-
    make menuconfig
  2. 驱动支持
    Device Drivers -》SPI Flash Support —> 选下型号
  3. 命令支持sf
    Command line interface —> Device access commands —> [*] sf

编译报错

rivers/mtd/spi/built-in.o: In function `spi_flash_probe':
/data1/huangkai14/work/openSource/myOrgPiPc2Pro_uboot-master/drivers/mtd/spi/sf_probe.c:64: undefined reference to `spi_setup_slave'
drivers/mtd/spi/built-in.o: In function `spi_flash_probe_slave':
/data1/huangkai14/work/openSource/myOrgPiPc2Pro_uboot-master/drivers/mtd/spi/sf_probe.c:38: undefined reference to `spi_claim_bus'
drivers/mtd/spi/built-in.o: In function `spi_flash_probe':
/data1/huangkai14/work/openSource/myOrgPiPc2Pro_uboot-master/drivers/mtd/spi/sf_probe.c:77: undefined reference to `spi_free_slave'
drivers/mtd/spi/built-in.o: In function `spi_flash_probe_slave':
/data1/huangkai14/work/openSource/myOrgPiPc2Pro_uboot-master/drivers/mtd/spi/sf_probe.c:53: undefined reference to `spi_release_bus'
drivers/mtd/spi/built-in.o: In function `spi_flash_free':
/data1/huangkai14/work/openSource/myOrgPiPc2Pro_uboot-master/drivers/mtd/spi/sf_probe.c:90: undefined reference to `spi_free_slave'
drivers/mtd/spi/built-in.o: In function `spi_flash_read_common':
/data1/huangkai14/work/openSource/myOrgPiPc2Pro_uboot-master/drivers/mtd/spi/spi_flash.c:438: undefined reference to `spi_claim_bus'
/data1/huangkai14/work/openSource/myOrgPiPc2Pro_uboot-master/drivers/mtd/spi/spi_flash.c:450: undefined reference to `spi_release_bus'
drivers/mtd/spi/built-in.o: In function `spi_flash_write_common':
/data1/huangkai14/work/openSource/myOrgPiPc2Pro_uboot-master/drivers/mtd/spi/spi_flash.c:284: undefined reference to `spi_claim_bus'

这是因为需要dm以及spi驱动框架 的支持
DM框架下的驱动
CONFIG_DM_SPI_FLASH
CONFIG_DM_SPI:

再次报错

drivers/spi/built-in.o: In function `sun4i_spi_set_clock':
/data1/huangkai14/work/openSource/myOrgPiPc2Pro_uboot-master/drivers/spi/spi-sunxi.c:265: undefined reference to `clk_disable'
/data1/huangkai14/work/openSource/myOrgPiPc2Pro_uboot-master/drivers/spi/spi-sunxi.c:266: undefined reference to `clk_disable'
/data1/huangkai14/work/openSource/myOrgPiPc2Pro_uboot-master/drivers/spi/spi-sunxi.c:272: undefined reference to `clk_enable'
/data1/huangkai14/work/openSource/myOrgPiPc2Pro_uboot-master/drivers/spi/spi-sunxi.c:278: undefined reference to `clk_enable'

因为使用了dm框架所以clk也需要dm的支持
clk_disable->./drivers/clk/clk-uclass.c:383:int clk_disable(struct clk *clk)

发现在这里定义clk相关,以及打开h3/h5的clk相关配置
clk-uclass.o
CONFIG_CLK-》CONFIG_CLK_SUNXI-》CONFIG_CLK_SUN8I_H3

在编译已经可以了

运行
./sunxi-fel -v -p spl sunxi-h5-spl32-ddr3.bin write 0x44000 bl31uboot.bin write 0x4a000000 u-boot.bin reset64 0x44000
Stack pointers: sp_irq=0x00012000, sp=0x00015E08
MMU is not enabled by BROM
=> Executing the SPL… done.
100% [] 33 kB, 563.0 kB/s
100% [
] 509 kB, 572.7 kB/s

查看命令

AK # sf 
sf - SPI flash sub-system

Usage:
sf probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus

AK # sf probe
sunxi spi probe
SF: unrecognized JEDEC id bytes: ef, 40, 21
Failed to initialize SPI flash at 0:0 (error -2)
AK # 

漂亮,读到了id检查下flash的datasheet,是否读到的正确,这里报错无非就是uboot里面的flash表里面没有这个型号,添加上即可

添加uboot列表的flash型号

flash ids

找到flashtable,spi_flash_ids(drivers\mtd\spi\spi_flash_ids.c)
{“w25q01jv”, INFO(0xef4021, 0x0, 64 * 1024, 2048, RD_FULL | WR_QPP | SECT_4K) },
这里的id虽然写的是sector,但是代码中read和erase都用这个参数,所以一般这个sector就位擦除的一个block大小一般64k

3字节地址

添加flashid后编译运行发现有警告,一看说只能访问低16M,那么一看就马上联想到,是地址字节数相关的东西,因为3字节地址最大就只能访问16M的空间。
AK # sf probe
sunxi spi probe
SF: Detected w25q01jv with page size 256 Bytes, erase size 4 KiB, total 128 MiB
SF: Warning - Only lower 16MiB accessible, Full access #define CONFIG_SPI_FLASH_BAR

这里也给你提示了这个宏CONFIG_SPI_FLASH_BAR,因为方位16M之外的,需要访问bank address register 的ba24 bit。
那么很简单在cfg文件下定义下
这里提下uboot的配置
1.一般我们编译相关和menuconfig的在这
\configs\orangepi_pc2_defconfig
2. 配置宏定义板子相关的定义在这\include\configs\sun50i.h

#define CONFIG_SERVERIP 192.168.5.100
#define CONFIG_IPADDR 192.168.5.123
/*
 * Flash orange pipc 2板载 2M nor flash
 */
   添加这一行
#define CONFIG_SPI_FLASH_BAR
......

测试

在编译运行,没有警告
AK # sf probe
sunxi spi probe
SF: Detected w25q01jv with page size 256 Bytes, erase size 4 KiB, total 128 MiB
AK #

  1. tftp文件查看下内容
    AK # tftp uImage
    ethernet@1c30000 Waiting for PHY auto negotiation to complete… done
    Using ethernet@1c30000 device
    AK # md 0x42000000 3
    42000000: 56190527 05626f27 5681a962 '…V’ob.b…V
    AK #
  2. 读下flash原来内容
    AK # sf read 0x41000000 0 0x200
    device 0 offset 0x0, size 0x200
    SF: 512 bytes @ 0x0 Read: OK
    AK # md 0x41000000 3
    41000000: ea000a15 eafffffe eafffffe …
    AK #
  3. 擦除功能,这个擦除注意block对齐,不然会报错error
    AK # sf erase 0 0x10000
    SF: 65536 bytes @ 0x0 Erased: OK
    AK # sf read 0x41000000 0 0x200
    device 0 offset 0x0, size 0x200
    SF: 512 bytes @ 0x0 Read: OK
    AK # md 0x41000000 3
    41000000: ffffffff ffffffff ffffffff …
    AK #
  4. 写功能
    AK # sf write 0x42000000 0x00 0x200
    device 0 offset 0x0, size 0x200
    SF: 512 bytes @ 0x0 Written: OK
    AK # sf read 0x41000000 0 0x200
    device 0 offset 0x0, size 0x200
    SF: 512 bytes @ 0x0 Read: OK
    AK # md 0x41000000 3
    41000000: 56190527 05626f27 5681a962 '…V’ob.b…V
    AK #
  5. 完美成功。
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值