Public feed
#891864
#!/bin/bash
# unless otherwise noted, EVERY NUMBER IS IN HEX
base_dir=$(dirname $0)
scriptfile=autoscript.scr
imgfile=autoscript.bin
kernel_file=uImage
for i in $base_dir/omap5912osk/uImage* ; do
cp -f $i $base_dir/$kernel_file
done
if [ ! -f $base_dir/$kernel_file ] ; then
echo "Could not find kernel image $base_dir/$kernel_file."
exit 1
fi
kernel_size_10=`du -b $base_dir/$kernel_file | cut -f 1`
kernel_size=$( printf "0x%08X" $kernel_size_10 )
rootfs_file=rootfs.jffs2
#cp -f $base_dir/omap5912osk/gpe-image-omap5912osk.jffs2 $base_dir/$rootfs_file
cp -f $base_dir/omap5912osk/pd-osk-gpe-image-omap5912osk.jffs2 $base_dir/$rootfs_file
if [ ! -f $base_dir/$rootfs_file ] ; then
echo "Could not find root filesystem image $base_dir/$rootfs_file."
exit 1
fi
rootfs_size_10=`du -b $base_dir/$rootfs_file | cut -f 1`
rootfs_size=$( printf "0x%08X" $rootfs_size_10 )
# the osk doesn't have enough RAM to copy the whole rfs with tftp
# thus we must split it
# this makes files named rootfs.jffs2.00, rootfs.jffs2.01, ...
max_file_size=0x00C00000 # 12 MiB
split --bytes $(($max_file_size)) --numeric-suffixes $rootfs_file ${rootfs_file}.
# because this may get confusing, here is a description of interpolation rules
# here documents work basically like double quoted strings w.r.t. variable expansion
# $var is local to this script, and will be expanded before catting
# \${var} is not expanded here, but will be expanded when the generated script is run in u-boot
# like in a double quoted string, single quotes don't have any special meaning (w.r.t. this script)
# in u-boot, single quote do not expand variables, so
# setenv bar blah
# setenv foo '${bar}'
# setenv fu ${bar}
# means that foo is literally "${bar}" and fu is literally "blah"
# variables are expanded only once, so "setenv baz ${foo}" means baz = "${bar}"
# basically,
# $var is a literal in u-boot
# \${var} is "${var}" in u-boot
# "setenv foo \${var}" or "setenv foo '${var}'" makes foo the unexpanded ${var} in u-boot
# almost everything except constants (addresses and such) should be of the form \${var}
# so they get expanded when they're used.
# use this regex to check: [^\\][$]
# isn't quoting fun? bonus points if you can quine this script
# note about bootargs
# it seems that bootargs is not expanded before being passed to the kernel,
# so we must not have any unexpanded variables in it
# 0x00000000-0x00020000 : "bootloader"
# 0x00020000-0x00040000 : "params"
# 0x00040000-0x00240000 : "kernel"
# 0x00240000-0x02000000 : "filesystem"
(cat <<EOF
echo
echo addresses and sizes
echo
setenv tmp 0x10000000
setenv kernel_flash_addr 0x00040000
print kernel_flash_addr
setenv kernel_flash_endaddr 0x0023FFFF
print kernel_flash_endaddr
setenv rootfs_flash_addr 0x00240000
print rootfs_flash_addr
setenv rootfs1_flash_addr 0x00240000
setenv rootfs2_flash_addr 0x00E40000
setenv rootfs_flash_endaddr 0x01FFFFFF
print rootfs_flash_endaddr
echo
echo tftp
echo
setenv ipaddr 192.168.0.187
print ipaddr
setenv serverip 192.168.0.23
print serverip
setenv gatewayip 192.168.0.3
print gatewayip
setenv netmask 255.255.255.0
print netmask
echo
echo erase flash
echo
setenv erase_kernel_flash 'erase \${kernel_flash_addr} \${kernel_flash_endaddr}'
print erase_kernel_flash
setenv erase_rootfs_flash 'erase \${rootfs_flash_addr} \${rootfs_flash_endaddr}'
print erase_kernel_flash
echo
echo download
echo
setenv kernel_file ${kernel_file}
print kernel_file
setenv get_kernel 'run erase_kernel_flash; tftp \${tmp} \${kernel_file}; cp.b \${fileaddr} \${kernel_flash_addr} \${filesize}'
print get_kernel
setenv rootfs_file ${rootfs_file}
print rootfs_file
setenv get_rootfs1 'tftp \${tmp} \${rootfs_file}.00; cp.b \${fileaddr} \${rootfs1_flash_addr} \${filesize}'
setenv get_rootfs2 'tftp \${tmp} \${rootfs_file}.01; cp.b \${fileaddr} \${rootfs2_flash_addr} \${filesize}'
setenv get_rootfs 'run erase_rootfs_flash; run get_rootfs1; run get_rootfs2'
print get_rootfs
setenv get_system 'run get_kernel; run get_rootfs'
print get_system
echo
echo boot commands
echo
setenv bootargs console=ttyS0,115200n8 noinitrd rw ip=dhcp root=/dev/mtdblock3 rootfstype=jffs2 mem=32M
print bootargs
setenv bootcmd 'bootm \${kernel_flash_addr}'
print bootcmd
echo
echo update
echo
setenv autoscript_file ${imgfile}
print autoscript_file
setenv update_env 'tftp \${tmp} \${autoscript_file}; autoscr \${fileaddr}'
printenv update_env
echo
echo saving env...
echo
saveenv
EOF
) > $base_dir/$scriptfile
mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
-n "kernel/fs loader script" \
-d $base_dir/$scriptfile $base_dir/$imgfile
chmod 644 $base_dir/$imgfile
chmod 644 $base_dir/$kernel_file
chmod 644 $base_dir/$rootfs_file