Forum Discussion
uClinux .data segment in SDRAM?
For a number of reasons, I'd like to run my kernel in SRAM but allocate data memory (i.e. socket buffers) in SDRAM. This seems possible with a NIOS 'Hello World' application, or the like, but these options aren't readily apparent when creating a kernel project in Eclipse. Is there a config file I can tweak, or other steps to be performed to accomplish putting .DATA in SDRAM? I've considered actually rewriting appropriate allocation routines in the kernel, but that feels very dangerous. Any help would be appreciated.
Thanks in advance, Ryan22 Replies
- Altera_Forum
Honored Contributor
If let me guess, I will go to arch/nios2nommu/kernel/setup.c, at the end of setup_arch(). There give all the memory to init_bootmem_node. I am not sure if this is the reason of your problem, but you should be able to find out by stepping through the booting procedures...
- Altera_Forum
Honored Contributor
Hi Wentao,
I've been back and forth on this project and another, so sorry for no response last week. I've been through a number of permutations of mappings and kernel changes in attacking this problem, so I'll just post what I have now (and how it's failing) and hopefully you may have some suggestions. I had our board image remapped to eliminate the 'gap' between SDRAM and SRAM. So, now the map looks like this: 0x0-0x07ffffff -- 128MB of SDRAM 0x08000000-0x09000000 -- 16 MB of SRAM So, again, I'd like to run code in SRAM but allocate kernel memory in SDRAM. I edited paging_init to give all of SRAM to ZONE_DMA:
and I changed ZONE_NORMAL accordingly:zones_size = (0x08000000-PAGE_OFFSET) >> PAGE_SHIFT;
(note: here end_mem is 0x09000000) Then I edited page.h to# define PAGE_OFFSET as 0. These changes build fine and boot on the new image. However, when I try:zones_size =(end_mem-0x08000000) >> PAGE_SHIFT;
...I get the following 'page allocation failure':char * str = kmalloc(2048,GFP_DMA)
Just wondering if there is anything you could suggest I do. My options are fairly open (that is, I can remap SDRAM somewhere else if necessary). Let me know if anything needs clarified. Thanks in advance, Ryan Quantapoint, Inc.swapper: page allocation failure. order:0, mode:0x1 Stack from 08327eb8:<0> <0> 00000000<0> 0802dc14<0> 00000000<0> 00000000<0> 00000001<0> 00000003<0> 00000000<0> 00000001<0> <0> 00000000<0> 0817b8ec<0> 0817b8e0<0> 082f2060<0> 0817b8e0<0> deadbeef<0> 0802dc44<0> 08031a54<0> <0> 00000000<0> 08032300<0> deadbeef<0> deadbeef<0> deadbeef<0> deadbeef<0> fffffc18<0> 00000001<0> <0> 00000001<0> 00000001<0> 08031fb8<0> 08c0e000<0> 08169f90<0> deadbeef<0> fffffc18<0> 00000001<0> <0> 00000000<0> 0816c608<0> 081698f8<0> 0816c30c<0> 0816c8d0<0> 00000001<0> 00000001<0> 08169a0c<0> <0> 00000000<0> 0816c890<0> 08000274<0> deadbeef<0> deadbeef<0> deadbeef<0> 081756c0<0> 080044c4<0> Call Trace:<0> <0> <0> <0> <0> <0> <0> <0> <0> - Altera_Forum
Honored Contributor
go to arch/nios2nommu/kernel/setup.c, after the call of init_bootmem_node , put a free_bootmem for your SDRAM. This will label your SDRAM as free memory.
wentao Microtronix Datacom Ltd. - Altera_Forum
Honored Contributor
<div class='quotetop'>QUOTE </div>
--- Quote Start --- go to arch/nios2nommu/kernel/setup.c, after the call of init_bootmem_node , put a free_bootmem for your SDRAM. This will label your SDRAM as free memory[/b] --- Quote End --- I did this (after the first free_bootmem call) as below:
...and got the same result as before (page allocation error on kmalloc(2048,GFP_DMA)). Did I miss something? Ryanfree_bootmem(0x0,0x08000000); - Altera_Forum
Honored Contributor
sorry, that is all I can imagine about this problem. It could be something else causing this problem...
- Altera_Forum
Honored Contributor
I occured to me that your problem might be caused by the address you gaven to SDRAM. It is not a good idea to give address 0 to anyone. It will be intepreted as NULL. When you want to allocated a DAM buffer through kmalloc, the slab allocator will try to grab pages, and the first page (with address 0) will be returned, making the slab think there is no memory available...
<div class='quotetop'>QUOTE </div> --- Quote Start --- 0x0-0x07ffffff -- 128MB of SDRAM 0x08000000-0x09000000 -- 16 MB of SRAM[/b] --- Quote End --- - Altera_Forum
Honored Contributor
Hi Wentao,
I'm back on this problem after some more immediate issues. Your last suggestion seems to make no difference. At this point, I'm looking for the simplest solution to this problem. It seems like there is a general problem with allocating memory below where the kernel lives. My question is, what would be the ideal physical mapping for what I am trying to do? I can move SRAM, SDRAM, FLASH, etc wherever you recommend. I'm thinking the easier solution might be to remap the system in a way that the kernel can deal with, rather than hacking at the kernel to get it to use my mapping. Any thoughts? Again, my requirement is that the kernel runs from SRAM but allocates memory from SDRAM. Thanks again, Ryan - Altera_Forum
Honored Contributor
actually my system has sram in a lower address than sdram. And there is a hole between them. I tried to add sram to the paging pool and did not find problems. I can allocate buffer from sram. All the mods needed were discussed in this thread.
- Altera_Forum
Honored Contributor
Hi Wentao,
I went back and started from scratch on this, and I got the kernel to use SDRAM as GFP_DMA. I can allocate a buffer using 'kmalloc' in SDRAM. However, I have since encountered a couple new problems: 1) I can't seem to kmalloc more than 4MB -- not sure if this is normal behavior or not. 2) I get Perror: Bad Address when I try to send an SDRAM buffer over a TCP socket, regardless of the size of the buffer. Googling for this perror I see that it's caused by an 'invalid address'. Thanks again, I think I'm getting close, Ryan - Altera_Forum
Honored Contributor
1). normal
2). I have no idea. Maybe the way you handle the buffer is not right.