| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- /******************************************************************************
- 版权所有:
- 文件名称: read_id.c
- 文件版本: 01.01
- 创建作者: sunxi
- 创建日期: 2014-10-30
- 功能说明: 读取flash id
- 其它说明:
- 修改记录:
- */
- #include "head.h"
- #ifdef LINUX_KERNEL_APP
- #include <linux/kernel.h>
- #include <linux/init.h>
- #include <linux/module.h>
- #include <linux/moduleparam.h>
- #include <linux/fs.h>
- #include <linux/sched.h>
- #include <linux/interrupt.h>
- #include <linux/kthread.h>
- #include <linux/delay.h>
- #include <linux/wait.h>
- #include <asm/uaccess.h>
- #include <asm/io.h>
- #include <asm/ioctls.h>
- #include <termios.h>
- #include <linux/syscalls.h>
- #else
- #include <linux/fs.h>
- #include <linux/sched.h>
- #include <linux/wait.h>
- #include <asm/ioctls.h>
- #include <termios.h>
- #include "rt.h"
- #endif
-
- #define PROC_FLASHID "/proc/flashid"
- /******************************************************************************
- 函数名称: read_unique_id
- 函数版本: 01.01
- 创建作者: sunxi
- 创建日期: 2014-10-30
- 函数说明: 读取ID。
- 参数说明: id: 8字节的ID.
- 返回值: 成功返回0,失败返回负数。。
- 修改记录:
- */
- int read_unique_id(unsigned char *id)
- {
- unsigned char buf[17];
- unsigned char tmpbuf[9];
- int fd = 0;
- int ret = 0;
- uint32_t tmp = 0;
-
- memset(buf, 0, sizeof(buf));
- memset(tmpbuf, 0, sizeof(tmpbuf));
-
- fd = sys_open(PROC_FLASHID, O_RDONLY, 0);
- if(fd < 0)
- {
- printk("open %s error!\n", PROC_FLASHID);
- return -1;
- }
- ret = sys_read(fd, buf, sizeof(buf) - 1);
-
- if(ret < 0)
- {
- printk("read_unique_id error!\n");
- ret = -1;
- goto end;
- }
-
- memcpy(tmpbuf, buf, 8);
- tmp = simple_strtoul(tmpbuf, NULL, 16);
- id[0] = (tmp >> 24) & 0xFF;
- id[1] = (tmp >> 16) & 0xFF;
- id[2] = (tmp >> 8) & 0xFF;
- id[3] = (tmp >> 0) & 0xFF;
-
- memcpy(tmpbuf, buf+8, 8);
- tmp = simple_strtoul(tmpbuf, NULL, 16);
- id[4] = (tmp >> 24) & 0xFF;
- id[5] = (tmp >> 16) & 0xFF;
- id[6] = (tmp >> 8) & 0xFF;
- id[7] = (tmp >> 0) & 0xFF;
- ret = 0;
- end:
- sys_close(fd);
-
- return ret;
- }
-
-
|