• flashrom读写flash bin文件


    1、设备树中添加spidev0.0

    
    &spi0 {
    	/* Disable SPI NOR by default: it optional on Orange Pi Zero boards */
    	pinctrl-names = "default";
     	pinctrl-0 = <&spi0_pins>;
     	status = "okay";
    
    	spidev@0{
    		compatible = "Allwinner,sun8i-h2-spi0";
    		reg = <0>;
    		spi-max-frequency = <40000000>;
    		
    		// 128M spi-nor flash layout
     		partition@00000000 {
     			label = "u-boot";
     			reg = <0x00000000 0x000C0000>;
     		};
     	
     		partition@000C0000 {
     			label = "bootenv";
     			reg = <0x000C0000 0x00020000>;
     		};
     
     		partition@000E0000 {
     			label = "dtb";
     			reg = <0x000E0000 0x00020000>;
     		};
     	
     		partition@00100000 {
     			label = "kernel";
     			reg = <0x00100000 0x00500000>;
     		};
     
     		partition@00600000 {
     			label = "rootfs";
     			reg = <0x00600000 0x00A00000>;
     		};
    	};
    };  

    2、驱动中添加compatiable

    3、uboot配置

    u-boot/configs/nano_c1_defconfig:

    CONFIG_SPI_SUNXI=y
    CONFIG_SPL_SPI_FLASH_SUPPORT=y
    

    4、make menuconfig -->utils-配置flashrom包

    CONFIG_PACKAGE_flashrom=y
    

    5、(查看读写的flash型号flashrom是否已经添加,没有添加自己需要添加)增加要读写的flash信息(以XMC为例)

    //flashchips.c文件
    
    
    {
    		.vendor		= "XinXin",
    		.name		= "XM25QH128C",
    		.bustype	= BUS_SPI,
    		.manufacture_id	= ST_ID,
    		.model_id	= ST_XM25QH128C,
    		.total_size	= 16384,
    		.page_size	= 256,
    		/* OTP: 1536B total; read 0x48; write 0x42, erase 0x44 */
    		/* QPI: enable 0x38, disable 0xFF */
    		.feature_bits	= FEATURE_WRSR_WREN | FEATURE_OTP | FEATURE_QPI,
    		.tested		= TEST_OK_PREW,
    		.probe		= probe_spi_rdid,
    		.probe_timing	= TIMING_ZERO,
    		.block_erasers	=
    		{
    			{
    				.eraseblocks = { {4 * 1024, 4096} },
    				.block_erase = spi_block_erase_20,
    			}, {
    				.eraseblocks = { {32 * 1024, 512} },
    				.block_erase = spi_block_erase_52,
    			}, {
    				.eraseblocks = { {64 * 1024, 256} },
    				.block_erase = spi_block_erase_d8,
    			}, {
    				.eraseblocks = { {16 * 1024 * 1024, 1} },
    				.block_erase = spi_block_erase_60,
    			}, {
    				.eraseblocks = { {16 * 1024 * 1024, 1} },
    				.block_erase = spi_block_erase_c7,
    			}
    		},
    		/* TODO: 2nd status reg (read 0x35, write 0x31) and 3rd status reg (read 0x15, write 0x11) */
    		.printlock	= spi_prettyprint_status_register_bp4_srwd,
    		.unlock		= spi_disable_blockprotect_bp4_srwd,
    		.write		= spi_chip_write_256,
    		.read		= spi_chip_read, /* Fast read (0x0B) and multi I/O supported */
    		.voltage	= {2700, 3600},
    	},
    

     定义设备和厂商ID

    //flashchips.h文件
    #define ST_XM25QH128C 0x4018

    6、系统编译成功后会在/usr/sbin下生成flashrom工具

    根据一下命令读写:

    read flash:    flashrom -p linux_spi:dev=/dev/spidev0.0 -r  flash.bin
    write flash:   flashrom -p linux_spi:dev=/dev/spidev0.0 -w  flash.bin
    

     其他命令也可以flashrom -h去查看

    root@OpenWrt:/# flashrom -h
    flashrom v1.2 on Linux 5.4.124 (armv7l)
    flashrom is free software, get the source code at https://flashrom.org
    
    Usage: flashrom [-h|-R|-L|
            -p <programmername>[:<parameters>] [-c <chipname>]
                    (--flash-name|--flash-size|
                     [-E|(-r|-w|-v) <file>]
                     [(-l <layoutfile>|--ifd| --fmap|--fmap-file <file>) [-i <imagename>]...]
                     [-n] [-N] [-f])]
            [-V[V[V]]] [-o <logfile>]
    
     -h | --help                        print this help text
     -R | --version                     print version (release)
     -r | --read <file>                 read flash and save to <file>
     -w | --write <file>                write <file> to flash
     -v | --verify <file>               verify flash against <file>
     -E | --erase                       erase flash memory
     -V | --verbose                     more verbose output
     -c | --chip <chipname>             probe only for specified flash chip
     -f | --force                       force specific operations (see man page)
     -n | --noverify                    don't auto-verify
     -N | --noverify-all                verify included regions only (cf. -i)
     -l | --layout <layoutfile>         read ROM layout from <layoutfile>
          --flash-name                  read out the detected flash name
          --flash-size                  read out the detected flash size
          --fmap                        read ROM layout from fmap embedded in ROM
          --fmap-file <fmapfile>        read ROM layout from fmap in <fmapfile>
          --ifd                         read layout from an Intel Firmware Descriptor
     -i | --image <name>                only flash image <name> from flash layout
     -o | --output <logfile>            log output to <logfile>
          --flash-contents <ref-file>   assume flash contents to be <ref-file>
     -L | --list-supported              print supported devices
     -p | --programmer <name>[:<param>] specify the programmer device. One of
        internal, dummy, gfxnvidia, drkaiser, satasii, atavia, it8212, ft2232_spi,
        serprog, buspirate_spi, dediprog, developerbox, pony_spi, nicintel,
        nicintel_spi, nicintel_eeprom, ogp_spi, linux_mtd, linux_spi,
        usbblaster_spi, mstarddc_spi, pickit2_spi, ch341a_spi, digilent_spi,
        stlinkv3_spi.
    
    You can specify one of -h, -R, -L, -E, -r, -w, -v or no operation.
    If no operation is specified, flashrom will only probe for flash chips.
    

     

  • 相关阅读:
    WordPress手机端插件——WPtouch
    WordPress404页面自定义
    WordPress浏览数插件的安装使用
    WordPress的SEO插件——WordPress SEO by yoast安装及使用
    WordPress友情链接插件的安装
    各大搜索引擎提交入口
    thinkphp博客项目纪录
    新概念英语第一册——视频
    ThinkPHP自定义错误页面、成功页面及异常页面
    豪情后台模板,图标大全
  • 原文地址:https://www.cnblogs.com/yuanqiangfei/p/15215662.html
Copyright © 2020-2023  润新知