Skip to content

Environment

gtxaspec edited this page Apr 1, 2024 · 6 revisions

Sample Default Environment Settings

Thingino # printenv
baseaddr=0x80600000
baudrate=115200
bootargs=mem=${osmem} rmem=${rmem} console=${serialport},${baudrate}n8 panic=${panic_timeout} root=/dev/mtdblock3 rootfstype=squashfs init=/init mtdparts=jz_sfc:256k(boot),64k(env),${kern_size}(kernel),${rootfs_size}(rootfs),-(rootfs_data)${update}
bootcmd=sf probe;sq probe;setenv setargs setenv bootargs ${bootargs};run setargs;sf read ${baseaddr} 0x50000 ${kern_len};bootm ${baseaddr};
bootdelay=1
disable_eth=true
disable_sd=true
enable_updates=false
ethact=Jz4775-9161
ethaddr=26:79:53:9c:0e:82
gatewayip=192.168.1.1
gpio_button=6
gpio_default=62O
gpio_default_net=61o 48o
gpio_ir850=60
gpio_ir940=58
gpio_ircut=49 50
gpio_mmc_cd=48
gpio_motor_h=52 53 57 51
gpio_motor_v=59 61 62 63
gpio_speaker=63O
hostname=indus
ipaddr=192.168.1.10
loads_echo=1
netmask=255.255.255.0
osmem=40M
panic_timeout=10
restore=n
rmem=24M@0x2800000
sensor=gc2083
serialport=ttyS1
serverip=192.168.1.254
soc=t31
stderr=serial
stdin=serial
stdout=serial
totalmem=64M
wlanmac=26:79:53:9c:0e:83

Saving Environment Variables

After setting or changing any environment variables, do not forget to save your changes to ensure they persist across reboots. Use the saveenv command to save the U-Boot environment variables to non-volatile storage:

saveenv

This step is crucial for maintaining your desired boot configuration between device restarts.


Environment Variable Import from SD Card

U-Boot can import environment variables from an SD card by utilizing a file named uEnv.txt placed at the root of the SD card. This file should contain variables and their corresponding values in a simple key-value format. Each line of the uEnv.txt file specifies one environment variable and its value, adhering to the structure:

variable_name=value

For example, to set the bootdelay and ipaddr environment variables, your uEnv.txt might look like this:

bootdelay=10
ipaddr=192.168.1.100

When U-Boot starts, it reads this file and applies the specified environment variables, allowing for dynamic configuration based on the contents of the SD card.


Automatic Boot Script Processing

In addition to environment variable import, U-Boot supports automatic execution of a boot script named boot.scr. This file should also be placed at the root of the SD card. The boot.scr is a binary file, typically created from a human-readable script using tools like mkimage from the U-Boot toolset.

This boot script can contain a series of U-Boot commands to be executed sequentially during the boot process. It enables automated, custom boot actions without the need for manual intervention each time the system boots.

To use this feature, prepare your boot commands in a script, convert it to the boot.scr format using mkimage, and place the resulting file on the SD card. Upon booting, U-Boot will automatically detect and execute the commands in boot.scr.

Inserting an SD card with properly configured uEnv.txt and/or boot.scr files allows U-Boot to adapt its behavior according to these custom settings during the boot process.


Factory Reset

For scenarios requiring a configuration reset during boot, such as reverting to default settings or troubleshooting, U-Boot can be configured to respond to a physical button press.

To enable configuration reset via a physical button:

  • Define a GPIO variable named gpio_button in your U-Boot environment, assigning it the GPIO number corresponding to the physical button on your device, for example: gpio_button=14.

Reset Procedure:

  1. Ensure the device is powered off.
  2. Press and hold the designated reset button.
  3. While holding the button, power on the device.
  4. Continue to hold the button for a few seconds after power is applied.
  5. Release the button.

This action triggers U-Boot to clear all configuration variables stored in the environment, reverting them to their default settings. Additionally, it will format the overlay JFFS2 partition, effectively resetting the device to a clean state. This process provides a straightforward method for system recovery and initial setup scenarios.