saveenv is not working from uuu script

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

saveenv is not working from uuu script

5,610 Views
vinothkumars
Senior Contributor IV

Hi All,

saveenv is not working from uuu script. Is there any configuration missing. I able to do from uboot console but not from script.

FB: ucmd saveenv

 

 

Regards,
Vinothkumar Sekar
Tags (2)
0 Kudos
19 Replies

3,000 Views
MicMoba
Contributor V

Yes I was succeeded. The secret was to init and reload the environment after setting the location.

This example works for me (uboot v2021.04)

 

typedef enum ESource{
    SOURCE_AUTO = 0,
    SOURCE_SD_CARD,
    SOURCE_MMC,
}ESource;

static ESource env_location = SOURCE_AUTO;

void env_set_inited(enum env_location location)
{
    /*
     * We're using a 32-bits bitmask stored in gd (env_has_init)
     * using the above enum value as the bit index. We need to
     * make sure that we're not overflowing it.
     */
    //BUILD_BUG_ON(ARRAY_SIZE(env_locations) > BITS_PER_LONG);
    debug("%s: init environment on loc %d before: 0x%lx\n", __func__, location, gd->env_has_init & BIT(location));
    gd->env_has_init |= BIT(location);
    debug("%s: init environment after: 0x%lx\n", __func__, gd->env_has_init & BIT(location));
}


int do_set_env_location(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
{
    env_location = SOURCE_MMC;
    env_set_inited(ENVL_MMC);
    env_load();
    debug("%s: set environment location to SD card\n", __func__);
    return 0;
}

 

 After that you have access to the environment variables. You can set and save them.

 

2,978 Views
gnulux
Contributor II

Hi, 

You mean i have to patch U-boot first ? 

Regards.

0 Kudos

4,603 Views
MicMoba
Contributor V

Okay, I have to reopen this case

I still have the same problem. When I run u-boot over UUU tool I can't access to the environment stored in my emmc.

If the u-boot detects that it is startet over USB and it is using a default environment. How can I get access to the environment.

Following situation:

Start device (i.MX8MP) in serial-download-mode and connect PC over USB

Load image to emmc over UUU-Tool

sudo ./uuu -b emmc_all imx-boot image.wic

The redundant environment is located at:

CONFIG_ENV_SIZE=0x10000
CONFIG_ENV_OFFSET=0x3C0000
CONFIG_ENV_OFFSET_REDUND=0x3E0000

Now I want to set an environment variable over FastBoot protocol and save the environment on the emmc.

Afterwards set boot-options to boot from emmc. Now the u-boot should work with the environment variable that I have set before over UUU-Tool and FB.

 

0 Kudos

3,030 Views
gnulux
Contributor II

Hi, 

Did you succeed to change U-boot parameter with UUU ? 

K.regards

0 Kudos

5,541 Views
dewayne_gibson
Contributor II

Hello @ Vinothkumar:

I provided you the UUU user guide in the earlier post. 

You need only change the one line below to call the proper uuu FB: download -f imx8---_mek.dtb:

To talk with fastboot:

First Step: boot linux kernel using these commands
uuu FB: ucmd setenv fastboot_buffer ${loadaddr}
uuu FB: download -f Image
uuu FB: ucmd setenv fastboot_buffer ${fdt_addr}
uuu FB: download -f imx8qxp_mek.dtb
uuu FB: acmd booti ${loadaddr} - ${fdt_addr}
Extended environment for fastboot
fastboot_buffer Image download address
fastboot_bytes reflect previous download image byte size

Last Step: write image to emmc
uuu FB: flash -raw2sparse all <image file>

You will not be able to save the commands that you script in UUU. UUU is not an editor utility.  If you want to save the script commands you are using, create and save to a text file or USE the XML2 method instead of UUU commands.

 

Regards and Good Luck!

DeWayne

0 Kudos

5,603 Views
dewayne_gibson
Contributor II

Hello @vinothkumars

Yes sir you are missing rest of the command line requirements.  See below and let me know if this helps:

To Talk with fastboot, boot linux kernel:

uuu FB: ucmd setenv fastboot_buffer ${loadaddr}
uuu FB: download -f Image
uuu FB: ucmd setenv fastboot_buffer ${fdt_addr}
uuu FB: download -f imx8qxp_mek.dtb
uuu FB: acmd booti ${loadaddr} - ${fdt_addr}

Good Luck!

DeWayne

0 Kudos

5,571 Views
vinothkumars
Senior Contributor IV

Thank you @dewayne_gibson for the reply.

 

Will you please share the full script. I am unable to save from uuu script.

1:13>Start Cmd:FB: ucmd mmc partconf ${emmc_dev} ${emmc_ack} 1 0
1:13>Okay
1:13>Start Cmd:FB: ucmd printenv
1:13>Okay
1:13>Start Cmd:FB: ucmd saveenv
1:13>Fail

 

 

Regards,
Vinothkumar Sekar
0 Kudos

5,226 Views
MicMoba
Contributor V

Hi,
is there a solution? I have the same issue. I am able to flash my emmc and I can call all uboot commands but saveenv is not working.

Flash of emmc:
uuu.exe -v -b emmc_all uboot.bin image.wic

After successful flashing I want to reset and save my environment

uuu.exe FB: ucmd env default -a
>Okay

uuu.exe FB: ucmd saveenv
>Error:

Unfortunately uuu tool does not print out any error. The serial console prints also nothing.

In general the serial console prints two errors:

## Error: Can't overwrite "serial#"
## Error inserting "serial#" variable, errno=1
Detect USB boot. Will enter fastboot mode!
request 00000000bdf3e1c0 was not queued to ep1in-bulk

But I don't know if this has something to do with the saveenv issue.

The reason why I want to set my environment to default and save it is because I use a redundant environment and only with a saveenv it will be stored to flash. If it is not stored to flash I wouldn't be able to use fw_printenv and fw_setenv out of rootfs.

Is there another possibility to save the environment initialy?

0 Kudos

2,890 Views
BiyongSUN
NXP Employee
NXP Employee

What you can do with uboot command through uart, you can do the exactly the same through uuu. 

The difference I had told two years ago. 

"

The u-boot has mmcautodetect, it can  detect boot from  the emmc(for example) and make the u-boot environment save to that device regardless the u-boot environment.

But boot from usb, uboot will think it is not from emmc or sd or any usdhc interface. 

"

 

 

When you use "uuu -v FB: ucmd env default -a", the mmcdev will become 1.

That is why you saveenv will get fail. 

uuu -b spl imx-boot-imx8mm-lpddr4-evk-sd.bin-flash_evk

uuu -v FB: ucmd env default -a  
uuu -v FB: ucmd print mmcdev
uuu -v FB: ucmd saveenv
uuu -v FB: ucmd print emmc_dev
uuu -v FB: ucmd setenv mmcdev ${emmc_dev}
uuu -v FB: ucmd saveenv

 


## Checking Image at 43800000 ...
Unknown image format!
Run fastboot ...
## Resetting to default environment
Detect USB boot. Will enter fastboot mode!
mmcdev=1
Detect USB boot. Will enter fastboot mode!
Saving Environment to MMC... MMC: no card present
No block device
Failed (1) fastboot mode!
Detect USB boot. Will enter fastboot mode!
Saving Environment to MMC... Writing to MMC(2)... OK
Detect USB boot. Will enter fastboot mode!

 

Untitled.png

 

0 Kudos

5,217 Views
BiyongSUN
NXP Employee
NXP Employee

It is very simple reason.

 

The u-boot has mmcautodetect, it can  detect boot from  the emmc(for example) and make the u-boot environment save to that device regardless the u-boot environment.

But boot from usb, uboot will think it is not from emmc or sd or any usdhc interface. 

so the mmcdev=1, not match the hardware.  

even you don't issue the command uuu -v FB: ucmd env default -a. you could not saveenv, either. 

You have to manually set the mmc device. 

uuu -v FB: ucmd setenv mmcdev ${emmc_dev}

uuu -v FB: ucmd saveenv

 

By the way, uuu flash use the emmc_dev and sd_dev to do flash.

 

 

 

 

 

 

 

 

 

0 Kudos

2,897 Views
BiyongSUN
NXP Employee
NXP Employee

I had provided the command two years ago. 

Today, I have to give a demo.

Using uuu to send uboot command is exactly the same as you using uart to type uboot command to saveenv.  

But you need to make sure the configuration. Because there are default settings. Or you may lose some settings. 

Once you get error, please check such as emmc dev is correct or not. 

HW: i.MX8MM EVK

SW: LF_v5.15.71-2.2.0_images_IMX8MMEVK

uuu_setenv.uuu(uuu_setenv.zip attached):

uuu_version 1.2.39

# This command will be run when i.MX6/7 i.MX8MM, i.MX8MQ
SDP: boot -f imx-boot-imx8mmevk-sd.bin-flash_evk

# This command will be run when ROM support stream mode
# i.MX8QXP, i.MX8QM
SDPS: boot -f imx-boot-imx8mmevk-sd.bin-flash_evk

# These commands will be run when use SPL and will be skipped if no spl
# SDPU will be deprecated. please use SDPV instead of SDPU
# {
SDPU: delay 1000
SDPU: write -f imx-boot-imx8mmevk-sd.bin-flash_evk -offset 0x57c00
SDPU: jump
# }

# These commands will be run when use SPL and will be skipped if no spl
# if (SPL support SDPV)
# {
SDPV: delay 1000
SDPV: write -f imx-boot-imx8mmevk-sd.bin-flash_evk -skipspl
SDPV: jump
# }


FB: ucmd setenv mmcdev ${emmc_dev}
FB: ucmd setenv ABC test
FB: ucmd saveenv
FB: ucmd setenv mmcdev 1
FB: ucmd saveenv
FB: done

 

Log:

uuu log

dev 2 is emmc and dev 1 is sdcard/tf card.

The script saves the env to the emmc first. Then it switches to the sdcard and save again.

 

Untitled.png

 

boot and check 

Untitled1.png

 

 

0 Kudos

2,867 Views
gnulux
Contributor II

Hi , 

Sorry to bother, you're right and i understood well the case. Except that on my board (Not EVK) I have another behavior i would like to fix. 

With your uuu_setenv , i have the error :  Saving Environment to nowhere... not possible

uuu_version 1.2.39

# This command will be run when i.MX6/7 i.MX8MM, i.MX8MQ
SDP: boot -f LEC-IMX8MP-2G-IPi-SMARC-PLUS-UUU-TOOL_20220309

# This command will be run when ROM support stream mode
# i.MX8QXP, i.MX8QM
SDPS: boot -f LEC-IMX8MP-2G-IPi-SMARC-PLUS-UUU-TOOL_20220309

# These commands will be run when use SPL and will be skipped if no spl
# SDPU will be deprecated. please use SDPV instead of SDPU
# {
SDPU: delay 1000
SDPU: write -f LEC-IMX8MP-2G-IPi-SMARC-PLUS-UUU-TOOL_20220309 -offset 0x57c00
SDPU: jump
# }

# These commands will be run when use SPL and will be skipped if no spl
# if (SPL support SDPV)
# {
SDPV: delay 1000
SDPV: write -f LEC-IMX8MP-2G-IPi-SMARC-PLUS-UUU-TOOL_20220309 -skipspl
SDPV: jump
# }


FB: ucmd setenv fastboot mmc
FB: ucmd setenv mmcdev ${emmc_dev}
FB: ucmd setenv ABC test
FB: ucmd saveenv
FB: ucmd setenv mmcdev  1
FB: ucmd saveenv
FB: done 

 

UUU output : 

1:13>Start Cmd:FB: ucmd setenv fastboot mmc
1:13>Okay (0.01s)
1:13>Start Cmd:FB: ucmd setenv mmcdev ${emmc_dev}
1:13>Okay (0.01s)
1:13>Start Cmd:FB: ucmd setenv ABC test
1:13>Okay (0.01s)
1:13>Start Cmd:FB: ucmd saveenv
1:13>Fail (0.011s) 

I have checked with command lines , and FB enable emmc 2 . I can flash fat and rootfs without problem. But only the savenv failed (trying to set mac addresses during flash)   

Console output :

U-Boot 2021.04-lf_v2021.04+g263b27e076 (Nov 22 2021 - 01:39:23 +0000)

alloc space exhausted
CPU:   i.MX8MP[8] rev1.1 at 1200 MHz
Reset cause: POR
Model: Adlink lec-imx8mp LPDDR4 SOM
DRAM:  2 GiB
MMC:   FSL_SDHC: 1, FSL_SDHC: 2
[*]-Video Link 0probe video device failed, ret -2

        [0] lcd-controller@32e80000, video
        [1] mipi_dsi@32e60000, video_bridge
In:    serial
Out:   serial
Err:   serial

 BuildInfo:
  - ATF 5782363

MMC: no card present
Detect USB boot. Will enter fastboot mode!
Net:   
Warning: ethernet@30be0000 (eth0) using random MAC address - fa:22:46:75:18:a5
eth0: ethernet@30be0000
Fastboot: Normal
Boot from USB for mfgtools
*** Warning - Use default environment for                                mfgtools
, using default environment

Run bootcmd_mfg: run mfgtool_args;if iminfo ${initrd_addr}; then if test ${tee} = yes; then bootm ${tee_addr} ${initrd_addr} ${fdt_addr}; e;
Hit any key to stop autoboot:  0 

## Checking Image at 43800000 ...
Unknown image format!
Run fastboot ...
Unknown command 'setenc' - try 'help'
(NULL udevice *): request 00000000bcf23d00 was not queued to ep1in-bulk
Detect USB boot. Will enter fastboot mode!
(NULL udevice *): request 00000000bcf23d00 was not queued to ep1in-bulk
Detect USB boot. Will enter fastboot mode!
(NULL udevice *): request 00000000bcf23d00 was not queued to ep1in-bulk
Detect USB boot. Will enter fastboot mode!
(NULL udevice *): request 00000000bcf23d00 was not queued to ep1in-bulk
Saving Environment to nowhere... not possible
(NULL udevice *): request 00000000bcf23d00 was not queued to ep1in-bulk

 

I'm wondering if it is not related to CONFIG_ENV_IS_NOWHERE=y in U-Boot ? 

Regards

 

 

0 Kudos

2,843 Views
BiyongSUN
NXP Employee
NXP Employee

 

You can also create a scard mirror with env already set. 

--- u-boot/arch/arm/mach-imx/imx8m/soc.c.orig   2023-08-08 19:06:07.627236934 +0800
+++ u-boot/arch/arm/mach-imx/imx8m/soc.c        2023-08-08 19:07:15.708770073 +0800
@@ -1713,6 +1713,9 @@ enum env_location env_get_location(enum
                return ENVL_UNKNOWN;

        switch (dev) {
+       case USB_BOOT:
+       case USB2_BOOT:
+               return ENVL_MMC;
        case QSPI_BOOT:
                if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
                        return ENVL_SPI_FLASH;

 

0 Kudos

2,832 Views
BiyongSUN
NXP Employee
NXP Employee

The alternative way. I think it is the better way to set the u-boot environment into sdcard mirror. 

It is better, because this way can be used for mass production.

The idea is to use fw_setenv to set the sdcard mirror as the operation on a real emmc/sdcard. 

Here is the demo.

I add test=ABCD for test purpose. 

And use fw_printenv to check and use hexdump to double confirm it.

The uboot env is already written into sdcard mirror(imx-image-multimedia-imx8mpevk.wic). 

Those operations are on the host x86/x64 PC.

 

 

 ./fw_setenv -c fw_env.config -f u-boot-initial-env
Environment WRONG, copy 0
Cannot read environment, using default

 ./fw_printenv -c fw_env.config
Environment OK, copy 0
 jh_root_dtb=imx8mp-evk-root.dtb
 loadbootscript=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${bsp_script};
 mmc_boot=if mmc dev ${devnum}; then devtype=mmc; run scan_dev_for_boot_part; fi
arch=arm
baudrate=115200
.........
........
........
splashimage=0x50000000
test=ABCD
usb_boot=usb start; if usb dev ${devnum}; then devtype=usb; run scan_dev_for_boot_part; fi
vendor=freescale

 
 hexdump -s 0x400000 -n 100 -C imx-image-multimedia-imx8mpevk.wic
            
00400000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

hexdump -s 0x400000 -n 10000 -C imx-image-multimedia-imx8mpevk.wic
00400000  5f a4 9b 97 20 6a 68 5f  72 6f 6f 74 5f 64 74 62  |_... jh_root_dtb|
00400010  3d 69 6d 78 38 6d 70 2d  65 76 6b 2d 72 6f 6f 74  |=imx8mp-evk-root|
00400020  2e 64 74 62 00 20 6c 6f  61 64 62 6f 6f 74 73 63  |.dtb. loadbootsc|
00400030  72 69 70 74 3d 66 61 74  6c 6f 61 64 20 6d 6d 63  |ript=fatload mmc|
00400040  20 24 7b 6d 6d 63 64 65  76 7d 3a 24 7b 6d 6d 63  | ${mmcdev}:${mmc|
00400050  70 61 72 74 7d 20 24 7b  6c 6f 61 64 61 64 64 72  |part} ${loadaddr|
00400060  7d 20 24 7b 62 73 70 5f  73 63 72 69 70 74 7d 3b  |} ${bsp_script};|
00400070  00 20 6d 6d 63 5f 62 6f  6f 74 3d 69 66 20 6d 6d  |. mmc_boot=if mm|



00401390  76 3d 31 00 73 6f 63 3d  69 6d 78 38 6d 00 73 70  |v=1.soc=imx8m.sp|
004013a0  6c 61 73 68 69 6d 61 67  65 3d 30 78 35 30 30 30  |lashimage=0x5000|
004013b0  30 30 30 30 00 74 65 73  74 3d 41 42 43 44 00 75  |0000.test=ABCD.u|
004013c0  73 62 5f 62 6f 6f 74 3d  75 73 62 20 73 74 61 72  |sb_boot=usb star|
004013d0  74 3b 20 69 66 20 75 73  62 20 64 65 76 20 24 7b  |t; if usb dev ${|
004013e0  64 65 76 6e 75 6d 7d 3b  20 74 68 65 6e 20 64 65  |devnum}; then de|

 

 

Then,

I flash the sdcard mirror into i.MX8MP evk  board  emmc to check

 

 

uuu -b emmc_all imx-boot-imx8mp-lpddr4-evk-sd.bin-flash_evk  imx-image-multimedia-imx8mpevk.wic

 

 

 

The first time boot, the env is already there.

Untitled.png

How to:

a. fw_setenv/fw_printenv:

    https://github.com/sbabic/libubootenv.git

     Note: Please do not use uboot fw_setenv/fw_printenv

              Compile it on the host x86/x64 PC. It is used on host.  

b. u-boot-initial-env

    Under uboot, make u-boot-initial-env

    Note: Yocto deploys u-boot-initial-env by default 

c. fw_env.config

 

 

imx-image-multimedia-imx8mpevk.wic 0x400000 0x4000

 

 

 

  0x400000 0x4000  are from uboot-imx\configs\imx8mp_evk_defconfig

 

 

CONFIG_ENV_SIZE=0x4000
CONFIG_ENV_OFFSET=0x400000

 

Now, you can run 

./fw_setenv -c fw_env.config -f u-boot-initial-env

 

 

 

2,802 Views
gnulux
Contributor II

Hi BiyongSUN

It works fine. Many thanks

Indeed I will use this method for mass production instead of setenv from UUU. 

Regards

0 Kudos

2,773 Views
BiyongSUN
NXP Employee
NXP Employee

It is great to hear it works fine on your side. 

That makes me think file it into my collection, more people can see it and use it. 

u-boot environment preset for sdcard mirror
https://community.nxp.com/t5/i-MX-Processors-Knowledge-Base/u-boot-environment-preset-for-sdcard-mir...

 

i.MX Development Miscellanea(i.MX 开发杂记) - NXP Community

 

0 Kudos

5,211 Views
MicMoba
Contributor V

Hi BiyongSUN,

thanks for your reply but this doesn't work for me. I set the mmcdev to my emmc_dev but the saveenv command doesn't work either.

0 Kudos

5,221 Views
MicMoba
Contributor V

Okay, I think I know why saveenv doesn't work.

This prints the serial console after I load the bootloade into RAM and start in fastboot mode:
...
Loading Environment from nowhere... OK
In:    serial
Out:   serial
Err:   serial

BuildInfo:
 - ATF f1d7187
 - U-Boot 2020.04

Detect USB boot. Will enter fastboot mode!
Net:    
Warning: ethernet@30bf0000 using MAC address from ROM
eth1: ethernet@30bf0000 [PRIME]
Fastboot: Normal
Boot from USB for mfgtools
*** Warning - Use default environment for                                mfgtools
, using default environment

Because of the Serial Download Mode the environment is nowhere. And then it makes sense that the saveenv command do nothing

 

0 Kudos

5,560 Views
AldoG
NXP TechSupport
NXP TechSupport

Hello,

Does uboot output something?
Also, please share the script you're using

Regards,
Aldo.

0 Kudos