linux内核空间操作flash mtd问题

u2m 2008-11-26 02:42:55
各位大侠,

遇到一问题,我想实现在linux kernel crash的时候加入写flash操作,然后重启。我在crash handler function die()中实现重启没问题,但是读写flash操作就没有头绪了。
哪位大侠给些提示,如何在此时访问mtd呢?

多谢
...全文
480 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
gmting 2009-12-26
  • 打赏
  • 举报
回复
werwer
bxhzct 2008-12-01
  • 打赏
  • 举报
回复
学习!
u2m 2008-12-01
  • 打赏
  • 举报
回复
问题解决,揭帖
u2m 2008-12-01
  • 打赏
  • 举报
回复
read mtd 操作is ok, 写还是有问题,看上去是erase操作出了点问题,我直接调用mtd->erase可以吗?
u2m 2008-12-01
  • 打赏
  • 举报
回复
试了一下,
mtd = get_mtd_device(NULL, 0); // open
if (mtd == NULL)
{
printk(KERN_DEBUG "MTD device 0 doesn't appear to exist\n");
return -ENODEV;
}

res = mtd->read(mtd, 0xa0300000, DATA_SIZE, &retlen, (unsigned char *)&laty);
if (retlen != 4) {
printk("Didn't read a int in mtd_read(). Returned %d\n", res);
return 0;
}
每次都失败,打印Didn't read a int in mtd_read(). Returned 0
楼上大侠帮看下
u2m 2008-11-28
  • 打赏
  • 举报
回复
多谢楼上的几位朋友,我试试看
zjujoe 2008-11-27
  • 打赏
  • 举报
回复

struct mtd_info *mtd = NULL;
int retlen;

mtd = get_mtd_device(NULL, 0);
if (mtd == NULL)
return -ENODEV;
addr = kmalloc(DATA_SIZE, GFP_KERNEL);
if (!addr)
return -ENOMEM;

/* DATA begins from 0x800 */
if (mtd->writesize == 2048)
mtd->read(mtd, 0x800, DATA_SIZE, &retlen, addr);
fibbery 2008-11-26
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 u2m 的回复:]
不是,是一个嵌入式的linux系统,flash存放boot以及linux image,希望系统crash的时候会自动重启并写入标记到flash.
[/Quote]

哦,有点明白了!没做过嵌入式的Linux开发,不过我还是很感兴趣的。
Dualing 2008-11-26
  • 打赏
  • 举报
回复
内核空间读写FLASH那就直接调用:
static ssize_t mtd_read(struct file *file, char *buf, size_t count,loff_t *ppos)
static ssize_t mtd_write(struct file *file, const char *buf, size_t count,loff_t *ppos)
u2m 2008-11-26
  • 打赏
  • 举报
回复
我想了一下.linux有mtd的字符驱动,我可以在用户空间调用此驱动读写flash,但现在的问题是我想在内核空间完成flash的读写操作,该怎样作?
u2m 2008-11-26
  • 打赏
  • 举报
回复
不是,是一个嵌入式的linux系统,flash存放boot以及linux image,希望系统crash的时候会自动重启并写入标记到flash.
fibbery 2008-11-26
  • 打赏
  • 举报
回复
你是指读写bios吗?
系统启动会从引导去载入启动程序,启动程序在加载操作系统程序,你是想在重启之后读取bios?

4,465

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧