This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] Linux/66AK2H12:从 Linux 直接访问 DDR3

Guru**** 1997545 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/700680/linux-66ak2h12-access-directly-to-ddr3-from-linux

器件型号:66AK2H12

工具/软件:Linux

大家好。 我不熟悉 Linux env。

我使用了 K2H EVM 和处理器 SDK。 我希望通过 gcc 在 Linux 中编译 CPP 文件、并直接读取和写入 DDR3存储器空间。

我的简单代码是:

#include
int main()

printf ("您好! 世界!\n");

*(int *) 0xc1000000 = 1024;
*(int *) 0xc2000000 = 2;
*(int *) 0xc3000000 =(*(int *) 0xc1000000)+(*(int *) 0xc2000000);

printf ("结果为:%d.\n"、*(int *) 0xc3000000);

返回0;

当我在 Linux 中编译并运行它时,我看到:

root@k2hk EVM:~#/usr/bin/gcc hello.cpp -o output.out
root@k2hk EVM:~#./output.out
您好! 世界!
分段故障(转储内核)

如何从 Linux ARM 内核直接访问 DDR3存储器?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您好!

    我将对此进行研究。

    此致、
    Yordan
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    你(们)好。 谢谢你。

    我忘记提到:

    我将此代码与 mmap()函数一起使用:

    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    
    #define filepath "/tmp/mmapped.bin //空文件!
    #define NUMINTS (1000)
    #define filesize (NUMINTS * sizeof (int))
    
    int main (int argc、char * argv[])
    {
    int i;
    int fd;
    int *映射;/* int 的映射数组*/
    
    fd =开路(filepath、O_RDONLY);
    if (fd =-1){
    perror ("打开文件进行读取时出错");
    exit (exit_failure);
    }
    
    MAP =(int *) mmap (0、filesize、PROT_read、MAP_shared、FD、 0xC0000000); 
    if (map == map_failed){
    Close (fd);
    perror ("Error mmapping the file");
    exit (exit_failure);
    }
    
    /*从 mmap 中读取文件 int-by-int
    *
    对于(i = 1;i <=NUMINTS;++I){
    printf ("%d:%d\n"、i、map[i]);
    }
    
    if (munmap (map、filesize)=-1){
    perror ("Error un-mmapping the file");
    }
    关闭(FD);
    返回0;
    } 

    编译并运行后、我看到:

    总线错误(转储内核)

    谢谢。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    首先使用 cat /proc/iomem.检查可用的内存 DDR 空间

    然后、在您的程序中、您需要虚拟化地址。 Linux 内核和用户空间可与虚拟地址配合使用、0xc1000000、0xc2000000和0xc3000000是物理地址。
    请尝试以下代码(它在我的一方有效):
    #include
    #include
    #include
    #include
    #include
    #include
    #include

    #define MAP_SIZE 4096UL
    #define MAP_MASK (MAP_SIZE - 1)
    void main (void)

    int fd;
    void * virt_addr_p、* virt_addr_q、* virt_addr_sum;

    FD =开路("/dev/mem、O_RDWR | O_SYNC);

    void *p = mmap (0、map_size、PROT_read | PROT_write、map_shared、fd、 0xC1000000 &~MAP_MASK);
    void *q = mmap (0、map_size、PROT_read | PROT_write、map_shared、fd、 0xC2000000 &~MAP_MASK);
    void *sum = mmap (0、map_size、PROT_read | PROT_write、map_shared、fd、 0xC3000000 &~MAP_MASK);

    virt_addr_p = p +(0xC1000000 & MAP_MASK);
    virt_addr_q = q +(0xC2000000 & MAP_MASK);
    virt_addr_sum =和+(0xC3000000 & MAP_MASK);

    printf ("\nHello!\n");
    *(int *) virt_addr_p = 1024;
    *(int *) virt_addr_q = 2;
    *(int *) virt_addr_sum =*(int *) virt_addr_p +*(int *) virt_addr_q;

    printf ("\n 结果为:%d\n"、*(int *) virt_addr_sum);



    此致、
    Yordan

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    是的! 非常感谢!