Not able to run fw_printenv in platform.sh and fw_setenv in common.sh while doing firmware upgrade from openwrt GUI

Hi,
Openwrt by default have single partition and while doing firmware upgrade from openwrt GUI then it would upgrade default partition and boot from the same partition.
But In my case, i have 2 partition(primary and secondary). what my use case is when we do firmware upgrade from openwrt GUI then it should upgrade the secondary partition and boot from the updated partition i.e., secondary partition or vice versa.
So we have one u-boot arguments i.e., primary whose value would be 0 or 1 i.e., 0 for primary partition and 1 for secondary partition. i want to read this u-boot argument from the script paltform.sh which is running on doing firmware upgrade from GUI using command fw_printenv primary but i am not able to run this command from platform.sh script and it shows the following error:
fw_printenv
ash: fw_printenv: not found
Please help me in this i am stuck over here.

or is there any other way to do firmware upgrade while having 2 partitions in board?

fw_printenv is only included in targets that require it.
If you are experimenting with a new target or modifying another, you will need to install it (not sure if that is possible) or recompile to include it.

I believe the relevant config line is
CONFIG_DEFAULT_uboot-envtools=y

Like e.g. mvebu, which I already pointed out to you in your LuCI ticket

Hi all,

Thank you for your reply.
I have already enabled this env tool(CONFIG_DEFAULT_uboot-envtools=y) and working fine when board is properly boot-up but when i add these commands in platform.sh and common.sh which is running when doing firmware upgrade then only these commands are not getting executed and showing error (error: not found).
If u want then i can share platform.sh and common.sh file with you.
If u can check platform.sh and common.sh file please check because i am stuck over here and not able to do upgrade in alternate partition.
Please help.
Thank a lot in advance.

Thank you

Regard
Sakshi

You need to make sure that it's available during the sysupgrade:

1 Like

And while we are at it, you’d need to supppy a valid uboot_env config.
Continuing the mvebu example;
https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob;f=package/boot/uboot-envtools/files/mvebu;h=7d16a59666b0b145f9b7f1e4e80fbc9cf8eb7699;hb=bfbdeeb3de3da31f7e5f9bd429e079c2d839644a

Hi @slh

i have added the thing which u mentioned in comments in platform.sh file
RAMFS_COPY_BIN='fw_printenv fw_setenv'
RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock'
and also try to do firmware upgarde using the following command:
sysupgrade -v /tmp/firmware.img
But still i am getting same error which is shown below:

**+ fw_printenv primary**
**ash: fw_printenv: not found**
**+ cut -b 9**
**+ check=**
**+ echo !!!!*********** check is  *************!!!!!!!!!!**
**!!!!*********** check is  *************!!!!!!!!!!**

Also uploading file:

#                          
# Copyright (C) 2011 OpenWrt.org               
#  
USE_REFRESH=1
 set -x
. /lib/ipq806x.sh
. /lib/upgrade/common.sh
                    
RAMFS_COPY_BIN='fw_printenv fw_setenv'
RAMFS_COPY_DATA=/lib/ipq806x.sh
RAMFS_COPY_BIN="/usr/bin/dumpimage /bin/mktemp /usr/sbin/mkfs.ubifs
        /usr/sbin/ubiattach /usr/sbin/ubidetach /usr/sbin/ubiformat /usr/sbin/ubimkvol
        /usr/sbin/ubiupdatevol /usr/bin/basename /bin/rm /usr/bin/find
        /usr/sbin/mkfs.ext4 /etc/fw_env.config /var/lock/fw_printenv.lock"     
do_flash_mtd() {        
        local bin=$1
        local mtdname=$2              
        local append=""        
        echo "the bin is $1" > /dev/console                        
        echo "The mtdname is $2" > /dev/console                                       
                                                                      
        local mtdpart=$(grep "\"${mtdname}\"" /proc/mtd | awk -F: '{print $1}')
        echo "mtdpart is $mtdpart" > /dev/console
        local pgsz=$(cat /sys/class/mtd/${mtdpart}/writesize)
        echo "pgsz is $pgsz" > /dev/console
        check=$(fw_printenv primary | cut -b 9)
        echo "!!!!*********** check is $check *************!!!!!!!!!!" > /dev/console
        echo "Praty primary is $check" > /dev/console     
if [ $check == '1' ]                         
then
        echo "in if ****successfull*** primary is $check" > /dev/console
        [ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 -a "$2" == "rootfs" ] && append="-j $CONF_TAR"
else                
        echo "in else ****successfull*** primary is $check" > /dev/console
        [ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 -a "$2" == "rootfs_1" ] && append="-j $CONF_TAR"
fi

        dd if=/tmp/${bin}.bin bs=${pgsz} conv=sync | mtd $append write - -e "/dev/${mtdpart}" "/dev/${mtdpart}"
}

And my fw_printenv prints the following u-boot arguments:

root@HFCI:/# fw_printenv 
TRAPS_STATUS=225
baudrate=115200
bootcmd=bootipq
bootdelay=2
primary=0
serverip=192.168.1.15
stderr=serial
stdin=serial
stdout=serial

Please help me out in this

Thanks in advance

Regards
Sakshi

Hi @lantis1008

i have checked the things u mentioned in comments using example mvedu.
and all the things are present in our file.
Also we are giving valid uboot_env config but still facing same problem.

Can u have another method to resolve this?
Thanks in advance

Regards
Sakshi

Hi all,

Please look into this issue. It would be great help from you all.
I am really stuck over here.
Thanks in advance

Regards
Sakshi

If fw_printenv works in the normal shell, but not during sysupgrade, then logic says it has not been copied across to the RAMFS correctly.

Perhaps you should continue your investigations around the function switch_to_ramfs()
https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob;f=package/base-files/files/lib/upgrade/stage2;hb=16c712501cdcb10f333f4abc027a0dcdb8f8101b#l46

Hi @lantis1008

I have added
"install_bin /usr/sbin/fw_printenv
install_bin /usr/sbin/fw_setenv</>"
in common.sh file under function

run_ramfs() { # <command> [...]                                                  
        install_bin /bin/busybox /bin/ash /bin/sh /bin/mount /bin/umount        \
                /sbin/pivot_root /usr/bin/wget /sbin/reboot /bin/sync /bin/dd   \
                /bin/grep /bin/cp /bin/mv /bin/tar /usr/bin/md5sum "/usr/bin/[" \
                /bin/dd /bin/vi /bin/ls /bin/cat /usr/bin/awk /usr/bin/hexdump  \
                /bin/sleep /bin/zcat /usr/bin/bzcat /usr/bin/printf /usr/bin/wc \
                /bin/cut /usr/bin/printf /bin/sync /bin/mkdir /bin/rmdir        \
                /bin/rm /usr/bin/basename /bin/kill /bin/chmod                   
                                                                                 
        install_bin /sbin/mtd                                                    
        install_bin /sbin/mount_root                                             
        install_bin /sbin/snapshot                                               
        install_bin /sbin/snapshot_tool                                          
        install_bin /usr/sbin/ubiupdatevol                                                            
        install_bin /usr/sbin/ubiattach                                                               
        install_bin /usr/sbin/ubiblock                                                                
        install_bin /usr/sbin/ubiformat                                                               
        install_bin /usr/sbin/ubidetach                                                               
        install_bin /usr/sbin/ubirsvol                                                                
        install_bin /usr/sbin/fw_printenv                                                             
        install_bin /usr/sbin/fw_setenv                                                                
        for file in $RAMFS_COPY_BIN; do                                                               
                install_bin ${file//:/ }                                                              
        done                                                                                          
        install_file /etc/resolv.conf /lib/*.sh /lib/functions/*.sh /lib/upgrade/*.sh $RAMFS_COPY_DATA
                                                                                                      
        [ -L "/lib64" ] && ln -s /lib $RAM_ROOT/lib64                                                 
                                                                                                      
        supivot $RAM_ROOT /mnt || {                                                                   
                echo "Failed to switch over to ramfs. Please reboot."                                 
                exit 1                                                                                
        }
/bin/mount -o remount,ro /mnt                                                                 
        /bin/umount -l /mnt                                                                           
                                                                                                      
        grep /overlay /proc/mounts > /dev/null && {                                                   
                /bin/mount -o noatime,remount,ro /overlay                                             
                /bin/umount -l /overlay                                                               
        }                                                                                             
                                                                                                      
        # spawn a new shell from ramdisk to reduce the probability of cache issues                    
        exec /bin/busybox ash -c "$*"                                                                 
}</>

but getting below errors:

+ fw_printenv primary
+ cut -b 9
Error opening lock file /var/lock/fw_printenv.lock
+ check=
+ echo !!!!*********** check is  *************!!!!!!!!!!
!!!!*********** check is  *************!!!!!!!!!!
+ echo Praty primary is 
Praty primary is 
+ [ == 1 ]
ash: 1: unknown operand
+ echo in else ****successfull*** primary is 
in else ****successfull*** primary is</>

Please look into this
Thanks in advance

Regards
Sakshi

You have fw_printenv.lock under copy BIN rather than copy DATA in your previous post. That would be my guess. As well as a few other files.

Hi @lantis1008

I have fw_printenv under RAMFS_COPY_DATA in the platform.sh file. Below is the file attached:-

#
# Copyright (C) 2011 OpenWrt.org
#
set -x
USE_REFRESH=1

. /lib/ipq806x.sh
. /lib/upgrade/common.sh

RAMFS_COPY_BIN="fw_printenv fw_setenv"
**RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock'**
RAMFS_COPY_DATA=/lib/ipq806x.sh
RAMFS_COPY_BIN="/usr/bin/dumpimage /bin/mktemp /usr/sbin/mkfs.ubifs
        /usr/sbin/ubiattach /usr/sbin/ubidetach /usr/sbin/ubiformat /usr/sbin/ubimkvol
        /usr/sbin/ubiupdatevol /usr/bin/basename /bin/rm /usr/bin/find
        /usr/sbin/mkfs.ext4"
REQUIRE_IMAGE_METADATA=1

get_full_section_name() {
        local img=$1
        local sec=$2

        dumpimage -l ${img} | grep "^ Image.*(${sec})" | \
                sed 's,^ Image.*(\(.*\)),\1,'
}

image_contains() {
        local img=$1
        local sec=$2
        dumpimage -l ${img} | grep -q "^ Image.*(${sec}.*)" || return 1
}

But when i didnt write 
install_bin /usr/sbin/fw_printenv
install_bin /usr/sbin/fw_setenv
i was not getting logs which i added to get to know that in which partition i have, below are the logs:
" * echo !!!!*********** check is ** <em><strong><strong><strong><strong><strong>!!!!!!!!!!
!!!!</strong></strong></strong></strong></strong></em>  check is *************!!!!!!!!!! </>"
and
" * echo in else * ***successfull***  primary is
in else * ***successfull***  primary is&lt;/&gt;" </>"

Thanks in advance

Regards
Sakshi

  1. I’m not sure I understand what the question is in this last post sorry
  2. You really need to start using code tags in your post to make these readable. It would be great if you edited all your previous posts to use them too.
Code goes here like this
  1. In your above snippet, it looks like you set the variables, and then immediately overwrite them, which might be why it is not working the way you expect it?
2 Likes

Yep. At the first glance sakshi first sets the fwgetenv etc. values to variables, but then on the next line the variable gets reset with the original values.

You need to add the files to the existing file list, instead if trying to set variables twice.

1 Like

Hi, @lantis1008 and @hnyman

Thanks for your help.
But this didn't work for me. So I have to take a new path. I was using "sysugrade -v" command to do the firmware upgrade which is a script. So I take a variable in that script and export that variable and then use that variable in the platform.sh script. It works for me and I am able to do the firmware upgrade in alternate partition.
Following is the sysupgrade file changes:

export current_part=$(fw_printenv primary | cut -b 9)               
echo "current partition is $current_part" > /dev/console

Thanks for your help

Regards
Sakshi

I'm glad this works for you.
If you wanted this change pushed upstream however, i think it would need to be fixed properly. So i'd encourage you to keep working at it!
But if you were just after a solution to your individual problem, you're all done :slight_smile:

Hi @lantis1008

I don't have time to do more search on this but yes whenever I get free I will do.
But I am facing one problem in this.
When I am doing firmware upgrade via connecting locally, it is working fine but when I put the board on the network and got the DHCP IP and then do firmware upgrade from GUI. It is showing "BAD GATEWAY...The process did not produce any response".

I think GUI is taking so much time to upload the image as I have the single image which is of 45.6 MB or may be GUI timeout time is less.
I don't know how to solve this problem.

If you know anything about this please help me.

Thanks in advance

Regards
Sakshi

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.