I'm developing under a linux embedded board I have a NVRAM where stores all my sensible data. I managed to access it via mmap /dev/mem, now the problem is writing, through an unsigned char* pointer there's no problem, but I need to write an entire structure, e.g.:
struct t_game_data
{
int energy;
int bet;
int coin;
};
after mapping my memory with:
unsigned char* mem_ptr = (unsigned char*)mmap((void *)0x0, 512*1024, PROT_READ | PROT_WRITE,MAP_SHARED, fd, 0x90600000);
I can write on NVRAM with no problem via mem_ptr:
*mem_ptr++ = 1;
*mem_ptr++ = 2;
*mem_ptr++ = 3;
mem_ptr++;
*mem_ptr++ = 4;
// What i get reading NVRAM is(NVRAM is filled with 255 by default)
1 2 3 255 4
But if I try to do something like this:
t_game_data* data = (t_game_data*)mmap((void *)0x0,512*1024, PROT_READ |PROT_WRITE, MAP_SHARED, fd, 0x90600000);
When I try to use data for writing I can't write on NVRAM properly, so I tried to use an unsigned int* just to understand the problem and I got something really strange:
unsigned int* mem_ptr_int = (unsigned int*)mmap((void *)0x0, 512*1024, PROT_READ | PROT_WRITE,MAP_SHARED, fd, 0x90600000);
*mem_ptr_int++ = 1;
*mem_ptr_int++ = 2;
*mem_ptr_int++ = 3;
mem_ptr_int++;
*mem_ptr_int++ = 4;
// What i get reading NVRAM is(NVRAM is filled with 255 by default)
0 255 255 255 0 255 255 255 0 255 255 255 255 255 255 255 0
Perhaps there's some problem with addressing I'm hoping it's not a physical limit of hw;
Thank you in advance.