- 编译内核
sudo ./build.sh -p sunivw1p1 -m kernel -k linux-3.10
sudo ./build.sh pack
全部编译 sudo ./build.sh
2.打开 spi读写sd卡
因为spi引脚和串口冲突 所以需要调整串口
/home/work/F25-4MSPI-SDK/tools/pack/chips/sunivw1p1/configs/evb/sys_config.fex
2.1
85 [uart_para]
86 uart_debug_port = 1
87 ;uart_debug_tx = port:PA3<5><1> ; pa3 pa2 为默认打印引脚
88 ;uart_debug_rx = port:PA2<5><1>
89 uart_debug_tx = port:PD4<3><1>
90 uart_debug_rx = port:PD3<3><1>
2.2
170 [uart1]
171 uart1_used = 1
172 uart1_port = 1
173 uart1_type = 2
174 ;uart1_tx = port:PA3<5><1>
175 ;uart1_rx = port:PA2<5><1>
176 uart1_tx = port:PD4<3><1>
177 uart1_rx = port:PD3<3><1>
2.3
189 [spi0]
190 spi0_used = 1 ;置1
191 spi0_cs_number = 1
192 spi0_cs_bitmap = 1
193 spi0_cs0 = port:PC1<2><1>
194 spi0_sclk = port:PC0<2>
195 spi0_mosi = port:PC3<2>
196 spi0_miso = port:PC2<2>
-
内核配置一定要加上 arch=arm ,不然配置会重置配置
make menuconfig arch=arm -
flash check addr
#define CHECK_ADDR 0x3df000 -
F25 增加PWM 支持 ,
5.1 在tools/pack/chips/sunivw1p1/configs/evb/sys_config.fex 文件修改如下
453 ;----------------------------------------------------------------------------------
454 ;pwm config
455 ;----------------------------------------------------------------------------------
456 [pwm0_para]
457 pwm_used = 1
458 ;pwm_positive = port:PH00<2><0> Port:端口+组内序号<功能分配><内部电阻状态><驱动能力><输出电平状态>
459 pwm_positive = port:PE12<4><1>
460 [pwm1_para]
461 pwm_used = 0
462 pwm_positive = port:PH01<2><0>
5.2 在设备树中增加
linux-3.10/arch/arm/boot/dts/sunivw1p1.dtsi
185 pwm0: pwm0@01c21000 {
186 compatible = “allwinner,sunxi-pwm0”;
187 reg = <0x0 0x01c21000 0x0 0x400>;
188 pwm-number = <1>;
189 pinctrl-names = “active”, “sleep”;
190 pinctrl-0 = <&pwm0_pins_a>;
191 pinctrl-1 = <&pwm0_pins_b>;
192 status = “okay”;
193 };
194
linux-3.10/arch/arm/boot/dts/sunivw1p1-pinctrl.dtsi
45 pwm0_pins_a: pwm0@0 {
46 allwinner,pins = “PE12”;
47 allwinner,pname = “pwm0”;
48 allwinner,function = “pwm0”;
49 allwinner,muxsel = <4>;
50 allwinner,drive = <1>;
51 allwinner,pull = <1>;
52 };
53
54 pwm0_pins_b: pwm0@1 {
55 allwinner,pins = “PE12”;
56 allwinner,function = “io_disabled”;
57 allwinner,muxsel = <7>;
58 allwinner,drive = <1>;
59 allwinner,pull = <1>;
60 };
5.3 在meunconfig 中 增加pwm 核心驱动
[] Pulse-Width Modulation (PWM) Support —>
— Pulse-Width Modulation (PWM) Support │ │
│ │ <> Sunxi PWM support
5.4 编写lewei_pwm.c, pwm设备驱动
增加 linux-3.10/drivers/misc/lewei_pwm.c
利用到的5个函数
- pwm0_bl = pwm_request(0 , “pwm0”);
- pwm_enable(pwm0_bl);
- pwm_config(pwm0_bl, PwmConfig.active_ns , PwmConfig.period_ns);
- pwm_disable(pwm0_bl);
- pwm_free(pwm0_bl);
5.5 应用层打开 lewei_pwm.c 的杂项设备节点,按驱动操作即可。
- 怎加 flash 型号及保留flash部分区域
diff --git a/linux-3.10/drivers/mtd/devices/m25p80.c b/linux-3.10/drivers/mtd/devices/m25p80.c
index 8df1138..703c61c 100755
--- a/linux-3.10/drivers/mtd/devices/m25p80.c
+++ b/linux-3.10/drivers/mtd/devices/m25p80.c
@@ -35,6 +35,9 @@
#include <linux/spi/spi.h>
#include <linux/spi/flash.h>
+//#define pr_debug(buff...) printk(KERN_ALERT buff )
+//#define pr_err(buff...) printk(KERN_ERR buff)
+static struct mtd_info *check_mtd = NULL;
#define M25_DBG(fmt, arg...) pr_debug("%s()%d - "fmt, __func__, __LINE__, ##arg)
#define M25_ERR(fmt, arg...) pr_err("%s()%d - "fmt, __func__, __LINE__, ##arg)
@@ -51,7 +54,7 @@
#define OPCODE_CHIP_ERASE 0xc7 /* Erase whole flash chip */
#define OPCODE_SE 0xd8 /* Sector erase (usually 64KiB) */
#define OPCODE_RDID 0x9f /* Read JEDEC ID */
-
+#define OPCODE_UNIQUEID 0x4b /* Read unique id*/
/* Used for SST flashes only. */
#define OPCODE_BP 0x02 /* Byte program */
#define OPCODE_WRDI 0x04 /* Write disable */
@@ -823,7 +826,8 @@ static const struct spi_device_id m25p_ids[] = {
{ "w25q80bl", INFO(0xef4014, 0, 64 * 1024, 16, SECT_4K) },
{ "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, SECT_4K) },
{ "w25q256", INFO(0xef4019, 0, 64 * 1024, 512, SECT_4K) },
-
+ /*zbit */
+ {"ZB25VQ32",INFO(0x5e4016, 0, 64 * 1024, 64, SECT_4K)}, // 新型号的flash型号增加
/* Catalyst / On Semiconductor -- non-JEDEC */
{ "cat25c11", CAT25_INFO( 16, 8, 16, 1) },
{ "cat25c03", CAT25_INFO( 32, 8, 16, 2) },
@@ -862,6 +866,7 @@ static int partitions_register(struct mtd_info *mtd, struct mtd_part_parser_data
M25_ERR("Failed to kzalloc(%d)\n", MBR_SIZE);
return -ENOMEM;
}
+ check_mtd = mtd; // modify for fan 2018 1 29
ret = m25p80_read(mtd, MBR_OFFSET, MBR_SIZE, &retlen, (u_char *)sunxi_mbr);
M25_DBG("m25p80_read() ret= %d, retlen = %d\n", ret, retlen);
if ((ret != 0) || (sunxi_mbr->PartCount == 0)) {
@@ -884,7 +889,7 @@ static int partitions_register(struct mtd_info *mtd, struct mtd_part_parser_data
}
M25_DBG("valid partitions count: %d\n",sunxi_mbr->PartCount);
-
+ sunxi_mbr->array[2].lenlo = sunxi_mbr->array[2].lenlo-8; //reserve 4096 // 2 号位置是rootfs 分区大小 ,保留 8 个块 ,8*512
for (i=0; i<sunxi_mbr->PartCount-1; i++) {
partitions[0].name = "uboot";
@@ -916,6 +921,53 @@ static int partitions_register(struct mtd_info *mtd, struct mtd_part_parser_data
}
#endif
+u64 unique_id;
+unsigned long long get_flash_uniqueid(void) // 外界获取 uid
+{
+ return unique_id;
+}
+EXPORT_SYMBOL_GPL(get_flash_uniqueid);
+#define CHECK_ADDR 0x3df000
+int read_flash_check_num(unsigned char *buff,int size,int offset)//在保留分区中读出数据
+{
+// ret = m25p80_read(mtd, MBR_OFFSET, MBR_SIZE, &retlen, (u_char *)sunxi_mbr);
+
+ int ret, relen ;
+ if(!check_mtd)
+ return -1;
+ ret= m25p80_read(check_mtd, /* (0x400000 - ( 8*512 )) + offset MBR_OFFSET*/ CHECK_ADDR+offset , si
+ if(!ret)
+ {
+ return relen;
+ }
+ return -1;
+}
+EXPORT_SYMBOL_GPL(read_flash_check_num);
+int write_flash_check_num(unsigned char *buff,int size,int offset) //在保留分区中写入数据
+{
+// 462 static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
+// 463 size_t *retlen, const u_char *buf)
+ int ret, relen ;
+ if(!check_mtd)
+ return -1;
+ //721 erase->addr = einfo32.start;
+// 722 erase->len = einfo32.length;
+struct erase_info erase={0};
+ erase.addr = CHECK_ADDR;
+ erase.len =4096;
+ erase.mtd = check_mtd;
+ erase.callback =NULL;
+ erase.priv=NULL;
+ m25p80_erase(check_mtd, &erase);
+ ret= m25p80_write(check_mtd,/* (0x400000 - ( 8*512 )) + offset MBR_OFFSET */ CHECK_ADDR+offset, si
+ if(!ret)
+ {
+ return relen;
+ }
+ return -1;
+}
+EXPORT_SYMBOL_GPL(write_flash_check_num);
+
static const struct spi_device_id * jedec_probe(struct spi_device *spi)
{
int tmp;
@@ -923,7 +975,38 @@ static const struct spi_device_id * jedec_probe(struct spi_device *spi)
u8 id[5];
u32 jedec;
u16 ext_jedec;
+ u8 uid[12];
struct flash_info *info;
+ code = OPCODE_UNIQUEID;
+ /*read unique id*/
+ tmp = spi_write_then_read(spi, &code, 1,uid, 12); // 读取flash uid 前是四字节是无效的
+ if( tmp<0)
+ {
+ printk(KERN_ERR "read unique id error \n");
+ }
+ else
+ {
+ unique_id = uid[4];
+ unique_id = unique_id << 8;
+ unique_id |=uid[5];
+ unique_id <<= 8;
+ unique_id |=uid[6];
+ unique_id <<=8;
+ unique_id |=uid[7];
+ unique_id <<=8;
+ unique_id |=uid[8];
+ unique_id <<=8;
+ unique_id |=uid[9];
+ unique_id <<=8;
+ unique_id |=uid[10];
+ unique_id <<=8;
+ unique_id |=uid[11];
+ printk(KERN_ERR "unique id = 0x%llx\n",unique_id);
+
+ }
+
+
+code = OPCODE_RDID;
- 增加串口登陆认证
在etc/inittab 中增加
::respawn:/sbin/getty -L ttyS1 115200 vt100
终端设置中流控要选择XON/XOFF,不然没有办法输入用户名密码。(不一定有效)
openssl passwd -1 ‘123456’ 生成的字符串 放入 shadow 文件中
-
./target/generic/Makefile.in 会修改一些系统的启动配置文件
-
在lewei_key.c 中 增加中断检测按键 , 并加入了等待队列等机制 ,影响了usb 的正常采集,造成到通过wifi传输至手机的图像半边花屏和闪动。后去掉中断和不使用poll进行柱塞,bug依旧在,只有去掉声明的等待队列头,和部分函数才恢复正常。
10.后面的key采用查询方式。
11.电压检测采用的是keyboard的adc,精度只有6位,输入电压范围在0~2v 之间,电池电压采用 1:1.2 的电阻分压。