How do I use both internal SRAM and external SDRAM for malloc on RZA1?

We are using:

  • 3.12.x kernel
  • XIP for kernel base libraries
  • SPI flash for our application
  • external SDRAM for Linux
  • (parts of) internal SRAM for frame buffer

We would like to make the unused portion of the on-chip RAM available to malloc, basically to complement the external SDRAM.  Preferably in a manner that is completely transparent to any user space code that uses new or malloc.

So if I'm using 32MB external SDRAM, and I'm using 2MB out of 10MB for framebuffer, I'd like to end up with 32+(10-2)=40MB of RAM that is available to and managed by the Linux kernel and thus available for malloc etc.

Is this at all possible in Linux for RZ?  If so, is it possible in the 3.12 kernel and what exactly would need to go into the device tree and other files?

Now in absence of making this 100% transparent to Linux user space, I guess the next best thing would be to replace malloc w/ a custom implementation that is aware of the SRAM (and has mapped it into the user space address space via mmap). I think I understand how to override the default malloc so that the application is not even aware that a custom one is used, and I understand conceptually what this custom malloc would have to do, but struggling to find a library to provides a heap allocation implementation that is as good as malloc, in terms of ability to deal with fragmentation.   So any pointes to a good heap allocator library would also be appreciated.

 

  • In reply to mahesh:

    Hello Mahesh,

    When you run the xsa_boot command, it will overwrite the "memory" node in the device tree.

    setenv("xsa_boot", "run dtb_read_sdram; run dtb_mem_sdram; setenv bootargs ${cmdline_common} ${fs_axfs}; fdt chosen; run xImg");

    setenv("dtb_mem_sdram", "fdt memory "MEM_ADDR_SDRAM""); /* Use external SDRAM for system memory */

     

    This was good for the Renesas demo board (easy to change from internal RAM to external SDRAM). But not good for your board (you do not want to always be changing)

     

    Please remove "run dtb_mem_sdram" from your xsa_boot command.

     

    setenv("xsa_boot", "run dtb_read_sdram; setenv bootargs ${cmdline_common} ${fs_axfs}; fdt chosen; run xImg");

     

    Also note that the kernel command in your Device Tree is also overwritten by these commands:

        " setenv bootargs ${cmdline_common} ${fs_axfs}; fdt chosen "

    So, you can remove these lines if you want to boot using the command line in your Device Tree.

    Then, your command will look like this:

    setenv("xsa_boot", "run dtb_read_sdram; run xImg");

     

    Then, you can just use the Device Tree:

        chosen {
            bootargs = "ignore_loglevel earlyprintk xx xx xx   ";
            stdout-path = "serial0:115200n8";
        };

     

    Chris

  • In reply to Chris:

    Dear Chris,

    Thanks for your reply, as you suggested i tried the below following changes
    1) I removed "run dtb_mem_sdram" from xsa_boot command in u-boot, rebuilded it and flashed.
    2)when i typed the command run xsa_boot i was stuck in Booting Linux...
    3)As you have suggested then I tried removing "setenv bootargs ${cmdline_common} ${fs_axfs}; fdt chosen " in the u-boot

    changes in the device tree looks like this
    chosen {
    /* Keep extra spaces at the end in case you want to add additional command line options from u-boot */
    /* bootargs = "ignore_loglevel earlyprintk earlycon=scif,0xE8008800 rootfstype=axfs root=/dev/null rootflags=physaddr=0x18800000 ";*/
    bootargs = "ignore_loglevel earlyprintk rw rootfstype=axfs root=/dev/null rootflags=physaddr=0x18800000";
    /*bootargs = "ignore_loglevel rw rootfstype=axfs root=/dev/null rootflags=physaddr=0x18800000";*/
    stdout-path = "serial0:115200n8";
    };


    4)i rebuilded it and flashed the board .

    this is my u-boot environment

    baudrate=115200
    bootargs=ignore_loglevel
    bootcmd=run xa_boot
    bootdelay=3
    cmdline_common=console=ttySC3,115200 ignore_loglevel rw root=/dev/mmcblk0p1 earlyprintk earlycon=scif,0xE8008800
    dtb_mem_ram=fdt memory 0x20000000 0x00A00000
    dtb_mem_sdram=fdt memory 0x0C000000 0x02000000
    dtb_read_ram=sf probe 0; sf read 20500000 C0000 8000; fdt addr 20500000 ; setenv addr_dtb 20500000
    dtb_read_sdram=sf probe 0; sf read 0D800000 C0000 8000; fdt addr 0D800000 ; setenv addr_dtb 0D800000
    ethact=sh_eth
    fs_axfs=rootfstype=axfs rootflags=physaddr=0x18800000
    fs_ext3=root=/dev/mmcblk0p1
    fs_mtd=root=/dev/mtdblock0
    ipaddr=172.16.30.55
    serverip=172.16.30.1
    stderr=serial_sh
    stdin=serial_sh
    stdout=serial_sh
    uImg=qspi dual; cp.b 0x18200000 09000000 0x400000; bootm start 09000000 - 0D800000; bootm loados ; bootm go
    xImg=qspi single; setenv cmd bootx 0x18200000 ${addr_dtb}; run cmd
    xa1_boot=run dtb_read_ram; run dtb_mem_ram; setenv bootargs ${cmdline_common} ${fs_ext3}; fdt chosen; run xImg
    xa_boot=run dtb_read_ram; run dtb_mem_ram; setenv bootargs ${cmdline_common} ${fs_axfs}; fdt chosen; run xImg
    xsa_boot=run dtb_read_sdram; run xImg

    following messages i am getting when i run xsa_boot
    run xsa_boot
    SF: Detected mx66l51235f with page size 256 Bytes, erase size 64 KiB, total 64 MiB
    device 0 offset 0xc0000, size 0x8000
    SF: 32768 bytes @ 0xc0000 Read: OK
    Current Mode: Read Mode (3-byte Addr) (RZ/A1 reset value)
    SF: Detected mx66l51235f with page size 256 Bytes, erase size 64 KiB, total 64 MiB
    New Mode: Quad I/O Read Mode (4-byte Addr)
    Booting Linux...
    Booting Linux on physical CPU 0x0
    Linux version 4.9.65-g8b4d151-dirty (mahesh@mahesh-HP-240-G3-Notebook-PC) (gcc version 6.4.1 20170707 (Linaro GCC 6.4-2017.08) ) #75 Wed Jun 19
    CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=58c53c7d
    CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
    OF: fdt:Machine model: SMRZA1H
    debug: ignoring loglevel setting.
    bootconsole [earlycon0] enabled
    Memory policy: Data cache writeback

    can please clarify my below doubts.
    1)can we enable 64MB of SD-RAM in Renesas RZ/A1H Board(we are using Etrontech SD-card of 512Mb i.e 64 MB)
    2)If it is possible can please tell me how to do it.


    Thanks and regards
    Mahesh
  • In reply to mahesh:

    Your old command line from u-boot was:

    cmdline_common=console=ttySC3,115200 ignore_loglevel rw root=/dev/mmcblk0p1 earlyprintk earlycon=scif,0xE8008800

     

    But, now your new command line in Device Tree is:

    chosen {
       bootargs = "ignore_loglevel earlyprintk rw rootfstype=axfs root=/dev/null rootflags=physaddr=0x18800000";
       stdout-path = "serial0:115200n8";
    };

    They are different.

     

    I think you need to change the command line in the Device Tee to match your old one:

    chosen {
       bootargs = "ttySC3,115200 ignore_loglevel rw root=/dev/mmcblk0p1 earlyprintk earlycon=scif,0xE8008800";
       stdout-path = "serial0:115200n8";
    };

     

    1. 1)can we enable 64MB of SD-RAM in Renesas RZ/A1H Board(we are using Etrontech SD-card of 512Mb i.e 64 MB)

    The Renesas RZ/A1H RSK board only has 32MB of SDRAM.

  • In reply to Chris:

    Dear Chris,

    As you have suggested i changed the following in dts file.

    chosen {
    bootargs = "ignore_loglevel earlyprintk rw rootfstype=axfs root=/dev/null rootflags=physaddr=0x18800000";
    stdout-path = "serial0:115200n8";
    };

    but it is stopping in this stage

    run xsa_boot
    SF: Detected mx66l51235f with page size 256 Bytes, erase size 64 KiB, total 64 MiB
    device 0 offset 0xc0000, size 0x8000
    SF: 32768 bytes @ 0xc0000 Read: OK
    Current Mode: Read Mode (3-byte Addr) (RZ/A1 reset value)
    SF: Detected mx66l51235f with page size 256 Bytes, erase size 64 KiB, total 64 MiB
    New Mode: Quad I/O Read Mode (4-byte Addr)
    Booting Linux...
    Booting Linux on physical CPU 0x0
    Linux version 4.9.65-g8b4d151-dirty (mahesh@mahesh-HP-240-G3-Notebook-PC) (gcc version 6.4.1 20170707 (Linaro GCC 6.4-2017.08) ) #75 Wed Jun 19
    CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=58c53c7d
    CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
    OF: fdt:Machine model: SMRZA1H
    debug: ignoring loglevel setting.
    bootconsole [earlycon0] enabled
    Memory policy: Data cache writeback

    can you please help us regarding the above issues.


    i'am using renesas rz/a1h custom based board in that we want to enable 64 MB of External Ram i.e Etrontech SD-RAM of 512Mb i.e 64 MB which has same pin configuration and same frequency of SD-RAM in Renesas RSK Board can we enable it and we have tried it by making changes in dts file and u-boot but be are getting fdt error in u-boot prompt.
  • In reply to mahesh:

    i'am using renesas rz/a1h custom based board in that we want to enable 64 MB of External Ram i.e Etrontech SD-RAM of 512Mb i.e 64 MB which has same pin configuration and same frequency of SD-RAM in Renesas RSK Board can we enable it and we have tried it by making changes in dts file and u-boot but be are getting fdt error in u-boot prompt.

    Did you configure all the correct timing values for the RZ/A SDRAM controller in u-boot? If you are using a different SDRAM chip, you need to refer to the SDRAM's hardware specification and calculate the new register values for the SDRAM controller.

    After modifying the timing registers for the new SDRAM, did you perform memory tests on the Etrontech using u-boot to confirm that the SDRAM is working correctly?