U-Boot writes incorrect CRC in env - environment-variables

I'm using u-boot on raspberry pi 4, A/B booting from USB attached SSD, integrated with mender without yocto. Everything works fine except the env saving: initially configured to use MMC and offsets, fw_printenv complained about a bad CRC and output the default config instead. I changed the env saving to FAT files on the boot partition, and I'm now troubleshooting 2 issues:
uboot.env does not get written by issuing saveenv in the u-boot prompt
uboot-redund.env gets written but its CRC is incorrect.
I'm checking the CRC by issuing the fw_printenv command from linux. Its config file states:
/boot/u-boot/uboot-redund.env 0x0000 0x4000
U-Boot is compiled with 0x4000 as env size, and using hexdump to check the file shows a correct file with a length of 0x4000.
When booting up, u-boot outputs the following log over TTL serial:
U-Boot 2021.07-rc2-00246-gd64b3c608d-dirty (Jun 16 2021 - 12:16:24 +0200)
DRAM: 7.9 GiB
RPI 4 Model B (0xd03114)
MMC: mmcnr#7e300000: 1, emmc2#7e340000: 0
Loading Environment from FAT... In: serial
Out: vidconsole
Err: vidconsole
Net: eth0: ethernet#7d580000
PCIe BRCM: link up, 5.0 Gbps x1 (SSC)
starting USB...
Bus xhci_pci: Register 5000420 NbrPorts 5
Starting the controller
USB XHCI 1.00
scanning bus xhci_pci for devices... 3 USB Device(s) found
scanning usb for storage devices... 1 Storage Device(s) found
Hit any key to stop autoboot: 0
which shows that u-boot does load the env from FAT correctly.
How can I investigate further why u-boot does not write uboot.env, and why when it does write uboot-redund.env, writes it with a wrong CRC from fw_printenv's point of view?

env save
In function env_fat_save only one file is written. If CONFIG_SYS_REDUNDAND_ENVIRONMENT is defined, alternatively either file CONFIG_ENV_FAT_FILE_REDUND or file CONFIG_ENV_FAT_FILE is written.
You have to execute the command env save twice if you want to write both files.
Command env infoindicates which instance was written last via field env_valid:
=> env select FAT
Select Environment on FAT: OK
=> env info
env_valid = invalid
env_ready = true
env_use_default = false
=> env save
Saving Environment to FAT... OK
=> env info
env_valid = redundant
env_ready = true
env_use_default = false
=> env save
Saving Environment to FAT... OK
=> env info
env_valid = valid
env_ready = true
env_use_default = false
=>
fw_printenv
When using fw_printenv you must specify the configuration which matches your U-Boot build. By default file /etc/fw_env.config is used. You can pass the configuration file on the command line:
tools/env/fw_printenv -c fw_env.config
This is what your configuration file could look like:
uboot.env 0x0000 0x2000
uboot-redund.env 0x0000 0x2000
There is an example file in tools/env/fw_env.config explaining the available fields.

Related

Error While exiting Configuration mode using Python Script

It's been long since I opened stack websites.
please ignore any mistakes.
I am using telnetlib library to login into my Multilayer switch on GNS3.
I am Successfully able to configure loopback interfaces using script and execute show commands in it, including the show commands on configuration mode. Example : "do sh ip int br" OR "do sh run".
The issue is when my script does it's configuration and tries to exit then it is not exiting and the code is stuck.
I have to manually login into device and clear the vty line session to get the output.
Catch is : for both commands "exit" and "end" the code is removing the initial "e" which is happening only to the last "exit" and/or "end.
Below is the code :
import getpass
import sys
import telnetlib
HOST = input("Enter Device IP: ")
user = input("Enter your telnet username: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until(b"Username: ")
tn.write(user.encode('ascii') + b"\n")
if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")
tn.write(b"enable\n")
#tn.write(b"xxpasswordxx\n")
tn.write(b"conf t\n")
tn.write(b"int loop 2 \n")
tn.write(b"ip address 1.1.1.2 255.255.255.255 \r\n")
tn.write(b"exit \r\n") **>>>>> This exit is working fine.**
tn.write(b"do wr\n")
tn.write(b"exit \r\n") **>>>>> This exit is working fine.**
tn.write(b"sh ip int br \n")
tn.write(b"end\n") **>>>>> This exit/end is not working no matter if I use "exit" or "end", it removes initial "e"**
print (tn.read_all().decode('ascii'))
Output of switch CLI :
ESW1#
ESW1#
*Mar 1 03:00:07.635: %SYS-5-CONFIG_I: Configured from console by user1 on vty0 (20.20.20.6)
ESW1#sh users
Line User Host(s) Idle Location
* 0 con 0 idle 00:00:00
162 vty 0 user1 idle 00:00:22 20.20.20.6
Interface User Mode Idle Peer Address
ESW1#clear line vty 0
[confirm]
[OK]
ESW1#
Output of Windows-command line/ When I execute the script :
Path:\P_Project\MyScript>python Telnet_1.py
Enter Device IP: 20.20.20.1
Enter your telnet username: user1
Password:
***************************************************************
This is a normal Router with a Switch module inside (NM-16ESW)
It has been pre-configured with hard-coded speed and duplex
To create vlans use the command "vlan database" in exec mode
After creating all desired vlans use "exit" to apply the config
To view existing vlans use the command "show vlan-switch brief"
Alias(exec) : vl - "show vlan-switch brief" command
Alias(configure): va X - macro to add vlan X
Alias(configure): vd X - macro to delete vlan X
***************************************************************
ESW1#enable
ESW1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
ESW1(config)#int loop 2
ESW1(config-if)#ip address 1.1.1.2 255.255.255.255
ESW1(config-if)#exit
ESW1(config)#do wr
Building configuration...
[OK]
ESW1(config)#exit
ESW1#sh ip int br
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 20.20.20.1 YES manual up up
FastEthernet0/1 unassigned YES NVRAM administratively down down
FastEthernet1/0 unassigned YES unset up down
FastEthernet1/1 unassigned YES unset up down
FastEthernet1/2 unassigned YES unset up down
FastEthernet1/3 unassigned YES unset up down
FastEthernet1/4 unassigned YES unset up down
FastEthernet1/5 unassigned YES unset up down
FastEthernet1/6 unassigned YES unset up down
FastEthernet1/7 unassigned YES unset up down
FastEthernet1/8 unassigned YES unset up down
ESW1#nd
Translating "nd" >>>> To print this error I have to execute the command "clear line vty 0" on switch (refer the output of switch CLI)
Translating "nd"
% Unknown command or computer name, or unable to find computer address
ESW1#
I have also tried to add space, extra "e" in the last exit command. however still getting the same error
Please let me know if I am missing something/anything.
Environment details:
Python 3.10.6
GNS3 2.2.21
Switch is L3 Multilayer Switch and is IOS router running on local PC as server
PC is connected to GNS3 via loopback interface on PC and cloud on GNS3
Topology on GNS3 : Multi-layer Switch=======L2Switch=====Cloud
The same script is working fine with Cisco Router-7200
Please let me know if any other information is required.
----- TIA
Resolved by encoding it to string
tn.write(str.encode("exit\n"))

uboot fails to execute load cmd from uboot.env

I am working with
U-boot v2021.10
BeagleBone Black rev C
I've created an uboot.env image with mkenvimage tool from file
loadfromsd=load mmc 0:1 0x82000000 /zImage; load mmc 0:1 0x88000000 /am335x-boneblack.dtb
set_bootargs=setenv bootargs console=ttyS0,115200n8 root=/dev/mmcblk0p2 rw rootfstype=ext4 rootwait
uenvcmd=setenv auotload no; run set_bootargs; run loadfromsd; printenv bootargs; bootz 0x82000000 - 0x88000000
The problem is in files loading to memory with load cmd in first line.
Full message from start is:
U-Boot SPL 2021.10 (Oct 14 2021 - 20:41:20 -0700)
Trying to boot from MMC1
U-Boot 2021.10 (Oct 14 2021 - 20:41:20 -0700)
CPU : AM335X-GP rev 2.1
Model: TI AM335x BeagleBone Black
DRAM: 512 MiB
ti_sysc target-module#9000: failed to get fck clock
WDT: Started with servicing (60s timeout)
NAND: nand_base: timeout while waiting for chip to become ready
nand_base: No NAND device found
0 MiB
MMC: ti_sysc target-module#7000: failed to get fck clock
OMAP SD/MMC: 0, OMAP SD/MMC: 1
Loading Environment from FAT... OK
<ethaddr> not set. Validating first E-fuse MAC
Net: eth2: ethernet#4a100000, eth3: usb_ether
=> run uenvcmd
4295456 bytes read in 282 ms (14.5 MiB/s)
'ailed to load '/am335x-boneblack.dtb
bootargs=console=ttyS0,115200n8 root=/dev/mmcblk0p2 rw rootfstype=ext4 rootwait
Kernel image # 0x82000000 [ 0x000000 - 0x418b20 ]
ERROR: Did not find a cmdline Flattened Device Tree
Could not find a valid device tree
Actual error is
=> run uenvcmd
4295456 bytes read in 282 ms (14.5 MiB/s)
'ailed to load '/am335x-boneblack.dtb
P.S. My u-boot fails to recognize ${} substitutions properly, and usage of
console=ttyS0,115200n8
bootpartition=mmcblk0p2
set_bootargs=setenv bootargs console=${console} root=/dev/${bootpartition} rw rootfstype=ext4 rootwait
caused and error
syntax error:
rootfstype=ext4 rootwait0n8
this 0n8 was appended after rootwait and shouldn't be there. So I've written this "straight" file without variables.
Thanks to sawdust for info that carriage return character matters and overrides first letter of error msg - I've got an idea that it also matters for path to file in load cmd, and it matters.
If I use space+\r, NOT just \r - everything works fine.

Beaglebone Black doesn't boots up with the yocto-image

I am working on yocto-project to create images for BBB.I cloned the project git clone -b pyro git://git.yoctoproject.org/poky then initiated the build process. Baked it with bitbake core-image-sato and got the build directory with files.
I created 2 partitions on SD card with 64M for root and rest(15+GB) for boot.
Copied MLO and u-boot-beaglebone.img to the root partition.
Untared the core-image-sato-beaglebone.tar.bz2on root partition and then copied zImage-beaglebone.bin, zImage-am335x-bone.dtb, zImage-am335x-boneblack.dtb under boot partition.
When I tried to boot BBB found that u-boot expects uEnv.txt and get stuck there. The yocto build directory doesn't have any uEnv.txt, so how to write own uEnv.txt ? This is the u-boot prompt.
Hit any key to stop autoboot: 0
gpio: pin 53 (gpio 53) value is 1
mmc0 is current device
micro SD card found
mmc0 is current device
gpio: pin 54 (gpio 54) value is 1
SD/MMC found on device 0
reading uEnv.txt
** Unable to read file uEnv.txt **
gpio: pin 55 (gpio 55) value is 1
** File not found /boot/uImage **
U-Boot#
I added uEnv.txt in root partition with text as
mmcdev=0
mmcpart=1
bootpart=0:1
This time u-boot tries to read a uImage from /boot directory but I have zImage whats this conflict now? How should I resolve it?
SD/MMC found on device 0
reading uEnv.txt
32 bytes read in 4 ms (7.8 KiB/s)
Loaded environment from uEnv.txt
Importing environment from mmc ...
gpio: pin 55 (gpio 55) value is 1
reading /boot/uImage
** Unable to read file /boot/uImage **
U-Boot#
It seems that U-boot is not able to find the uEnv.txt file. Try these configurations. You might need to modify some of the configuration based on your environment.
sudo vim uEnv.txt
kernel_file=zImage
bootdir=/boot
mmcdev=0
mmcpart=2
loadzimage=load mmc ${mmcdev}:${mmcpart} ${loadaddr} ${bootdir}/${kernel_file}
loadfdt=load mmc ${mmcdev}:${mmcpart} ${fdtaddr} ${bootdir}/${fdtfile}
console=ttyO0,115200n8
mmcroot=/dev/mmcblk0p2 ro
mmcrootfstype=ext4 rootwait fixrtc
mmcargs=setenv bootargs console=${console} root=${mmcroot} rootfstype=${mmcrootfstype} ${optargs}
uenvcmd=run loadzimage; run loadfdt; run mmcargs; bootz ${loadaddr} - ${fdtaddr}
Copy zImage and dtb to the boot partition :
sudo cp -v /<path_to_kernel>/arch/arm/boot/zImage <path_to_boot>/boot/
sudo cp -v /<path_to_kernel>/arch/arm/boot/dts/am335x-boneblack.dtb <path_to_boot>/boot/

It possible to boot freertos over network?

some words to my system.
Im work on the Xilinx development-board zc706.
The basic example of freertos are running.
Now the question is: How i can boot the application over network?
A freertos application is a bare-metal approach.
Typically a loader like u-boot is been used, but the examples I find, was only for the linux use-case.
Addition:
With the XMD console its possible to load the u-boot in the memory
XMD% source ps7_init.tcl
XMD% ps7_init
XMD% dow u-boot
Processor started. Type "stop" to stop processor
Processor Stop Condition Unknown
Processor Reset .... DONE
Downloading Program -- u-boot
section, .text: 0x04000000-0x040524d7
section, efi_runtime_text: 0x040524d8-0x040524fb
section, .rodata: 0x04052500-0x040650d1
section, .hash: 0x040650d4-0x040650ff
section, .dtb.init.rodata: 0x04065100-0x0406866f
section, .data: 0x04068670-0x0406b31b
section, .got.plt: 0x0406b31c-0x0406b327
section, efi_runtime_data: 0x0406b328-0x0406b3ff
section, .u_boot_list: 0x0406b400-0x0406c71f
section, .rel.dyn: 0x0406c720-0x04077d5f
section, .bss: 0x0406c720-0x040ad29f
Download Progress..10.20.30.40.50.60.70.80.90.Done
Setting PC with Program Start Address 0x04000000
XMD% run
RUNNING> 0
XMD%
The result ist seen with on a com port:
U-Boot 2017.01-00012-g374a838 (May 29 2017 - 17:55:04 +0200)
Model: Zynq ZC706 Development Board
Board: Xilinx Zynq
I2C: ready
DRAM: ECC disabled 1 GiB
MMC: sdhci#e0100000: 0 (SD)
SF: Detected s25fl128s_64k with page size 512 Bytes, erase size 128 KiB, total 32 MiB
*** Warning - bad CRC, using default environment
In: serial#e0001000
Out: serial#e0001000
Err: serial#e0001000
Model: Zynq ZC706 Development Board
Board: Xilinx Zynq
Net: ZYNQ GEM: e000b000, phyaddr 7, interface rgmii-id
eth0: ethernet#e000b000
Hit any key to stop autoboot: 0
Device: sdhci#e0100000
Manufacturer ID: 27
OEM: 5048
Name: SD16G
Tran Speed: 50000000
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 14.5 GiB
Bus Width: 4-bit
Erase Group Size: 512 Bytes
reading uEnv.txt
** Unable to read file uEnv.txt **
Copying Linux from SD to RAM...
reading uImage
** Unable to read file uImage **
Zynq>
Addition:
I have build the FSBL with the flag FSBL_DEBUG:
(Project -> Properties -> C/C++ Build -> Settings -> ARM gcc compiler -> Symbols)
The I build the bin file only with the boot loader partion and put it on the SD card:
Xilinx Tools->Create Boot Image
Addition:
The problem is, that the SDK needs a file with name u-boot.elf. The extention was not there after the build of u-boot.
So now I have a TFTP-Server running on my host and the u-boot find the uEnv.txt file, but the cmd in this file doesn't run:
How I can setup the u-boot an give the right loadAddress to loadthe freeRTos elf-file?
The tftpboot cmd seems to be:
tftpboot [loadAddress] [bootfilename]
e.g.
tftpboot 0x80400000 vlm-boards/14726/uImage
What is the load address of the zc706 board?
Addition:
The connection an the download with the TFTP-server seems to work:
But after starting with the "go" cmd a reset occur.
Zynq> setenv ipaddr 192.168.150.101
Zynq> setenv netmask 255.255.255.0
Zynq> setenv gatewayip 192.168.150.1
Zynq> serverip=192.168.150.100
Zynq> ping 192.168.150.100
Using ethernet#e000b000 device
host 192.168.150.100 is alive
Zynq> tftpboot 0x8000 FreeRTOS_HelloWorld.elf
Using ethernet#e000b000 device
TFTP from server 192.168.150.100; our IP address is 192.168.150.101
Filename 'FreeRTOS_HelloWorld.elf'.
Load address: 0x8000
Loading: ###############
2.8 MiB/s
done
Bytes transferred = 205675 (3236b hex)
Zynq> go 0x8000
## Starting application at 0x00008000 ...
undefined instruction
pc : [<0000fa60>] lr : [<3ff443c4>]
reloc pc : [<c40cda60>] lr : [<040023c4>]
sp : 3eb20cf4 ip : 0000001c fp : 3ff4437c
r10: 3eb1f9b0 r9 : 3eb21ee8 r8 : 3ffaef30
r7 : 00000000 r6 : 00008000 r5 : 00000002 r4 : 3eb2f9b4
r3 : 00008000 r2 : 3eb2f9b4 r1 : 3eb2f9b4 r0 : 00001084
Flags: nZcv IRQs off FIQs off Mode SVC_32
Resetting CPU ...
resetting ...
Thx in advance
The solution is:
The Xilinx SDK supply as an output an Elf-File, which the u-boot understands:
tftpboot 0x000000 FreeRTOS_ZC706_HelloWorld.elf
bootelf 0x0
Thanks
tftpboot 0x0 hello.efl; bootelf 0x0;
works in Uboot 2019.2 version and FreeRTOS.elf.
For the other core, you need to convert it to bin format using arm-none-eabi-objcopy -O binary hello.elf hello.bin. tftpboot it under the correct memory postion. And fire it up in the CPU0 code.

What is the correct address for loading spiffsimg file

I have used spiffsimg to create a single file containing multiple lua files:
# ./spiffsimg -f lua.img -c 262144 -r lua.script
f 4227 init.lua
f 413 cfg.lua
f 2233 setupWifi.lua
f 7498 configServer.lua
f 558 cfgForm.htm
f 4255 setupConfig.lua
f 14192 main.lua
#
I then use esptool.py to flash the NodeMCU firmware and the file containing the lua files to the esp8266 (NodeMCU dev kit):
c:\esptool-master>c:\Python27\python esptool.py -p COM7 write_flash -fs 32m -fm dio 0x00000 nodemcu-dev-9-modules-2016-07-18-12-06-36-integer.bin 0x78000 lua.img
esptool.py v1.0.2-dev
Connecting...
Running Cesanta flasher stub...
Flash params set to 0x0240
Writing 446464 # 0x0... 446464 (100 %)
Wrote 446464 bytes at 0x0 in 38.9 seconds (91.9 kbit/s)...
Writing 262144 # 0x78000... 262144 (100 %)
Wrote 262144 bytes at 0x78000 in 22.8 seconds (91.9 kbit/s)...
Leaving...
I then run ESPLorer to check the status and get:
PORT OPEN 115200
Communication with MCU..Got answer! AutoDetect firmware...
Can't autodetect firmware, because proper answer not received.
NodeMCU custom build by frightanic.com
branch: dev
commit: b21b3e08aad633ccfd5fd29066400a06bb699ae2
SSL: true
modules: file,gpio,http,net,node,rtctime,tmr,uart,wifi
build built on: 2016-07-18 12:05
powered by Lua 5.1.4 on SDK 1.5.4(baaeaebb)
lua: cannot open init.lua
>
----------------------------
No files found.
----------------------------
>
Total : 3455015 bytes
Used : 0 bytes
Remain: 3455015 bytes
The NodeMCU firmware flashed correctly, but the lua files can't be located.
I have tried flashing to other locations (0x84000, 0x7c000), but I am just guessing at these locations based on reading threads on github.
I used the NodeMCU file.fscfg() routine to get the flash address and size. If I only flash the NodeMCU firmware I get the following:
print (file.fscfg())
524288 3653632
534288 is 0x80000, so I tried flashing only the spiffsimg file (lua.img) to 0x8000, then ran the same print statement and got:
print (file.fscfg())
786432 3391488
The flash address incremented by the exact number of bytes in the lua.img - which I don't understand, why would the flash address change? Is the first number returned by file.fscfg not the starting flash address, but the ending flash address?
What is the correct address for flashing an image file, contain lua files, that was created by spiffsimg?
The version of spiffsimg found here will provide the correct address for flashing an image file that contains lua files.
Do not use this version of spiffsimg as it is out of date.
To install the spiffsimg utility, you need to download and install the entire nodemcu-firmware package (into a linux environment, use make to install - note: make on my debian linux box generated an error, but i was able to go to the ../tools/spiffsimg subdirectory and run make on the Makefile found in that directory to create the utility).
The spiffsimg instructions found here are quite clear, with one exception: the file name you specify, with the -f parameter, needs to include the characters %x. The %x will be replaced with the address that the image file should be flashed to.
For example, the command
spiffsimage -f %x-luaFiles.img -S 4MB -U 465783 -r lua.script
will create a file, in the local directory, with a name like: 80000-luaFiles.img. Which means you should install that image file at address 0x80000 on the ESP8266.
I've never done that myself but I'm reasonably confident the correct answer can be extracted from the docs.
-f specifies the filename for the disk image. '%x' will be replaced
by the calculated offset of the file system.
And a bit further down
The disk image file is placed into the bin directory and it is named
0x<offset>-<size>.bin where the offset is the location where it
should be flashed, and the size is the size of the flash part.
However, there's a slight mismatch between the two statements. We may have a bug in the docs. If "'%x' will be replaced..." then I'd expected the final name won't contain 0x anymore.
Furthermore, it is possible to define a fixed SPIFFS position when you build the firmware.
#define SPIFFS_FIXED_LOCATION 0x100000
This specifies that the SPIFFS filesystem starts at 1Mb from the start of the flash. Unless
otherwise specified, it will run to the end of the flash (excluding
the 16k of space reserved by the SDK).

Resources