目前有遇到在linux下升级程序的问题,比如spinor/spinand,我们一般情况会对flash进行分区,分区查看使用
/ # cat /proc/mtd
dev: size erasesize name
mtd0: 00050000 00010000 "BOOT"
mtd1: 00200000 00010000 "KERNEL"
mtd2: 00500000 00010000 "rootfs"
mtd3: 00200000 00010000 "nvrservice"
mtd4: 006b0000 00010000 "customer"
假如我们需要对customer分区做升级,我们可以参考如下代码段:
上面可以看到customer分区是mtd4,所以我们对mtd4进行擦除,然后再写进去这样就可以了。
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/ioctl.h>
#include <sys/time.h>
#include <mtd/mtd-user.h>
#include <errno.h>
static char Buffer[16*1024*1024] = {0};
int main (int argc, char **argv)
{
int fd;
fd = open ("/dev/mtd4", O_SYNC | O