Last active
April 28, 2019 20:35
-
-
Save chertov/0808c61a780020528a823a143a765dd2 to your computer and use it in GitHub Desktop.
Parse bootargs and create /etc/fw_env.config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
fw_env_path="/etc/fw_env.config" | |
bootargs_param="ubootenv" | |
cmdline=`cat /proc/cmdline` | |
# for testing | |
# cmdline="cmdline mem=128M totalmem=192M sensor=imx222 console=ttyAMA0,115200 phyaddru=0 phyaddrd=1 ubootenv=/dev/mtd1,0x00000,0x40000,0x10000 mtdparts=hi_sfc:320K(uboot),192K(ubootenv),6144K(romfs),5120K(romfail),3072K(app),1536K(config)" | |
for cmdparam in ${cmdline}; do | |
case ${cmdparam} in ${bootargs_param}=*) | |
set `echo ${cmdparam} | sed "s/${bootargs_param}=//g" | sed "s/,/ /g"` | |
ubootenv_params=$* | |
params_count=$# | |
if [ ${params_count} -lt 4 ]; then | |
echo "Error: uboot env parameters '${bootargs_param}=${ubootenv_params}' is incorrect! Must be ${bootargs_param}=<mtd_path>,<device_offset (hex)>,<env_size (hex)>,<sector_size (hex)>,<number_of_sectors>'" | |
fi | |
mtd_path=$1 | |
device_offset=$2 | |
env_size=$3 | |
sector_size=$4 | |
number_of_sectors=1 | |
if [ ${params_count} -eq 5 ]; then number_of_sectors=$5; fi | |
# echo mtd_path ${mtd_path} | |
# echo device_offset ${device_offset} | |
# echo env_size ${env_size} | |
# echo sector_size ${sector_size} | |
# echo number_of_sectors ${number_of_sectors} | |
printf "" > ${fw_env_path} # clear file | |
printf "# Configuration file for fw_(printenv/saveenv) utility.\n" >> ${fw_env_path} | |
printf "# MTD device name Device offset Env. size Flash sector size Number of sectors\n" >> ${fw_env_path} | |
printf "${mtd_path} ${device_offset} ${env_size} ${sector_size} ${number_of_sectors}\n" >> ${fw_env_path} | |
printf "\n" >> ${fw_env_path} | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment