Accessing u-boot environment from user space

Hi,

I am using sc589 board and want to access u-boot environment from user space. I know the tool "fw_printenv" to print the variables but it shows "bad CRC, using default environment" warning and prints default variables instead of that are in source code.

fw_printenv shows the result as follows:

[root@rspb ~]# fw_printenv
Warning: Bad CRC, using default environment
bootcmd=run vnlboot
bootdelay=3
baudrate=57600
loads_echo=1
ethaddr=02:80:ad:20:31:e8
ipaddr=192.168.0.15
serverip=192.168.0.2
autoload=no
rootpath=/romfs
gatewayip=192.168.0.1
netmask=255.255.255.0
hostname="sc58x"
loadaddr=0xC2000000
nc=set ncip ${serverip};set stdin nc;set stdout nc;set stderr nc
ubootfile=u-boot.ldr
kernel=uImage
rootfs=rootfs.gz
dtbfile=vnl-rspb.dtb
rfsaddr=0xC6000000
dtbaddr=0xC4000000
bootargs_base=root=/dev/ram0 rw earlyprintk=serial,uart0,57600 console=ttySC0,57600
update=tftp ${loadaddr} ${ubootfile};sf probe 2:1;sf erase 0 0x80000;sf write ${loadaddr} 0 ${filesize}
addip=set bootargs ${bootargs} ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}:eth0:off
ramfile=uImage
ramargs=set bootargs ${bootargs_base}
ramboot=tftp ${loadaddr} ${ramfile};tftp ${dtbaddr} ${dtbfile};run ramargs;run addip;bootm ${loadaddr} - ${dtbaddr}
vnlargs=set bootargs ${bootargs_base}
vnlboot=tftp ${loadaddr} ${kernel};tftp ${rfsaddr} ${rootfs};tftp ${dtbaddr} ${dtbfile};run vnlargs;run addip;bootm ${loadaddr} ${rfsaddr} ${dtbaddr}
mmcargs=set bootargs ${bootargs_base}
mmcboot=mmc dev 0;fatload mmc 0 ${loadaddr} ${kernel};fatload mmc 0 ${rfsaddr} ${rootfs};fatload mmc 0 ${dtbaddr} ${dtbfile};run mmcargs;run addip;bootm ${loadaddr} ${rfsaddr} ${dtbaddr}
loaduboot=tftp ${loadaddr} ${ubootfile}
sf_update=sf probe 2:1;sf erase 0 0x80000;sf write ${loadaddr} 0 ${filesize}
burnuboot=if run loaduboot;then run sf_update;reset;fi
erasenv=sf probe 2:1;sf erase 0x80000 +0x2000

but the u-boot environment is as below:

rspb #
rspb #
rspb # printenv
addip=set bootargs ${bootargs} ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}:eth0:off
autoload=no
baudrate=57600
boot_partid=1
bootargs=root=/dev/ram0 rw earlyprintk=serial,uart0,57600 console=ttySC0,57600 ip=192.168.0.16:192.168.0.1:192.168.0.1:255.255.255.0:sc58x:eth0:off
bootargs_base=root=/dev/ram0 rw earlyprintk=serial,uart0,57600 console=ttySC0,57600
bootcmd=run mmcboot
bootdelay=3
bootfile=vnl-rspb.dtb
burnuboot=if run loaduboot;then run sf_update;reset;fi
dnsip=10.100.200.55
dtbaddr=0xC4000000
dtbfile=vnl-rspb.dtb
erasenv=sf probe 2:1;sf erase 0x80000 +0x2000
ethact=dwmac.3100c000
ethaddr=02:80:ad:20:31:e8
gatewayip=10.100.206.1
hostname="sc58x"
ipaddr=10.100.206.82
kernel=uImage
loadaddr=0xC2000000
loads_echo=1
loaduboot=tftp ${loadaddr} ${ubootfile}
mmcargs=set bootargs ${bootargs_base}
mmcboot=mmc dev 0;fatload mmc 0:${boot_partid} ${loadaddr} ${kernel};fatload mmc 0:${boot_partid} ${rfsaddr} ${rootfs};fatload mmc 0:${boot_partid} ${dtbaddr} ${dtbfile};run mmcargs;run addip;bootm ${loadaddr} ${rfsaddr} ${dtbaddr}
nc=set ncip ${serverip};set stdin nc;set stdout nc;set stderr nc
netmask=255.255.255.0
ramargs=set bootargs ${bootargs_base}
ramboot=tftp ${loadaddr} ${ramfile};tftp ${dtbaddr} ${dtbfile};run ramargs;run addip;bootm ${loadaddr} - ${dtbaddr}
ramfile=uImage
rfsaddr=0xC6000000
rootfs=rootfs.gz
rootpath=/romfs
serverip=10.100.206.178
sf_update=sf probe 2:1;sf erase 0 0x80000;sf write ${loadaddr} 0 ${filesize}
stderr=serial
stdin=serial
stdout=serial
temp_env_var=0
ubootfile=u-boot.ldr
update=tftp ${loadaddr} ${ubootfile};sf probe 2:1;sf erase 0 0x80000;sf write ${loadaddr} 0 ${filesize}
ver=U-Boot 2015.01 ADI-1.2.0 VNL-RSPB, shivani.tripathi@GSR-Server, SVN#633 (Oct 11 2021 - 10:31:20)
vnlargs=set bootargs ${bootargs_base}
vnlboot=tftp ${loadaddr} ${kernel};tftp ${rfsaddr} ${rootfs};tftp ${dtbaddr} ${dtbfile};run vnlargs;run addip;bootm ${loadaddr} ${rfsaddr} ${dtbaddr}

Environment size: 2023/8188 bytes

My dmesg result is:

[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 4.0.0-VNL-1.1.02-SVN#562 (shivani.tripathi@GSR-Server) (gcc version 4.8.3 (Analog Devices Inc. ARM Tools (d9f69c572e3368746d6d95caf93dae57c9a689d4). Distributed as part of CrossCore Embedded Studio and associated add-ins. jenkins-LINUXADDIN1_2_0_arm_linux_gnueabi_toolchain-8 8 edin-stoke) ) #4 Tue Jun 29 12:33:14 IST 2021
[ 0.000000] CPU: ARMv7 Processor [410fc051] revision 1 (ARMv7), cr=10c53c7d
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[ 0.000000] Machine model: ADI sc589-ezkit
[ 0.000000] Ignoring memory range 0xc0000000 - 0xc2000000
[ 0.000000] bootconsole [earlycon0] enabled
[ 0.000000] Memory policy: Data cache writeback
[ 0.000000] On node 0 totalpages: 122880
[ 0.000000] free_area_init_node: node 0, pgdat c04da608, node_mem_map dc95c000
[ 0.000000] Normal zone: 960 pages used for memmap
[ 0.000000] Normal zone: 0 pages reserved
[ 0.000000] Normal zone: 122880 pages, LIFO batch:31
[ 0.000000] dump init clock rate
[ 0.000000] CGU0_PLL 450 MHz
[ 0.000000] CGU0_SYSCLK 225 MHz
[ 0.000000] CGU0_CCLK 450 MHz
[ 0.000000] CGU0_SYS0 112 MHz
[ 0.000000] CGU0_DCLK 450 MHz
[ 0.000000] CGU0_OCLK 150 MHz
[ 0.000000] CGU0_SYS0 112 MHz
[ 0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[ 0.000000] pcpu-alloc: [0] 0
[ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 121920
[ 0.000000] Kernel command line: root=/dev/ram0 rw earlyprintk=serial,uart0,57600 console=ttySC0,57600 ip=10.100.206.82:10.100.206.178:10.100.206.1:255.255.255.0:sc58x:eth0:off
[ 0.000000] PID hash table entries: 2048 (order: 1, 8192 bytes)
[ 0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
[ 0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
[ 0.000000] Memory: 464436K/491520K available (3423K kernel code, 115K rwdata, 1252K rodata, 148K init, 73K bss, 27084K reserved, 0K cma-reserved)
[ 0.000000] Virtual kernel memory layout:
[ 0.000000] vector : 0xffff0000 - 0xffff1000 ( 4 kB)
[ 0.000000] fixmap : 0xffc00000 - 0xfff00000 (3072 kB)
[ 0.000000] vmalloc : 0xde800000 - 0xff000000 ( 520 MB)
[ 0.000000] lowmem : 0xc0000000 - 0xde000000 ( 480 MB)
[ 0.000000] modules : 0xbf000000 - 0xc0000000 ( 16 MB)
[ 0.000000] .text : 0xc0008000 - 0xc0498f74 (4676 kB)
[ 0.000000] .init : 0xc0499000 - 0xc04be000 ( 148 kB)
[ 0.000000] .data : 0xc04be000 - 0xc04dade0 ( 116 kB)
[ 0.000000] .bss : 0xc04dade0 - 0xc04ed5a8 ( 74 kB)
[ 0.000000] NR_IRQS:16 nr_irqs:16 16
[ 0.000000] GIC CPU mask not found - kernel will fail to boot.
[ 0.000000] GIC CPU mask not found - kernel will fail to boot.
[ 0.000029] sched_clock: 32 bits at 112MHz, resolution 8ns, wraps every 38177486839ns
[ 0.015926] Console: colour dummy device 80x30
[ 0.024705] Calibrating delay loop... 297.98 BogoMIPS (lpj=595968)
[ 0.072621] pid_max: default: 32768 minimum: 301
[ 0.082207] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[ 0.095381] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[ 0.110595] CPU: Testing write buffer coherency: ok
[ 0.120644] Setting up static identity map for 0xc2342ac0 - 0xc2342af4
[ 0.135801] devtmpfs: initialized
[ 0.143077] do_initcall_level level 0
[ 0.150498] do_initcall_level level 1
[ 0.157748] VFP support v0.3: implementor 41 architecture 2 part 30 variant 5 rev 1
[ 0.174152] pinctrl core: initialized pinctrl subsystem
[ 0.198221] NET: Registered protocol family 16
[ 0.207166] do_initcall_level level 2
[ 0.215630] DMA: preallocated 256 KiB pool for atomic coherent allocations
[ 0.232102] do_initcall_level level 3
[ 0.240978] L2C: device tree omits to specify unified cache
[ 0.252035] L2C-310 dynamic clock gating enabled, standby mode enabled
[ 0.265164] L2C-310 cache controller enabled, 8 ways, 256 kB
[ 0.276596] L2C-310: CACHE_ID 0x410000c9, AUX_CTRL 0x06040000
[ 0.288215] sc58x_init: registering device resources
[ 0.298275] sec init...
[ 0.302890] enabled
[ 0.341556] hw-breakpoint: Failed to enable monitor mode on CPU 0.
[ 0.354846] ADI DMA2 Controller
[ 0.367582] do_initcall_level level 4
[ 0.395525] SCSI subsystem initialized
[ 0.404628] usbcore: registered new interface driver usbfs
[ 0.416102] usbcore: registered new interface driver hub
[ 0.426763] usbcore: registered new device driver usb
[ 0.438715] mcp230xx: probe of 0-0021 failed with error -1
[ 0.450243] mcp230xx: probe of 0-0022 failed with error -1
[ 0.461618] i2c-bfin-twi 31001400.twi: Blackfin on-chip I2C TWI Contoller, regs_base@f4001400
[ 0.479095] i2c-bfin-twi 31001500.twi: Blackfin on-chip I2C TWI Contoller, regs_base@f4001500
[ 0.496567] i2c-bfin-twi 31001600.twi: Blackfin on-chip I2C TWI Contoller, regs_base@f4001600
[ 0.514061] pps_core: LinuxPPS API ver. 1 registered
[ 0.523824] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[ 0.542494] PTP clock support registered
[ 0.552134] do_initcall_level level 5
[ 0.559979] Switched to clocksource cs_gptimer
[ 0.592014] NET: Registered protocol family 2
[ 0.602032] TCP established hash table entries: 4096 (order: 2, 16384 bytes)
[ 0.616086] TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
[ 0.629060] TCP: Hash tables configured (established 4096 bind 4096)
[ 0.641970] TCP: reno registered
[ 0.648414] UDP hash table entries: 256 (order: 0, 4096 bytes)
[ 0.660219] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[ 0.673130] NET: Registered protocol family 1
[ 0.682106] Unpacking initramfs...
[ 3.401766] Freeing initrd memory: 17656K (dcd24000 - dde62000)
[ 3.413552] do_initcall_level level 6
[ 3.421138] hw perfevents: enabled with armv7_cortex_a5 PMU driver, 3 counters available
[ 3.440110] futex hash table entries: 256 (order: -1, 3072 bytes)
[ 3.454728] jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
[ 3.468585] External imprecise Data abort at addr=0xb6f87880, fsr=0x1c06 ignored.
[ 3.530451] io scheduler noop registered (default)
[ 3.540333] ADI serial driver
[ 3.546556] adi-uart4.0: ttySC0 at MMIO 0x31003000 (irq = 20, base_baud = 7031250) is a ADI-UART4
[ 3.564472] console [ttySC0] enabled
[ 3.578565] bootconsole [earlycon0] disabled
[ 3.596596] adi-uart4.1: ttySC1 at MMIO 0x31003400 (irq = 81, base_baud = 7031250) is a ADI-UART4
[ 3.614705] adi-uart4.2: ttySC2 at MMIO 0x31003800 (irq = 84, base_baud = 7031250) is a ADI-UART4
[ 3.643759] loop: module loaded
[ 3.650149] at24 0-0050: 4096 byte 24c32 EEPROM, writable, 1 bytes/write
[ 3.663300] at24 2-0050: 4096 byte 24c32 EEPROM, writable, 1 bytes/write
[ 3.731250] adi-spi3 31042000.spi: registered ADI SPI controller spi0
[ 3.796835] adi-spi3 31043000.spi: registered ADI SPI controller spi1
[ 3.818684] m25p80 spi2.38: found w25q128, expected w25q32
[ 3.829638] m25p80 spi2.38: w25q128 (16384 Kbytes)
[ 3.838903] 3 ofpart partitions found on MTD device spi2.38
[ 3.849975] Creating 3 MTD partitions on "spi2.38":
[ 3.859699] 0x000000000000-0x000000080000 : "u-boot"
[ 3.871301] 0x000000080000-0x000000082000 : "env"
[ 3.882226] 0x000000082000-0x000001000000 : "kernel"
[ 3.920095] adi-spi3 31044000.spi: registered ADI SPI controller spi2
[ 3.933775] libphy: Fixed MDIO Bus: probed
[ 3.943399] stmmaceth 3100c000.ethernet: no reset control found
[ 3.955044] stmmac - user ID: 0x10, Synopsys ID: 0x37
[ 3.964954] Ring mode enabled
[ 3.971022] DMA HW capability register supported
[ 3.980044] Enhanced/Alternate descriptors
[ 3.988715] Enabled extended descriptors
[ 3.996700] RX Checksum Offload Engine supported (type 2)
[ 4.007629] TX Checksum insertion supported
[ 4.016131] Wake-Up On Lan supported
[ 4.023419] Enable RX Mitigation via HW Watchdog Timer
[ 4.046546] libphy: stmmac: probed
[ 4.053046] eth0: PHY ID 2000a231 at 0 IRQ POLL (stmmac-0:00) active
[ 4.066337] usbcore: registered new interface driver usb-storage
[ 4.079387] musb-hdrc: ConfigData=0x1e (UTMI-8, dyn FIFOs, HB-ISO Rx, HB-ISO Tx, SoftConn)
[ 4.079412] musb-hdrc: MHDRC RTL version 2.0
[ 4.079427] musb-hdrc: setup fifo_mode 4
[ 4.079460] musb-hdrc: 28/31 max ep, 16384/16384 memory
[ 4.079524] musb-hdrc musb-hdrc.1.auto: MUSB HDRC host driver
[ 4.091021] musb-hdrc musb-hdrc.1.auto: new USB bus registered, assigned bus number 1
[ 4.107617] hub 1-0:1.0: USB hub found
[ 4.115011] hub 1-0:1.0: 1 port detected
[ 4.124301] musb-hdrc: ConfigData=0x1e (UTMI-8, dyn FIFOs, HB-ISO Rx, HB-ISO Tx, SoftConn)
[ 4.124325] musb-hdrc: MHDRC RTL version 2.0
[ 4.124339] musb-hdrc: setup fifo_mode 4
[ 4.124371] musb-hdrc: 28/31 max ep, 16384/16384 memory
[ 4.124428] musb-hdrc musb-hdrc.3.auto: MUSB HDRC host driver
[ 4.135920] musb-hdrc musb-hdrc.3.auto: new USB bus registered, assigned bus number 2
[ 4.152470] hub 2-0:1.0: USB hub found
[ 4.159866] hub 2-0:1.0: 1 port detected
[ 4.168441] i2c /dev entries driver
[ 4.176927] adi_wdt: initialized: timeout=20 sec (nowayout=0)
[ 4.189393] Synopsys Designware Multimedia Card Interface Driver
[ 4.202161] dwmmc_adi mmc.0: num-slots property not found, assuming 1 slot is available
[ 4.217985] dwmmc_adi mmc.0: IDMAC supports 32-bit address mode.
[ 4.229840] dwmmc_adi mmc.0: Using internal DMA controller.
[ 4.240908] dwmmc_adi mmc.0: Version ID is 270a
[ 4.249968] dwmmc_adi mmc.0: DW MMC controller at irq 103, 32 bit host data width, 1024 deep fifo
[ 4.267671] dwmmc_adi mmc.0: No vmmc regulator found
[ 4.277507] dwmmc_adi mmc.0: No vqmmc regulator found
[ 4.319630] dwmmc_adi mmc.0: 1 slots initialized
[ 4.328770] Blackfin hardware CRC crypto driver
[ 4.352775] bfin-hmac-crc 31001200.crc: initialized
[ 4.362494] bfin-hmac-crc 31001300.crc: initialized
[ 4.373005] usbcore: registered new interface driver usbhid
[ 4.383826] usbhid: USB HID core driver
[ 4.392521] adi,corectrl 3108b000.core_ctrl: initialized
[ 4.404129] icc 20080000.icc: initialized
[ 4.411931] mmc0: MAN_BKOPS_EN bit is not set
[ 4.422758] mmc_host mmc0: Bus speed (slot 0) = 50000000Hz (slot req 52000000Hz, actual 50000000HZ div = 0)
[ 4.446007] RSPB GPIO Driver Initialized
[ 4.454323] lm73dev_init : Device Region Allocated. Major Number : 250
[ 4.467510] rspb_lm73.c : adapter [31001400.twi] registered as minor 0
[ 4.482701] mmc0: new high speed MMC card at address 0001
[ 4.493945] mmcblk0: mmc0:0001 P1XXXX 7.20 GiB
[ 4.503076] rspb_lm73.c : adapter [31001500.twi] registered as minor 1
[ 4.516029] mmcblk0boot0: mmc0:0001 P1XXXX partition 1 16.0 MiB
[ 4.527868] rspb_lm73.c : adapter [31001600.twi] registered as minor 2
[ 4.540845] mmcblk0boot1: mmc0:0001 P1XXXX partition 2 16.0 MiB
[ 4.552951] ADSP Register Driver Initialized !!!
[ 4.563393] mmcblk0: p1 p2 p3 p4
[ 4.569862] TCP: cubic registered
[ 4.580391] NET: Registered protocol family 17
[ 4.589075] do_initcall_level level 7
[ 4.596256] ThumbEE CPU extension supported.
[ 4.607655] console [netcon0] enabled
[ 4.614643] netconsole: network logging started
[ 4.716021] IP-Config: Complete:
[ 4.722165] device=eth0, hwaddr=02:80:ad:20:31:e8, ipaddr=10.100.206.82, mask=255.255.255.0, gw=10.100.206.1
[ 4.742613] host=sc58x, domain=, nis-domain=(none)
[ 4.753024] bootserver=10.100.206.178, rootserver=10.100.206.178, rootpath=
[ 4.768541] Freeing unused kernel memory: 148K (c0499000 - c04be000)
[ 4.896563] EXT4-fs (mmcblk0p4): recovery complete
[ 4.906526] EXT4-fs (mmcblk0p4): mounted filesystem with ordered data mode. Opts: (null)
[ 5.315630] random: dd urandom read with 28 bits of entropy available
[ 6.751854] stmmaceth 3100c000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
[ 7.104545] sm_debug:sm_find_session bits 00000000 localep 101
[ 7.118355] sm_debug:sm_find_session bits 00000000 localep 104
[ 7.130800] sm_debug:sm_find_session bits 00000000 localep 100
[ 15.720020] sm_debug:sm_find_session bits 00000000 localep 103
[ 15.733891] sm_debug:sm_find_session bits 00000000 localep 105
[ 15.746456] sm_debug:sm_find_session bits 00000000 localep 102
[ 26.063611] random: nonblocking pool is initialized

and  /etc/fw_env.config file is:

[root@rspb ~]# cat /etc/fw_env.config
# Configuration file for fw_(printenv/setenv) utility.
# Up to two entries are valid, in this case the redundant
# environment sector is assumed present.
# MTD device name Device offset Env. size Flash sector size
/dev/mtd1 0x0000 0x2000 0x10000

Am I doing anything wrong somewhere? I have gone through almost every discussion related to this on the internet but have not found the solution yet.

Thanks and regards

  • Hi Meena,

    It seems the fw_env.config entries were not configured well.

    Could you share the values of 

    $cat /proc/mtd

    Thanks,

    Prasanth R

  • Hi Prasanth,

    Thank you for the reply.

    cat /proc/mtd output is as below:

    [root@rspb ~]# cat /proc/mtd
    dev: size erasesize name
    mtd0: 00080000 00001000 "u-boot"
    mtd1: 00002000 00001000 "env"
    mtd2: 00f7e000 00001000 "kernel"

    and my env settings in /u-boot/include/configs/sc_adi_common.h are:

    /*
     * Env Storage Settings
     */
    #define CONFIG_ENV_OFFSET       0x0000
    #define CONFIG_ENV_OFFSET_SF    0x80000
    #define CONFIG_ENV_SIZE         0x2000
    #define CONFIG_ENV_SECT_SIZE    0x10000
    /* We need envcrc to embed the env into LDRs */
    #ifdef CONFIG_ENV_IS_EMBEDDED_IN_LDR
    # define CONFIG_BUILD_ENVCRC
    #endif
    I thought you might need this too.
    BR,
    Lalit
  • Hi Lalit,

    It might be due to the limited flash size,

    Could you try running "saveenv" in the u-boot and check for the warning still appears,

    [root@rspb ~]# fw_printenv
    Warning: Bad CRC, using default environment

    if so, let me know, the output of saveenv command.

    Have you done any modifications in the u-boot-fw-utils defconfig, kindly share those too?

    I am trying to recreate the same from myside.

    Thanks,

    Prasanth R

  • Hi Prasanth,

    There is one observation I have noted.

    What I am doing:

    1. saveenv on u-boot.

    2. booting the board with TFTP.

    3. running fw_printenv on Linux, does not give "bad CRC..." warning and prints correct env variables.

    4. Reset the board.

    5. no saveenv on uboot this time.

    7. step 2.

    6. step 3 ,but gives bad CRC warning this time.

    I repeated this many times and it always prints correct values when run saveenv on u-boot before booting the board with TFTP.

    When I run saveenv on u-boot it prints correct env variables in Linux, but why do I need to do this every time.

    Saveenv saves the env in flash when ran only one time and I can see them in u-boot correctly using "printenv" without running 'saveenv' every time I reset the board.