您尚未登录。

楼主 #1 2019-04-24 20:30:38

迪卡
会员
所在地: 河北
注册时间: 2018-11-02
已发帖子: 916
积分: 903
个人网站

如何更新SPI flash里的内核或文件系统

比如荔枝派nano,我使用sunxi-fel烧写了固件,我想更新一下内核,我该如何操作呢?
flashcp什么的是应用程序,但现在程序是没有办法传到nano里面的

离线

#2 2019-04-24 20:31:49

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,342
积分: 9202

Re: 如何更新SPI flash里的内核或文件系统

你是想要在 Linux 里面做 OTA 对吗?

在Linux  运行的时候刷 Linux ?





离线

楼主 #3 2019-04-24 20:37:01

迪卡
会员
所在地: 河北
注册时间: 2018-11-02
已发帖子: 916
积分: 903
个人网站

Re: 如何更新SPI flash里的内核或文件系统

我是想用荔枝派的固件,,更新一下内核。
因为荔枝派的内核缺少配置

离线

#4 2019-04-24 20:39:13

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,342
积分: 9202

Re: 如何更新SPI flash里的内核或文件系统

在 busybox 里面开启 flash utils, 包括 flashcp, flash_eraseall 等,

然后命令执行

flashcp zImage /dev/mtdX -v

这样重启之后就是跑新固件了,

前提是要生成 mtd 分区, linux 在一个单独的 mtd 分区, 并且这个分区不是只读.





离线

#5 2019-04-24 20:40:43

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,342
积分: 9202

Re: 如何更新SPI flash里的内核或文件系统

上面是命令行操作,

如果想要把 固件更新整合到自己的应用程序,

把下面的代码整进来即可:

https://git.busybox.net/busybox/tree/miscutils/flashcp.c

/* vi: set sw=4 ts=4: */
/*
 * busybox reimplementation of flashcp
 *
 * (C) 2009 Stefan Seyfried <seife@sphairon.com>
 *
 * Licensed under GPLv2, see file LICENSE in this source tree.
 */
//config:config FLASHCP
//config:	bool "flashcp (5.3 kb)"
//config:	default n  # doesn't build on Ubuntu 8.04
//config:	help
//config:	The flashcp binary, inspired by mtd-utils as of git head 5eceb74f7.
//config:	This utility is used to copy images into a MTD device.

//applet:IF_FLASHCP(APPLET(flashcp, BB_DIR_USR_SBIN, BB_SUID_DROP))
/* not NOEXEC: if flash operation stalls, use less memory in "hung" process */

//kbuild:lib-$(CONFIG_FLASHCP) += flashcp.o

//usage:#define flashcp_trivial_usage
//usage:       "-v FILE MTD_DEVICE"
//usage:#define flashcp_full_usage "\n\n"
//usage:       "Copy an image to MTD device\n"
//usage:     "\n	-v	Verbose"

#include "libbb.h"
#include <mtd/mtd-user.h>

/* If 1, simulates "flashing" by writing to existing regular file */
#define MTD_DEBUG 0

#define OPT_v (1 << 0)

#define BUFSIZE (4 * 1024)

static void progress(int mode, uoff_t count, uoff_t total)
{
	uoff_t percent;

	if (!option_mask32) //if (!(option_mask32 & OPT_v))
		return;
	percent = count * 100;
	if (total)
		percent = (unsigned) (percent / total);
	printf("\r%s: %"OFF_FMT"u/%"OFF_FMT"u (%u%%) ",
		(mode < 0) ? "Erasing block" : ((mode == 0) ? "Writing kb" : "Verifying kb"),
		count, total, (unsigned)percent);
	fflush_all();
}

static void progress_newline(void)
{
	if (!option_mask32) //if (!(option_mask32 & OPT_v))
		return;
	bb_putchar('\n');
}

int flashcp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int flashcp_main(int argc UNUSED_PARAM, char **argv)
{
	int fd_f, fd_d; /* input file and mtd device file descriptors */
	int i;
	uoff_t erase_count;
	struct mtd_info_user mtd;
	struct erase_info_user e;
	struct stat statb;
//	const char *filename, *devicename;
	RESERVE_CONFIG_UBUFFER(buf, BUFSIZE);
	RESERVE_CONFIG_UBUFFER(buf2, BUFSIZE);

	/*opts =*/ getopt32(argv, "^" "v" "\0" "=2"/*exactly 2 non-option args: file,dev*/);
	argv += optind;
//	filename = *argv++;
//	devicename = *argv;
#define filename argv[0]
#define devicename argv[1]

	/* open input file and mtd device and do sanity checks */
	fd_f = xopen(filename, O_RDONLY);
	fstat(fd_f, &statb);
	fd_d = xopen(devicename, O_SYNC | O_RDWR);
#if !MTD_DEBUG
	if (ioctl(fd_d, MEMGETINFO, &mtd) < 0) {
		bb_error_msg_and_die("%s is not a MTD flash device", devicename);
	}
	if (statb.st_size > mtd.size) {
		bb_error_msg_and_die("%s bigger than %s", filename, devicename);
	}
#else
	mtd.erasesize = 64 * 1024;
#endif

	/* always erase a complete block */
	erase_count = (uoff_t)(statb.st_size + mtd.erasesize - 1) / mtd.erasesize;
	/* erase 1 block at a time to be able to give verbose output */
	e.length = mtd.erasesize;
#if 0
/* (1) bloat
 * (2) will it work for multi-gigabyte devices?
 * (3) worse wrt error detection granularity
 */
	/* optimization: if not verbose, erase in one go */
	if (!opts) { // if (!(opts & OPT_v))
		e.length = mtd.erasesize * erase_count;
		erase_count = 1;
	}
#endif
	e.start = 0;
	for (i = 1; i <= erase_count; i++) {
		progress(-1, i, erase_count);
#if !MTD_DEBUG
		if (ioctl(fd_d, MEMERASE, &e) < 0) {
			bb_perror_msg_and_die("erase error at 0x%llx on %s",
				(long long)e.start, devicename);
		}
#else
		usleep(100*1000);
#endif
		e.start += mtd.erasesize;
	}
	progress_newline();

	/* doing this outer loop gives significantly smaller code
	 * than doing two separate loops for writing and verifying */
	for (i = 0; i <= 1; i++) {
		uoff_t done;
		unsigned count;

		xlseek(fd_f, 0, SEEK_SET);
		xlseek(fd_d, 0, SEEK_SET);
		done = 0;
		count = BUFSIZE;
		while (1) {
			uoff_t rem;

			progress(i, done / 1024, (uoff_t)statb.st_size / 1024);
			rem = statb.st_size - done;
			if (rem == 0)
				break;
			if (rem < BUFSIZE)
				count = rem;
			xread(fd_f, buf, count);
			if (i == 0) {
				int ret;
				if (count < BUFSIZE)
					memset((char*)buf + count, 0, BUFSIZE - count);
				errno = 0;
				ret = full_write(fd_d, buf, BUFSIZE);
				if (ret != BUFSIZE) {
					bb_perror_msg_and_die("write error at 0x%"OFF_FMT"x on %s, "
						"write returned %d",
						done, devicename, ret);
				}
			} else { /* i == 1 */
				xread(fd_d, buf2, count);
				if (memcmp(buf, buf2, count) != 0) {
					bb_error_msg_and_die("verification mismatch at 0x%"OFF_FMT"x", done);
				}
			}

			done += count;
		}

		progress_newline();
	}
	/* we won't come here if there was an error */

	return EXIT_SUCCESS;
}




离线

#6 2020-08-20 16:16:17

angelsan
会员
注册时间: 2020-04-02
已发帖子: 139
积分: 131.5

Re: 如何更新SPI flash里的内核或文件系统

那么如果是SD Nand,该怎么操作呢?
谢谢

晕哥 说:

上面是命令行操作,

如果想要把 固件更新整合到自己的应用程序,

把下面的代码整进来即可:

https://git.busybox.net/busybox/tree/miscutils/flashcp.c

/* vi: set sw=4 ts=4: */
/*
 * busybox reimplementation of flashcp
 *
 * (C) 2009 Stefan Seyfried <seife@sphairon.com>
 *
 * Licensed under GPLv2, see file LICENSE in this source tree.
 */
//config:config FLASHCP
//config:	bool "flashcp (5.3 kb)"
//config:	default n  # doesn't build on Ubuntu 8.04
//config:	help
//config:	The flashcp binary, inspired by mtd-utils as of git head 5eceb74f7.
//config:	This utility is used to copy images into a MTD device.

//applet:IF_FLASHCP(APPLET(flashcp, BB_DIR_USR_SBIN, BB_SUID_DROP))
/* not NOEXEC: if flash operation stalls, use less memory in "hung" process */

//kbuild:lib-$(CONFIG_FLASHCP) += flashcp.o

//usage:#define flashcp_trivial_usage
//usage:       "-v FILE MTD_DEVICE"
//usage:#define flashcp_full_usage "\n\n"
//usage:       "Copy an image to MTD device\n"
//usage:     "\n	-v	Verbose"

#include "libbb.h"
#include <mtd/mtd-user.h>

/* If 1, simulates "flashing" by writing to existing regular file */
#define MTD_DEBUG 0

#define OPT_v (1 << 0)

#define BUFSIZE (4 * 1024)

static void progress(int mode, uoff_t count, uoff_t total)
{
	uoff_t percent;

	if (!option_mask32) //if (!(option_mask32 & OPT_v))
		return;
	percent = count * 100;
	if (total)
		percent = (unsigned) (percent / total);
	printf("\r%s: %"OFF_FMT"u/%"OFF_FMT"u (%u%%) ",
		(mode < 0) ? "Erasing block" : ((mode == 0) ? "Writing kb" : "Verifying kb"),
		count, total, (unsigned)percent);
	fflush_all();
}

static void progress_newline(void)
{
	if (!option_mask32) //if (!(option_mask32 & OPT_v))
		return;
	bb_putchar('\n');
}

int flashcp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int flashcp_main(int argc UNUSED_PARAM, char **argv)
{
	int fd_f, fd_d; /* input file and mtd device file descriptors */
	int i;
	uoff_t erase_count;
	struct mtd_info_user mtd;
	struct erase_info_user e;
	struct stat statb;
//	const char *filename, *devicename;
	RESERVE_CONFIG_UBUFFER(buf, BUFSIZE);
	RESERVE_CONFIG_UBUFFER(buf2, BUFSIZE);

	/*opts =*/ getopt32(argv, "^" "v" "\0" "=2"/*exactly 2 non-option args: file,dev*/);
	argv += optind;
//	filename = *argv++;
//	devicename = *argv;
#define filename argv[0]
#define devicename argv[1]

	/* open input file and mtd device and do sanity checks */
	fd_f = xopen(filename, O_RDONLY);
	fstat(fd_f, &statb);
	fd_d = xopen(devicename, O_SYNC | O_RDWR);
#if !MTD_DEBUG
	if (ioctl(fd_d, MEMGETINFO, &mtd) < 0) {
		bb_error_msg_and_die("%s is not a MTD flash device", devicename);
	}
	if (statb.st_size > mtd.size) {
		bb_error_msg_and_die("%s bigger than %s", filename, devicename);
	}
#else
	mtd.erasesize = 64 * 1024;
#endif

	/* always erase a complete block */
	erase_count = (uoff_t)(statb.st_size + mtd.erasesize - 1) / mtd.erasesize;
	/* erase 1 block at a time to be able to give verbose output */
	e.length = mtd.erasesize;
#if 0
/* (1) bloat
 * (2) will it work for multi-gigabyte devices?
 * (3) worse wrt error detection granularity
 */
	/* optimization: if not verbose, erase in one go */
	if (!opts) { // if (!(opts & OPT_v))
		e.length = mtd.erasesize * erase_count;
		erase_count = 1;
	}
#endif
	e.start = 0;
	for (i = 1; i <= erase_count; i++) {
		progress(-1, i, erase_count);
#if !MTD_DEBUG
		if (ioctl(fd_d, MEMERASE, &e) < 0) {
			bb_perror_msg_and_die("erase error at 0x%llx on %s",
				(long long)e.start, devicename);
		}
#else
		usleep(100*1000);
#endif
		e.start += mtd.erasesize;
	}
	progress_newline();

	/* doing this outer loop gives significantly smaller code
	 * than doing two separate loops for writing and verifying */
	for (i = 0; i <= 1; i++) {
		uoff_t done;
		unsigned count;

		xlseek(fd_f, 0, SEEK_SET);
		xlseek(fd_d, 0, SEEK_SET);
		done = 0;
		count = BUFSIZE;
		while (1) {
			uoff_t rem;

			progress(i, done / 1024, (uoff_t)statb.st_size / 1024);
			rem = statb.st_size - done;
			if (rem == 0)
				break;
			if (rem < BUFSIZE)
				count = rem;
			xread(fd_f, buf, count);
			if (i == 0) {
				int ret;
				if (count < BUFSIZE)
					memset((char*)buf + count, 0, BUFSIZE - count);
				errno = 0;
				ret = full_write(fd_d, buf, BUFSIZE);
				if (ret != BUFSIZE) {
					bb_perror_msg_and_die("write error at 0x%"OFF_FMT"x on %s, "
						"write returned %d",
						done, devicename, ret);
				}
			} else { /* i == 1 */
				xread(fd_d, buf2, count);
				if (memcmp(buf, buf2, count) != 0) {
					bb_error_msg_and_die("verification mismatch at 0x%"OFF_FMT"x", done);
				}
			}

			done += count;
		}

		progress_newline();
	}
	/* we won't come here if there was an error */

	return EXIT_SUCCESS;
}

离线

#7 2020-08-20 16:18:12

哦豁哦豁
会员
注册时间: 2020-01-17
已发帖子: 79
积分: 79

Re: 如何更新SPI flash里的内核或文件系统

SD NAND不就是 /dev/mmcblk* 么?直接 dd 命令操作不就可以吗?又不用擦除。

离线

#8 2020-08-20 21:10:49

angelsan
会员
注册时间: 2020-04-02
已发帖子: 139
积分: 131.5

Re: 如何更新SPI flash里的内核或文件系统

要写到代码里面呢?

哦豁哦豁 说:

SD NAND不就是 /dev/mmcblk* 么?直接 dd 命令操作不就可以吗?又不用擦除。

离线

#9 2020-08-20 22:04:17

哇酷小二
管理员
所在地: 你猜
注册时间: 2020-04-22
已发帖子: 3,387
积分: 1902
个人网站

Re: 如何更新SPI flash里的内核或文件系统

angelsan 说:

要写到代码里面呢?

就是通用的io函数


c代码:
打开 open(/dev/mmcblk*)
写 write(/dev/mmcblk*)
关闭 close(/dev/mmcblk*)

如果你需要校验,再读回就行: read(/dev/mmcblk*)





离线

#10 2020-08-21 10:18:32

angelsan
会员
注册时间: 2020-04-02
已发帖子: 139
积分: 131.5

Re: 如何更新SPI flash里的内核或文件系统

好的,谢谢!

哇酷小二 说:

就是通用的io函数


c代码:
打开 open(/dev/mmcblk*)
写 write(/dev/mmcblk*)
关闭 close(/dev/mmcblk*)

如果你需要校验,再读回就行: read(/dev/mmcblk*)

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn