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.

Problem accessing custom memory using /dev/mem and mmap

Other Parts Discussed in Thread: OMAP3525

Hi,

I'm trying to access a memory device (256KB) we added to our OMAP3525-based custom board under Linux.  This memory device is allocated by the Xilinx Spartan 6 and hooked up to CS2 on the GPMC and mapped to physical address 0x10000000; the 7 CONFIG registers for CS2 are properly set up because

I'm able to access (reads and writes) it under u-boot without any problems.  

Under Linux, I wrote a little user-space application using /dev/mem and mmap to access it.  On our previous board which uses the TI Davinci processor (6446), the application works fine using mmap.  On this OMAP3525-based custom board, all I get are 0's on the reads and writes; no error conditions though.  This sample application can access the OMAP3525 registers fine but cannot properly access the CS2 256KB memory region created from the Xilinx FPGA.  Looking at the logic analyzer, I can see the chip select when I access the memory region.   Do I need to "register" the physical address (0x10000000) with the Linux kernel for mmap to work correctly?  If so, how do I go about doing so?  I searched the kernel and see that arch/arm/mach-omap2/io.c contains virtual and physical addresses for various memory space regions of the OMAP3; I assume this is used by kernel drivers only via ioremap.  For what I'm doing, I'm not writing any driver and am just using mmap in a user-space application to access the memory device.  Any advice on what I'm doing wrong; this area is not-cacheable so I added the "O_SYNC" option.  Here's a snippet of my sample application.  Thanks.

        volatile unsigned char *p;
        size_t length = 0x1000;    // 4KB page
        int prot = PROT_READ | PROT_WRITE;
        int flags = MAP_SHARED;
        int fd = open("/dev/mem", O_RDWR | O_SYNC);
        off_t offset;
        unsigned int offset_addr;
        int index;

        sscanf(argv[1], "%x", &offset_addr);
        offset = (off_t)(offset_addr & 0xfffff000);
        index = offset_addr & 0xfff;

        if (fd < 0) {
              perror("open");
              return 1;
        }

        p = (unsigned char *)mmap(NULL, length, prot, flags, fd, offset);
        if (p == MAP_FAILED) {
              perror("mmap");
              return 4;
        }

        // do something (like read or write) to p[index]

 

Regards,

Andy

  • NOTE: I have searched through the forums and tried to access the CS2 memory space without any luck using the other utilities (regrw and mem_util) that people have posted.

  • Never mind, I finally figured it out.  The 256KB memory is created
    from the Xilinx FPGA we have on our custom board.  We hooked up the
    sys_clkout2 output from the OMAP to the FPGA as its clocking source.
    It works fine under u-boot (I configured sys_clkout2 to 27MHz, use the
    54MHz with a divider of 2).  However, when I boot up to Linux, this
    clock source is messed up and the 256KB memory is unaccessable.  I
    tried playing around with clock.c, clock34xx.c and clock34xx.h to make
    sure sys_clkout2 is not disturbed and is not disabled but had no
    luck.  So I just reconfigured the kernel with the
    CONFIG_OMAP_RESET_CLOCKS option turned off and now I can access the
    memory correctly.  Thanks everyone for you help.

    Regards,
    Andy