Jetson Nano U-boot tool fw_printenv and fw_setenv

Hello. I need to access the U-Boot environment from Linux userspace on the Jetson Nano. I can’t seem to find the fw_env.config that the U-Boot tools “fw_printenv” and “fw_setenv” require to access and modify the bootloader environment.

I get the following error:

root@jetson-nano:/tmp# ./fw_printenv
Cannot access MTD device /dev/mmcblk0boot1: No such file or directory

How can I access the U-Boot environment on the Jetson Nano? Thank you.

For TX1 and TX2 - these were under /dev/mmcblk0boot1:

ubuntu@ip-172-31-23-71:~/Desktop/jetson-yocto/build/tmp/deploy/images/jetson-nano$ cat /home/ubuntu/Desktop/jetson-yocto/layers/meta-tegra/recipes-bsp/u-boot/files/tegra210/fw_env.config
# Jetson-TX1 dev kit puts U-Boot params in eMMC boot1 partition
/dev/mmcblk0boot1	0x3fe000	0x2000
ubuntu@ip-172-31-23-71:~/Desktop/jetson-yocto/build/tmp/deploy/images/jetson-nano$ cat /home/ubuntu/Desktop/jetson-yocto/layers/meta-tegra/recipes-bsp/u-boot/files/tegra186/fw_env.config
# Jetson-TX2 dev kit puts U-Boot params in eMMC boot1 partition
/dev/mmcblk0boot1	0x3fe000	0x2000

FDisk shows the following:

Device             Start      End  Sectors  Size Type
/dev/mmcblk0p1     24576 33554398 33529823   16G Linux filesystem
/dev/mmcblk0p2      2048     2303      256  128K Linux filesystem
/dev/mmcblk0p3      4096     4991      896  448K Linux filesystem
/dev/mmcblk0p4      6144     7295     1152  576K Linux filesystem
/dev/mmcblk0p5      8192     8319      128   64K Linux filesystem
/dev/mmcblk0p6     10240    10623      384  192K Linux filesystem
/dev/mmcblk0p7     12288    13439     1152  576K Linux filesystem
/dev/mmcblk0p8     14336    14463      128   64K Linux filesystem
/dev/mmcblk0p9     16384    17663     1280  640K Linux filesystem
/dev/mmcblk0p10    18432    19327      896  448K Linux filesystem
/dev/mmcblk0p11    20480    20735      256  128K Linux filesystem
/dev/mmcblk0p12    22528    22687      160   80K Linux filesystem
/dev/mmcblk0p13 33554432 67186687 33632256   16G Linux filesystem

Partition table entries are not in disk order.

And Parted shows the following:

root@jetson-nano:/tmp# parted /dev/mmcblk0
GNU Parted 3.2
Using /dev/mmcblk0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: SD SR128 (sd/mmc)
Disk /dev/mmcblk0: 128GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
 2      1049kB  1180kB  131kB                TBC
 3      2097kB  2556kB  459kB                RP1
 4      3146kB  3736kB  590kB                EBT
 5      4194kB  4260kB  65.5kB               WB0
 6      5243kB  5439kB  197kB                BPF
 7      6291kB  6881kB  590kB                TOS
 8      7340kB  7406kB  65.5kB               EKS
 9      8389kB  9044kB  655kB                LNX
10      9437kB  9896kB  459kB                DTB
11      10.5MB  10.6MB  131kB                RP4
12      11.5MB  11.6MB  81.9kB               BMP
 1      12.6MB  17.2GB  17.2GB  ext4         APP
13      17.2GB  34.4GB  17.2GB  ext4         primary

I’m pretty sure u-boot is in the LNX partition - but I cannot seem to mount it:

root@jetson-nano:/mnt# mount /dev/disk/by-partlabel/LNX /mnt/u-boot/
mount: /mnt/u-boot: wrong fs type, bad option, bad superblock on /dev/mmcblk0p9, missing codepage or helper program, or other error.
root@jetson-nano:/mnt#
root@jetson-nano:/mnt# mount -o offset=$((16384*512)) /dev/disk/by-partlabel/LNX /mnt/u-boot/
mount: /mnt/u-boot: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.
root@jetson-nano:/mnt#
root@jetson-nano:/mnt# mount -o loop,offset=$((16384*512)) /dev/disk/by-partlabel/LNX /mnt/u-boot/
mount: /mnt/u-boot: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.
root@jetson-nano:/mnt#
root@jetson-nano:/mnt# mount -t ext4 /dev/disk/by-partlabel/LNX /mnt/u-boot/
mount: /mnt/u-boot: wrong fs type, bad option, bad superblock on /dev/mmcblk0p9, missing codepage or helper program, or other error.
root@jetson-nano:/mnt#
root@jetson-nano:/mnt# mount /dev/mmcblk0p9 /mnt/u-boot
mount: /mnt/u-boot: wrong fs type, bad option, bad superblock on /dev/mmcblk0p9, missing codepage or helper program, or other error.

I found this post: [u-boot] saveenv command? - Jetson Nano - NVIDIA Developer Forums

And I patched u-boot as shown here:

diff -Naur old/include/configs/p3450-porg.h new/include/configs/p3450-porg.h
--- old/include/configs/p3450-porg.h	2019-07-24 14:07:45.399829865 +0000
+++ new/include/configs/p3450-porg.h	2019-07-24 14:10:53.166129230 +0000
@@ -31,8 +31,12 @@
 #define BOOT_TARGET_DEVICES(func) \
 	func(MMC, mmc, 1)
 
-/* Environment s/b at end of SPI, fix it later */
-#define CONFIG_ENV_IS_NOWHERE
+/* Allow saving environment and reading it */
+/* Environment is on SD (mmc1), in filesystem (APP partition, part #1) */
+#define CONFIG_ENV_IS_IN_EXT4
+#define EXT4_ENV_INTERFACE		"mmc"
+#define EXT4_ENV_DEVICE_AND_PART	"1:1"
+#define EXT4_ENV_FILE			"/boot/uboot.env"
 
 /* SPI */
 #define CONFIG_SF_DEFAULT_MODE		SPI_MODE_0

But when the board boots there is no /boot/uboot.env

Well I finally got it to work. First you have to patch u-boot-tegra with the patch mentioned previously and then you have to use an FTDI cable and run saveenv from the U-boot shell at least once. And the /etc/fw_env.config file needs to be:

/boot/uboot.env 0x0000 0x2000

After all that, the fw_printenv and fw_setenv run and new variables are available from the u-boot shell.