stm32mp1xxx烧写nandflash

stm32mp1xxx烧录镜像到NandFlash

网上大多数关于stm32mp1的教程都是烧录到MMC(SD卡和emmc),关于nand flash的实在太少,整理了使用stm32prog进行烧写和在linux命令行下进行烧写(使用sd卡启动)的两种方法。仅供参考,欢迎大家交流学习。

1.确定flashlayout

#Opt	Id	Name	Type	IP	Offset	Binary
-	0x01	fsbl1-boot	Binary	none	0x0	tf-a-stm32mp157d-ev1-serialboot.stm32
-	0x03	ssbl-boot	Binary	none	0x0	u-boot-stm32mp157d-ev1-trusted.stm32
P	0x04	fsbl1	Binary(2)	nand0	0x00000000	tf-a-stm32mp157d-ev1-trusted.stm32
P	0x06	ssbl	Binary	nand0	0x00200000	u-boot-stm32mp157d-ev1-trusted.stm32
P	0x07	ssbl2	Binary	nand0	0x00400000	u-boot-stm32mp157d-ev1-trusted.stm32
P	0x21	ubifs	System	nand0	0x00600000	xxx_157.ubi

2.制作ubi镜像

uboot查看nand flash参数

mtdlist

ubiinfo

UBI: MTD device name:            "UBI"
UBI: MTD device size:            1018 MiB
UBI: physical eraseblock size:   262144 bytes (256 KiB)
UBI: logical eraseblock size:    253952 bytes
UBI: number of good PEBs:        4068
UBI: number of bad PEBs:         4
UBI: smallest flash I/O unit:    4096
UBI: VID header offset:          4096 (aligned 4096)
UBI: data offset:                8192
UBI: max. allowed volumes:       128
UBI: wear-leveling threshold:    4096
UBI: number of internal volumes: 1
UBI: number of user volumes:     4
UBI: available PEBs:             0
UBI: total number of reserved PEBs: 4068
UBI: number of PEBs reserved for bad PEB handling: 76
UBI: max/mean erase counter: 2/0

ubi镜像包含包含uboot_config,uboot_config_r,boot.img,rootfs.img

根据上面获取的参数填写命令

mkfs.ubifs -F -v -r /home/hu/linux/ubi_flash/boot -o boot.img -m 4096 -e 253952 -c 4072
mkfs.ubifs -F -v -r /home/hu/linux/ubi_flash/rootfs -o rootfs.img -m 4096 -e 253952 -c 4072
mkfs.ubifs -F -v -r /home/hu/linux/ubi_flash/uboot_config -o uboot_config.img -m 4096 -e 253952 -c 4072
mkfs.ubifs -F -v -r /home/hu/linux/ubi_flash/uboot_config -o uboot_config_r.img -m 4096 -e 253952 -c 4072
-m, --min-io-size=SIZE   minimum I/O unit size
-e, --leb-size=SIZE      logical erase block size
-c, --max-leb-cnt=COUNT  maximum logical erase block count
-o, --output=FILE        output to FILE
-F, --space-fixup        file-system free space has to be fixed up on first mount
-v, --verbose            verbose operation
-r, -d, --root=DIR       build file system from directory DIR

将制作好的各个镜像分成卷放到ubifs

ubinize -v -o xxx_157.ubi -m 4096 -p 256KiB -s 4096 ubinize.cfg

-o, --output=<file name>     output file name
-v, --verbose                be verbose
-m, --min-io-size=<bytes>    minimum input/output unit size of the flash
                             in bytes
-s, --sub-page-size=<bytes>  minimum input/output unit used for UBI
                             headers, e.g. sub-page size in case of NAND
                             flash (equivalent to the minimum input/output
                             unit size by default)
-p, --peb-size=<bytes>       size of the physical eraseblock of the flash
                             this UBI image is created for in bytes,
                             kilobytes (KiB), or megabytes (MiB)
                             (mandatory parameter)

ubinize.cfg

[uboot_config]
mode=ubi
image=uboot_config.img   #mkfs.ubifs生成的文件
vol_id=0          #卷序号
vol_size=4MiB   #卷大小 
vol_name=uboot_config   #卷名
vol_type=static

[uboot_config_r]
mode=ubi
image=uboot_config_r.img   #mkfs.ubifs生成的文件
vol_id=1        #卷序号
vol_size=4MiB   #卷大小 
vol_name=uboot_config_r   #卷名
vol_type=static

[boot]
mode=ubi
image=boot.img   #mkfs.ubifs生成的文件
vol_id=2          #卷序号
vol_size=12MiB   #卷大小
vol_type=dynamic  #动态卷
vol_alignment=1   
vol_name=boot   #卷名

[rootfs]
mode=ubi
image=rootfs.img   #mkfs.ubifs生成的文件
vol_id=3          #卷序号
vol_size=10MiB   #卷大小
vol_type=dynamic  #动态卷
vol_alignment=1   
vol_name=rootfs   #卷名
vol_flags=autoresize

1.使用stm32prog直接烧录nandflash

使用FlashLayout.tsv文件进行烧录

2.使用sd卡烧录nandflash

将制作的最小linux使用stm32prog烧录到SD卡中,拨码开关从SD卡启动,进入命令行后,使用tftp将需要的镜像从虚拟机拷出来。

  • tf-a.stm32
  • u-boot.stm32
  • xxx_157.ubi

运行flash_nand.sh脚本。

#!/bin/bash

flash_eraseall /dev/mtd0
flash_eraseall /dev/mtd1
flash_eraseall /dev/mtd2
flash_eraseall /dev/mtd3
nandwrite -p -a /dev/mtd0 tf-a-stm32mp157d-ev1-trusted.stm32
nandwrite -m -p -a /dev/mtd1 u-boot.stm32
nandwrite -m -p -a /dev/mtd2 u-boot.stm32
nandwrite -m -p -a /dev/mtd3 xxx_157.ubi

脚本对nand的四个分区进行擦除,再进行烧录。

Usage: nandwrite [OPTION] MTD_DEVICE [INPUTFILE|-]
Writes to the specified MTD device.

  -a, --autoplace         Use auto OOB layout
  -m, --markbad           Mark blocks bad if write fails
  -p, --pad               Pad writes to page size

烧录完成之后,拨码开关从nandflash启动。

2.1 uboot内核启动方式

手动设置

setenv bootcmd 'ubifsmount ubi:boot;ubifsload c2000000 uImage;ubifsload c4000000 stm32mp157a-ev1.dtb;bootm c2000000 - c4000000;ubifsmount ubi:rootfs'

setenv bootargs 'ubi.mtd=UBI rootfstype=ubifs root=ubi:rootfs rootwait rw console=ttySTM0,115200'

saveenv

自动启动设置

/include/configs/stm32mp1.h

/*
#define STM32MP_BOOTCMD "bootcmd_stm32mp=" \
	"echo \"Boot over ${boot_device}${boot_instance}!\";" \
	"if test ${boot_device} = serial || test ${boot_device} = usb;" \
	"then stm32prog ${boot_device} ${boot_instance}; " \
	"else " \
		"run env_check;" \
		"if test ${boot_device} = mmc;" \
		"then env set boot_targets \"mmc${boot_instance}\"; fi;" \
		"if test ${boot_device} = nand ||" \
		  " test ${boot_device} = spi-nand ;" \
		"then env set boot_targets ubifs0; fi;" \
		"if test ${boot_device} = nor;" \
		"then env set boot_targets mmc0; fi;" \
		"run distro_bootcmd;" \
	"fi;\0"
*/
#define STM32MP_BOOTCMD "bootcmd_stm32mp=" \
	"env set bootargs \"ubi.mtd=UBI rootfstype=ubifs root=ubi:rootfs rootwait rw console=ttySTM0,115200\";" \
	"ubifsmount ubi:boot;" \
	"ubifsload c2000000 uImage;" \
	"ubifsload c4000000 stm32mp157a-ev1.dtb;" \
	"bootm c2000000 - c4000000;" \
	"ubifsmount ubi:rootfs;\0"
  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值