-
kernel中直接读取具体mtd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
static int (void)
{
struct mtd_info *mtd = NULL;
char buf[8] = {0};
size_t bytes_read = 0;
int err = 0;
mtd = get_mtd_device_nm("res");
if(IS_ERR(mtd))
return -ENODEV;
//读取mtd上,偏移0个字节长度,读取长度,实际读取字节数
err = mtd_read(mtd, 0, sizeof(buf), &bytes_read, buf);
if(err)
goto err;
printk("%s dat[0]:0x%x, dat[1]:0x%x, dat[2]:0x%x, dat[3]:0x%xn",__func__,buf[0],buf[1],buf[2],buf[3]);
//关闭
put_mtd_device(mtd);
return 0;
err:
return -ENXIO;
} -
在uboot中读取,并传递给kernel
-
2.1 cmd/Makefile
1
obj-y += get_lcd_value.o
-
2.2 cmd/get_lcd_value.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
static int do_get_lcd_value(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char buf[4];
int uImage_head_addr;
uImage_head_addr = simple_strtoul(argv[1], NULL, 16);
printf("agrv[1] addr 0x%xn",*(int *)uImage_head_addr);
buf[0] = ((char *)uImage_head_addr)[3] & 0x0f;
buf[1] = ((char *)uImage_head_addr)[2] & 0x0f;
buf[0] |= (buf[1] << 4);
buf[2] = ((char *)uImage_head_addr)[1] & 0x0f;
buf[3] = ((char *)uImage_head_addr)[0] & 0x0f;
buf[1] = (buf[3] << 4) | buf[2];
//将buf值设为环境变量loadlcdvalue
setenv_hex("loadlcdvalue", *(int *)buf);
}
U_BOOT_CMD(
get_lcd_value, CONFIG_SYS_MAXARGS, 0, do_get_lcd_value,
"Get lcd value !n",
"Usage: Get lcd valuen"
); -
2.3 include/configs/mx6dl_xxx_common.h
1
2
3
4
5
6
7
8
9
10
11
12
CONFIG_MFG_ENV_SETTINGS
"loadsz=" KN_PART_SZ "
-
近期评论