Skip to content

Instantly share code, notes, and snippets.

@Josua-SR
Created August 9, 2018 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Josua-SR/feb0a32903154fab147c875efac749a7 to your computer and use it in GitHub Desktop.
Save Josua-SR/feb0a32903154fab147c875efac749a7 to your computer and use it in GitHub Desktop.
i.MX6 Legacy Boot-Script
#
# Copyright <2017-2018> Josua Mayer <josua@solid-run.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#############
# functions #
#############
# load u-boot environment file $bootenv from mmc $mmcdev:$mmcpart
setenv loadbootenv "true;
load mmc '${mmcdev}':'${mmcpart}' '${loadaddr}' '${file_prefix}''${bootenv}';"
# Don't load boot-script $script from mmc $mmcdev:$mmcpart
setenv loadbootscript "false;"
# load mmc '${mmcdev}':'${mmcpart}' '${loadaddr}' '${file_prefix}''${script}';"
# load $bootfile from mmc $mmcdev:$mmcpart
setenv loadbootfile "true;
load mmc '${mmcdev}':'${mmcpart}' '${loadaddr}' '${file_prefix}''${bootfile}';"
# load fdt blob
setenv loadfdt "true;
if test '${boottype}' = mmc; then
load mmc '${mmcdev}':'${mmcpart}' '${fdt_addr}' '${file_prefix}'/'${fdt_file}';
else
'${get_cmd}' '${fdt_addr}' '${fdt_file}';
fi;"
# load ramdisk image
setenv loadramdisk "true;
if test '${boottype}' = mmc; then
load mmc '${mmcdev}':'${mmcpart}' '${ramdisk_addr}' '${file_prefix}'/'${ramdisk_file}';
else
'${get_cmd}' '${ramdisk_addr}' '${ramdisk_file}';
fi;"
# figure out filename of devicetree blob
setenv autodetectfdt "true;
run findfdt;
setenv fdt_file '${fdtfile}'";
# execute previously loaded boot-script
setenv bootscript "true;
echo Running bootscript from mmc ...;
source;"
# import previously loaded u-boot environment
setenv importbootenv "true;
echo Importing environment from mmc'${mmcdev}' ...;
env import -t '${loadaddr}' '${filesize}';"
# boot from network
setenv netboot "true;
echo Booting from net ...;
run netargs;
setenv boottype net;
if test '${ip_dyn}' = yes; then
setenv get_cmd dhcp;
else
setenv get_cmd tftp;
fi;
if test '${bootfile}' = auto; then
setenv bootfile zImage
if '${get_cmd}' '${bootfile}'; then
run bootit;
else
setenv bootfile uImage;
fi;
fi;
'${get_cmd}' '${bootfile}';
run bootit;"
# generate bootargs for booting from network
setenv netargs "true;
setenv bootargs console='${console}','${baudrate}' root=/dev/nfs ip=dhcp nfsroot='${serverip}':'${nfsroot}',v3,tcp;"
# boot from mmc
setenv mmcboot "true;
echo Booting from mmc ...;
run mmcargs;
setenv boottype mmc;
run bootit;"
# generate bootargs for booting from mmc
setenv mmcargs "true;
setenv bootargs quiet console='${console}','${baudrate}' root='${mmcroot}';"
# set up ramdisk and fdt
setenv bootit "true;
setenv boot_file '${bootfile}';
setenv fdt_addr_bak '${fdt_addr}';
if test -n '${ramdisk_file}'; then
if run loadramdisk; then
echo Loaded '${ramdisk_file}';
else
setenv ramdisk_addr -;
fi;
else
setenv ramdisk_addr -;
fi;
if test '${boot_file}' = zImage; then
if test '${boot_fdt}' = yes || test '${boot_fdt}' = try; then
if run loadfdt; then
echo Loaded '${fdt_file}';
else
setenv fdt_addr;
if test '${boot_fdt}' = try; then
echo WARN: Cannot load the DTB, and boot file is type zImage;
echo if you have not appended a dtb to the file it may;
echo hang after displaying Starting kernel...;
echo;
else
echo WARN: Cannot load the DT;
fi;
fi;
else
setenv fdt_addr;
fi;
else
setenv fdt_addr;
fi;
run autoboot;"
# call start kernel
setenv autoboot "true;
echo Booting '${boot_file}';
if test '${boot_file}' = zImage; then
bootz '${loadaddr}' '${ramdisk_addr}' '${fdt_addr}';
else
bootm '${loadaddr}' '${ramdisk_addr}' '${fdt_addr}';
fi;"
####################
# default settings #
####################
setenv loadaddr ${kernel_addr_r}
setenv fdt_addr ${fdt_addr_r}
setenv ramdisk_addr ${ramdisk_addr_r}
setenv fdt_high 0xffffffff
setenv initrd_high 0xffffffff
setenv console ttymxc0
setenv baudrate 115200
setenv mmcdev 0
setenv mmcpart 1
setenv mmcroot /dev/mmcblk0p2 rootwait rw
setenv boot_prefixes / /boot/
setenv bootfile auto
# setenv ramdisk_file initrd.img
setenv boot_fdt try
setenv bootenv uEnv.txt
setenv script boot.scr
# setenv serverip 10.0.0.1 # enable to boot from network
setenv ip_dyn yes
########
# Boot #
########
mmc dev ${mmcdev}
if mmc rescan; then
for prefix in ${boot_prefixes}; do
setenv file_prefix ${prefix}
if run loadbootscript; then
run bootscript
else
run autodetectfdt
if run loadbootenv; then
run importbootenv
fi
if test -n ${serverip}; then
run netboot
fi
if test ${bootfile} = auto; then
setenv origbootfile auto
setenv bootfile zImage
if run loadbootfile; then
run mmcboot
else
setenv bootfile uImage
fi
fi
if run loadbootfile; then
run mmcboot
else
setenv bootfile ${origbootfile}
fi
fi
done
fi
run netboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment