Home/Support/Support Forum/How to read newly added nvram variables once kernel is loaded ?
New and improved user forum site going live on 12/6 (All users will need to reset their password when the new forum is active)
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

How to read newly added nvram variables once kernel is loaded ?

0 votes
I need to add new variables to nvram in 'Digi connect ME 9210'. I can add it but was unable to find a way to read it back once the kernel is loaded.

I believe that nvram utility is not built as part of the kernel. Also in general if we add new parameters to the nvram through the uboot bootloaded then is there any other way other than nvram utility as to how i can read them back once the kernel is loaded.

If nvram utility is the only way then where do I find the code for nvram utility. The current utility allows me to read only the predefined nvram variables so i will have to modify the nvram utility to read the new variables that i add?

asked May 8, 2013 in Linux by sanju New to the Community (0 points)

Please log in or register to answer this question.

2 Answers

0 votes
use ubootenv command in linux kernel commandline for accessing nvram variables.
answered Aug 28, 2013 by tuxembb Veteran of the Digi Community (288 points)
0 votes
To read nvram from command line, check the examples in /etc/init.d/S40networking.sh /etc/init.d/S95runapp.sh /etc/network/if-up.d/ifup

If you want to read the from C source code, the API is documented only in source code:
it uses

How to compile the source code on your own (for modifications):
+ copy the toolchain from DVD to your local host:
# cp -r DEL59-DVD/toolchain .
# cd toolchain
# export TOOLCHAIN_DIR=/usr/local/DigiEL-5.9/x-tools/arm-unknown-linux-gnueabi
# export POOLWWW=file://`pwd`/packages
# cd del_toolchain/packages
# cd libdigi; make
# cd ../nvram; cp SOMEFOLDER/nvram-Makefile Makefile; make
# cd ../ubootenv
# cp SOMEFOLDER/ubootenv-Makefile.in Makefile.in
# cp SOMEFOLDER/cgi_env.c src
where SOMEFOLDER is where you extraced this application example source code
# make
copy target/ubootenv.cgi into your rootfs /usr/share/www/cgi-bin
copy stylesheet.csss into your rootfs /usr/share/www
Make NVRAM /dev/mdt1 read+writable for CGI script (see above)
You might want to modify the source code src/cgi_env.c
See src/*.[ch] and ../nvram/src/*.[ch] for example source code

here an example:

#include <stdio.h> /* printf() getchar() EOS */
#include <string.h> /* strncmp() */
#include <stdlib.h> // EXIT_FAILURE

#include <sys/utsname.h> /* uname(&struct utsname) */

#include "nvram.h" /* Nv* */

struct nv_critical *crit;
nv_param_ip_t *ip_params;
char ipaddr[IP_STRING_SIZE+1] = "";
char serverip[IP_STRING_SIZE+1] = "";

if (!NvInit(NVR_AUTO)) exit(-1);
if (!NvCriticalGet( &crit ) ) exit(-2);
ip_params = &crit->s.p.xIP;
strncpy(ipaddr, NvToStringIP(ip_params->axDevice[0].uiIP), sizeof(ipaddr));
strncpy(serverip, NvToStringIP(ip_params->uiIPServer), sizeof(serverip));
answered Apr 25, 2014 by User143 Community Contributor (132 points)