Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

346
Views
Writing on NVRAM through unsigned char* and unsigned int*

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.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!