全志F25工作簡記

  1. 編譯內核
    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>

  1. 內核配置一定要加上 arch=arm ,不然配置會重置配置
    make menuconfig arch=arm

  2. flash check addr
    #define CHECK_ADDR 0x3df000

  3. 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個函數

  1. pwm0_bl = pwm_request(0 , “pwm0”);
  2. pwm_enable(pwm0_bl);
  3. pwm_config(pwm0_bl, PwmConfig.active_ns , PwmConfig.period_ns);
  4. pwm_disable(pwm0_bl);
  5. pwm_free(pwm0_bl);

5.5 應用層打開 lewei_pwm.c 的雜項設備節點,按驅動操作即可。

  1. 怎加 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;
  1. 增加串口登陸認證
    在etc/inittab 中增加
    ::respawn:/sbin/getty -L ttyS1 115200 vt100

終端設置中流控要選擇XON/XOFF,不然沒有辦法輸入用戶名密碼。(不一定有效)
openssl passwd -1 ‘123456’ 生成的字符串 放入 shadow 文件中

  1. ./target/generic/Makefile.in 會修改一些系統的啓動配置文件

  2. 在lewei_key.c 中 增加中斷檢測按鍵 , 並加入了等待隊列等機制 ,影響了usb 的正常採集,造成到通過wifi傳輸至手機的圖像半邊花屏和閃動。後去掉中斷和不使用poll進行柱塞,bug依舊在,只有去掉聲明的等待隊列頭,和部分函數才恢復正常。

10.後面的key採用查詢方式。

11.電壓檢測採用的是keyboard的adc,精度只有6位,輸入電壓範圍在0~2v 之間,電池電壓採用 1:1.2 的電阻分壓。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章