导航

    全志在线开发者论坛

    • 注册
    • 登录
    • 搜索
    • 版块
    • 话题
    • 在线文档
    • 社区主页
    1. 主页
    2. haiqianghuang69
    3. 帖子
    H
    • 资料
    • 关注 0
    • 粉丝 0
    • 我的积分 265
    • 主题 2
    • 帖子 6
    • 最佳 1
    • 群组 0

    haiqianghuang69 发布的帖子

    • 回复: D1在uboot下的spi nor flash读写操作

      @yuzukitsuru
      1.大佬是用什么sdk的呀?我用的是韦东山提供的buildroot工程neza-d1-buildroot,
      2.然后感觉那个uboot有点问题,不会遍历dts中第二层级的device,我在源码上参照那个clocks的来遍历第二层,第三层的device,在uboot 输入dm tree可以正常显示device对应的层级关系。只是第三层级的spinor没有绑定成功

      ///drivers/core/root.c
        350     /* bind fixed-clock */
        351     node = ofnode_path("/clocks");
        352     /* if no DT "clocks" node, no need to go further */
      ~ 353     if (!ofnode_valid(node)){
      + 354         pr_debug("debug, not found ofnode_valid node\n");
        355         return ret;
      + 356     }
      + 364
      + 365         //直接进入到这里执行
      + 366         pr_debug("debug, dm_scan_fdt_node\n\n");
        367         ret = dm_scan_fdt_node(gd->dm_root, gd->fdt_blob, node.of_offset,
        368                        pre_reloc_only);
        369     if (ret)
      ~ 370         pr_debug("dm_scan_fdt_node() failed: %d\n", ret);
      + 371
      + 372
      + 373     pr_debug("\n\n");
      + 374     node = ofnode_path("/hello_dts_name@1234");
      + 375     if (!ofnode_valid(node)){
      + 376         pr_debug("find node faile\n");
      + 377         return ret;
      + 378     }
      + 379
      + 380     ret = uclass_get_device_by_name(UCLASS_HELLO_CJ, "hello_dts_name@1234", &getdev);
      + 381     if (ret){
      + 382         pr_debug("debug, can not get device hello\n");
      + 383         ret = uclass_get_device_by_driver(UCLASS_HELLO_CJ, DM_GET_DRIVER(hello_drv), &getdev);
      + 384         if (ret){
      + 385             pr_debug("debug, stil can not find device\n");
      + 386         }
      + 387     }
      + 388     ret = dm_scan_fdt_node(getdev, gd->fdt_blob, node.of_offset,pre_reloc_only);
      + 389     if (ret){
      + 390         pr_debug("dm_scan_fdt node faile\n");
      + 391     }
      
      

      修改后的串口dm tree打印

      => dm tree
       Class      Probed  Driver      Name
      ----------------------------------------
       root       [ + ]   root_drive  root_driver
       hello_cj_c [ + ]   hello_drv   |-- hello_dts_name@1234
       hello_cj_c [   ]   hello_drv_  |   `-- hello_dts_child@5678
       spi_flash  [   ]   spi_flash_  `-- spi@04026000
      => 
      

      uboot的spi1 dts配置

      //uboot-origin_master/arch/riscv/dts/sun20iw1p1-soc-system.dts
        6 /dts-v1/;
         11 / {
         12     model = "sun20iw1";
         13     compatible = "allwinner,riscv", "arm,sun20iw1p1";
         14     #address-cells = <2>;
         15     #size-cells = <2>;
      +  18     hellohqh: hello_dts_name@1234 {
      +  19
      +  20         #address-cells = <1>;
      +  21         #size-cells = <0>;
      +  22         compatible = "hello_dts";
      +  23         reg = <0x02000000>;
      +  24         pinctrl-names = "default", "sleep";
      +  25         pinctrl-0 = <&gpiotest_pins>;
      +  26
      +  27         hellohqh1: hello_dts_child@5678 {
      +  28             compatible = "hello_child_dts";
      +  29             reg = <0x31>;
      +  30             hellohqh2: hello_dts_child_child@99991 {
      +  31                 compatible = "hello_child_child_dts";
      +  32
      +  33                 };
      +  34           };
      +  35     };
      
         37     soc: soc@29000000 {
         38         #address-cells = <2>;
         39         #size-cells = <2>;
      
      + 427         spi1: spi@04026000 {
      + 428             //#address-cells = <1>;
      + 429             //#size-cells = <0>;
      + 430             compatible = "allwinner,sun20i-spi";
      + 431             device_type = "spi1";
      + 432             reg = <0x0 0x04026000 0x0 0x1000>;
      + 433             //interrupts-extended = <&plic0 31 IRQ_TYPE_LEVEL_HIGH>;
      + 434             //clocks = <&ccu CLK_PLL_PERIPH0>, <&ccu CLK_SPI0>, <&ccu CLK_BUS_SPI0>;
      + 435             //clock-names = "pll", "mod", "bus";
      + 436             //resets = <&ccu RST_BUS_SPI0>;
      + 437             clock-frequency = <100000000>;
      + 438             pinctrl-names = "default", "sleep";
      + 439             spi1_cs_number = <1>;
      + 440             spi1_cs_bitmap = <1>;
      + 441             spi_slave_mode = <0>;
      + 442             //dmas = <&dma 22>, <&dma 22>;
      + 443             //dma-names = "tx", "rx";
      + 444             pinctrl-0 = <&spi1_pins_a &spi1_pins_b>;
      + 445             pinctrl-1 = <&spi1_pins_c>;
      + 446             status = "okay";
      + 447             spi-nor {
      + 448                 compatible = "jedec,spi-nor";
      + 449                 spi-max-frequency=<0x5F5E100>;
      + 450                 reg = <0x0>;
      + 451                 spi-rx-bus-width=<0x01>;
      + 452                 spi-tx-bus-width=<0x01>;
      + 453                 status="okay";
      + 454             };
      + 455         };
      + 273             spi1_pins_a: spi1@0 {
      + 274                 allwinner,pins = "PD11", "PD12", "PD13","PD14", "PD15";
      + 275                 allwinner,pname = "spi1_sclk", "spi1_mosi","spi1_miso", "spi1_hold", "spi1_wp";
      + 276                 allwinner,function = "spi1";
      + 277                 allwinner,muxsel = <4>;
      + 278                 allwinner,drive = <1>;
      + 279                 allwinner,pull = <0>;
      + 280             };
      + 281
      + 282             spi1_pins_b: spi1@1 {
      + 283                 allwinner,pins = "PD10";
      + 284                 allwinner,pname = "spi1_cs0";
      + 285                 allwinner,function = "spi1";
      + 286                 allwinner,muxsel = <4>;
      + 287                 allwinner,drive = <1>;
      + 288                 allwinner,pull = <1>;   // only CS should be pulled up
      + 289             };
      + 290
      + 291             spi1_pins_c: spi1@2 {
      + 292                 allwinner,pins = "PD10", "PD11", "PD12", "PD13","PD14", "PD15";
      + 293                 allwinner,function = "gpio_in";
      + 294                 allwinner,muxsel = <0>;
      + 295                 allwinner,drive = <1>;
      + 296                 allwinner,pull = <0>;
      + 297             };
        307         };
      
      

      3.我看了一下drivers/sunxi_flash/sunxi_flash.c,貌似不是基于DM模型的驱动,这个是怎么调用的呀?大佬是否可以指导指导,还在学习阶段好多东西都不懂

      发布在 MR Series
      H
      haiqianghuang69
    • D1在uboot下的spi nor flash读写操作

      回复: 在uboot下调用spi的sf_dataflash驱动报错

      求各位大佬有没有人尝试过在uboot下操作spi nor flash的读写。我用的是drivers/mtd/spi/sf_dataflash.c

      发布在 MR Series
      H
      haiqianghuang69
    • 回复: 在uboot下调用spi的sf_dataflash驱动报错

      @whycan 刚开始贴的log打印,应该是程序的一些空指针的操作导致系统挂了

      发布在 MR Series
      H
      haiqianghuang69
    • 回复: 在uboot下调用spi的sf_dataflash驱动报错

      @whycan
      1.追查下来发现在绑定udevice的时候,probe没有获取到一个size,导致没有给一个parent_priv分配内存空间,尝试在U_BOOT_DRIVER上面添加一个per_child_auto_alloc_size,但没有生效,就直接在源码上赋值了(从其他地方打印这个size值为48)

       181 U_BOOT_DRIVER(spi_flash_std) = {
        182     .name       = "spi_flash_std",
        183     .id     = UCLASS_SPI_FLASH,
        184     .of_match   = spi_flash_std_ids,
        185     .probe      = spi_flash_std_probe,
        186     .remove     = spi_flash_std_remove,
        187     .priv_auto_alloc_size = sizeof(struct spi_flash),
      + 188     .per_child_auto_alloc_size = sizeof(struct spi_slave),//在这里赋值没有生效
        189     .ops        = &spi_flash_std_ops,
        190 };
      
      //drivers/core/device.c
       343     if (dev->parent) {
      + 344         printf("device_probe, get parent size\n");
        345         size = dev->parent->driver->per_child_auto_alloc_size;
        346         if (!size) {
      ~ 348             size = dev->parent->uclass->uc_drv->per_child_auto_alloc_size;
        349         }
      + 350         if (!size){
      + 352             //size = sizeof(struct spi_slave);//有报错
      + 353             size = 48;//通过其他地方打印的spi_slave大小
      + 354         }
      + 355
        357         if (size && !dev->parent_priv) {//分配parent_priv空间
        358             dev->parent_priv = alloc_priv(size, drv->flags);
        360             if (!dev->parent_priv) {
        362                 ret = -ENOMEM;
        363                 goto fail;
        364             }
        365         }
        366
      
      

      2.搞完第一步后,发现上电后就卡住了,经加log发现是在spi_claim_bus这里运行不下去

      //drivers/mtd/spi/sf_probe.c
       25 static int spi_flash_probe_slave(struct spi_flash *flash)
         26 {
         27     struct spi_slave *spi = flash->spi;//通过打印,flash传进来的是udevice ,spi@04026000
         28     int ret;
         29
         30     /* Setup spi_slave */
         31     if (!spi) {
         33         return -ENODEV;
         34     }
         35
         37     /* Claim spi bus */
      ~  38     ret = spi_claim_bus(spi);//这里是调用到drivers/spi/spi-uclass.c的实现
         39     if (ret) {
         40         debug("SF: Failed to claim SPI bus: %d\n", ret);
         41         return ret;
         42     }
      
      //drivers/spi/spi-uclass.c
      int spi_claim_bus(struct spi_slave *slave)
      {
          return log_ret(dm_spi_claim_bus(slave->dev));
      }
      50 int dm_spi_claim_bus(struct udevice *dev)
         51 {
      +  52     pr_err("spi/spi-uclass, spi_claim_bus->dm_spi_claim_bus\n\n");
      +  53
         54     struct udevice *bus = dev->parent;
      ~  55     if (bus == NULL){
      +  56         pr_err("debug, is null pointer\n");
      +  57     }else{
      +  58         pr_err("debug, spi_get_ops, bus = dev->parent, , \n");//貌似不能直接获取结构体内容
      +  61         struct dm_spi_ops *ops = spi_get_ops(bus);//这里的bus应该是一个父设备,这里获取父设备的ops,最终是卡在这里,spi_get_ops是获取bus->driver->ops
      +  62     }
      +  63
      
      

      分析代码是spi_claim_bus函数里面想拿执行spi_get_opt(bus),但程序跑到这里就卡住没往下执行了,应该是一个空的内容

      串口打印如下:

      [02.207]debug, spi_claim_bus, 
      [02.210]spi/spi-uclass, spi_claim_bus->dm_spi_claim_bus
      
      [02.215]debug, spi_get_ops, bus = dev->parent, , 
      
      
      发布在 MR Series
      H
      haiqianghuang69
    • 回复: 在uboot下调用spi的sf_dataflash驱动报错

      尝试在D1的uboot上实现一个nor flash的读写的功能,想直接用drivers/mtd/spi/sf_dataflash.c的驱动程序,但调用失败。求问各位大佬怎么在uboot下实现一个nor flash的读写

      发布在 MR Series
      H
      haiqianghuang69
    • 在uboot下调用spi的sf_dataflash驱动报错

      基于 韦东山的neza-d1-buildroot源码
      1.make menuconfig,选择spi以及允许DM
      2.配置dts

      +         spi1: spi@04026000 {
      +             //#address-cells = <1>;
      +             //#size-cells = <0>;
      +             compatible = "allwinner,sun20i-spi";
      +             device_type = "spi1";
      +             reg = <0x0 0x04026000 0x0 0x1000>;
      +             //interrupts-extended = <&plic0 31 IRQ_TYPE_LEVEL_HIGH>;
      +             //clocks = <&ccu CLK_PLL_PERIPH0>, <&ccu CLK_SPI0>, <&ccu CLK_BUS_SPI0>;
      +             //clock-names = "pll", "mod", "bus";
      +             //resets = <&ccu RST_BUS_SPI0>;
      +             clock-frequency = <100000000>;
      +             pinctrl-names = "default", "sleep";
      +             spi1_cs_number = <1>;
      +             spi1_cs_bitmap = <1>;
      +             spi_slave_mode = <0>;
      +             //dmas = <&dma 22>, <&dma 22>;
      +             //dma-names = "tx", "rx";
      +             pinctrl-0 = <&spi1_pins_a &spi1_pins_b>;
      +             pinctrl-1 = <&spi1_pins_c>;
      +             status = "okay";
      +             spi-nor {
      +                 compatible = "jedec,spi-nor";
      +                 spi-max-frequency=<0x5F5E100>;
      +                 reg = <0x0>;
      +                 spi-rx-bus-width=<0x01>;
      +                 spi-tx-bus-width=<0x01>;
      +                 status="okay";
      +             };
      +         };
      +
      +
      
      +             spi1_pins_a: spi1@0 {
      +                 allwinner,pins = "PD11", "PD12", "PD13","PD14", "PD15";
      +                 allwinner,pname = "spi1_sclk", "spi1_mosi","spi1_miso", "spi1_hold", "spi1_wp";
      +                 allwinner,function = "spi1";
      +                 allwinner,muxsel = <4>;
      +                 allwinner,drive = <1>;
      +                 allwinner,pull = <0>;
      +             };
      +
      +             spi1_pins_b: spi1@1 {
      +                 allwinner,pins = "PD10";
      +                 allwinner,pname = "spi1_cs0";
      +                 allwinner,function = "spi1";
      +                 allwinner,muxsel = <4>;
      +                 allwinner,drive = <1>;
      +                 allwinner,pull = <1>;   // only CS should be pulled up
      +             };
      +
      +             spi1_pins_c: spi1@2 {
      +                 allwinner,pins = "PD10", "PD11", "PD12", "PD13","PD14", "PD15";
      +                 allwinner,function = "gpio_in";
      +                 allwinner,muxsel = <0>;
      +                 allwinner,drive = <1>;
      +                 allwinner,pull = <0>;
      +             };
      

      3.自定义一个cmd/hello程序,通过uclass_get_device_by_name获取device。执行write方法,串口输出有报错,

      Unhandled exception: Load access fault
      EPC: 000000005ff2d380 TVAL: 00000002e3035e0a
      ### ERROR ### Please RESET the board ###
      
      发布在 MR Series
      H
      haiqianghuang69
    • 1 / 1