I'm stumped, and I need someone to tell me what I'm missing.
I've had to upgrade the U-boot bootloader on my devices, and naturally I've had to make things fit again. And right now I'm trying to get the U-Boot environment variables accessible from Linux/Android.
Long story short, I've created a file /etc/fw_env.config that points to U-Boot's env section in Flash. As documented here: https://elinux.org/U-boot_environment_variables_in_linux
This has not been successful, and so I started adding print statements to the source code to debug my device. I tracked the error down to a get_config() function, which as one could imagine, opens the /etc/fw_env.config and writes the values within to the necessary variables.
I've narrowed it further down to the sscanf() function, which returns 0, as in 0 variables read and/or written. So, as a sanity check, I isolated the function and made my own little program separately from my source code (variable names and structures I kept exactly the same).
/* sscanf example */
#include <stdio.h>
struct envdev_s {
    const char *devname;            /* Device name */
    long long devoff;               /* Device offset */
    unsigned long env_size;         /* environment size */
    unsigned long erase_size;       /* device erase size */
    unsigned long env_sectors;      /* number of environment sectors */
    unsigned int mtd_type;          /* type of the MTD device */
};
static struct envdev_s envdevices[2] = {};
#define DEVNAME(i)    envdevices[(i)].devname
#define DEVOFFSET(i)  envdevices[(i)].devoff
#define ENVSIZE(i)    envdevices[(i)].env_size
#define DEVESIZE(i)   envdevices[(i)].erase_size
#define ENVSECTORS(i) envdevices[(i)].env_sectors
#define DEVTYPE(i)    envdevices[(i)].mtd_type
int main ()
{
  char dump [] = "/dev/mtd1 0xc0000 0x2000  0x2000\n";
  char *devname;
  int i = 0;
  int rc;
  printf("I was here in get_config : dump = %s\n", dump);
  printf("I was here in get_config : i = %d\n", i);
  rc = sscanf(dump, "%ms %lli %lx %lx %lx",
                &devname,
                &DEVOFFSET(i),
                &ENVSIZE(i),
                &DEVESIZE(i),
                &ENVSECTORS(i));
  printf("I was here in get_config : rc = %d\n", rc);
  return 0;
}
Also recreated here: http://cpp.sh/5ckms
Now, when I run this independently, it works as I expect it should, particularly outputting:
I was here in get_config : rc = 4
4 being successful, as char dump [] = "/dev/mtd1 0xc0000 0x2000  0x2000\n";
But when I compile this and run it on my device, it returns:
I was here in get_config : rc = 0
Computer says NO! And no other error messages to work with.
I'm obviously missing some fundamental understanding here. Either some permissions, or some setup-variables somewhere, but I wouldn't know in where to start. Could someone please point me in the right direction?
