I have been building some different images and generally playing around. So I have 2 different images both built from 21.02.2. Is there a straight forward way to determine which image I have actually flashed onto my OpenWrt device? Yes I realise I could just flash it again but I wanted to know if there is a way to interrogate the running image.
Both images have the same "version.buildinfo" reference (r16495-bf0c965af0) but obviously the "config.buildinfo" and the hash for the bin files are different. I tried looking at /proc/version but that just tells me the version buildinfo.
Thanks but it doesn't help identify exactly which image I flashed just the build details which is the same for both images even though the built with different libraries.
It may only be a clue, but the file date and time on, e.g., /etc/banner/etc/rom tells you at least when exactly you built the image and may allow you to correlate that with the datetime of one of your images.
That's pretty much exactly what I said two posts earlier. No harm in that, good advice won't get bad if given twice. That being said, ls will not give you the time if the file was created in a different year, replacing the time with the year, so it's better to recommend date -r /rom to get the full timestamp.
Point taken, but the question was which of two 21.02.2 builds was most current. Year wasn’t relevant.
I’ve edited my post to reflect the ls option that provides full timestamp. Got caught out by my shell alias
Checking /rom is less ambiguous to the question. It’s static, and the timestamps are created in the build process. I for one rely on touch /etc/banner in a couple of of shell scripts I use, and I know there are a lot of cron reboot runs in use.
Oh, right, I forgot that it's a popular workaround to touchexactly that file. Of all the files I could have chosen I just had to pick that one. Good catch, I'll edit my post.
Thanks both.......these commands both give the same date/time but it's not the date/time that I built the image so I'm a bit confused by that. The image that is flashed onto the device atm was created 12th April 2022 09:47:04 BST but the commands you have suggested both give a date time of 16th Feb 2022 20:29:10
Buildroot for image creation. However, I do have the imagebuilder archive in the same packages directory as the bin files I created.....it has the same date as the files on running OpenWrt system (i.e. 16th Feb)?
If your sysupgrade.bin you flashed is dated as above and your /rom is dated Feb. 16, I have to surmise you are using ImageBuilder for your images and not building from source.
I flashed a "factory.bin" image. Here is the guide I was following when I built the image, not specifically a OpenWrt build document but covers downloading source etc etc...
I vaguely remember the build system setting the "creation date" on a squahfs filesystem to the last-commit date, rather than the build time. (This kind of choice is needed for testing that requires repeatable builds.)
See, for example, fgrep -r SOURCE_DATE_EPOCH ./include
$ cat ~/bin/wrt
#!/bin/sh
ETC_FW_DIR=./files/etc/firmware
SAVE_DIR=..
usage () {
echo '
usage: wrt prep [{wrt1900acs,wndr3700v2}]
wrt save [{wrt1900acs,wndr3700v2}]'
exit 0
}
TARGET=${2:-wrt1900acs}
case $TARGET in
wndr3700v2)
ARCH=ar71xx
PROFILE=generic
OPENWRT_BIN_DIR="./bin/targets/$ARCH/$PROFILE"
OPENWRT_FW_BASE="openwrt-$ARCH-$PROFILE-$TARGET-squashfs"
;;
wrt1900acs)
ARCH=mvebu
PROFILE=cortexa9
OPENWRT_BIN_DIR="./bin/targets/$ARCH/$PROFILE"
OPENWRT_FW_BASE="openwrt-$ARCH-$PROFILE-linksys_$TARGET-squashfs"
;;
*)
echo "unknown target $TARGET"
usage
;;
esac
find_fw_name () {
local \
rev="$(git rev-parse --short=10 HEAD)"
local date=$(date +%Y%m%d)
local i=1
fw_name="$TARGET-$date-$rev-$i"
while [ -f "$SAVE_DIR/$fw_name.config" ]; do
i=$(($i + 1))
fw_name="$TARGET-$date-$rev-$i"
done
}
prep () {
if [ ! -f .config ] ; then echo '.config does not exist'; exit 1; fi
if [ -d $ETC_FW_DIR ]; then
find $ETC_FW_DIR -name '*~' -delete
else
mkdir -p $ETC_FW_DIR
fi
cp -v .config $ETC_FW_DIR/config
find_fw_name
echo "$fw_name" > $ETC_FW_DIR/version
}
save () {
if [ ! -f .config ] ; then echo '.config does not exist'; exit 1; fi
local BIN_DIR
local FW_BASE
if [ -d $OPENWRT_BIN_DIR ] ; then
BIN_DIR=$OPENWRT_BIN_DIR
FW_BASE=$OPENWRT_FW_BASE
else
echo 'BIN_DIR not recognized'
exit 1
fi
local fw_factory="$BIN_DIR/$FW_BASE-factory.img"
local fw_sysupgrade="$BIN_DIR/$FW_BASE-sysupgrade.bin"
for fw in $fw_factory $fw_sysupgrade; do
if [ ! -f $fw ] ; then echo "$fw does not exist"; exit 1; fi
done
if [ -f $ETC_FW_DIR/version ]; then
fw_name=$(cat $ETC_FW_DIR/version)
else
find_fw_name
fi
fw_config="$SAVE_DIR/$fw_name.config"
if [ -f $fw_config ]; then
echo "$fw_config exists, forgot 'wrt prep' before 'make'?"
exit 1
fi
cp -v .config $fw_config
fw_fdst="$SAVE_DIR/$fw_name.fac.img"
cp -v $fw_factory $fw_fdst
fw_sdst="$SAVE_DIR/$fw_name.sys.bin"
cp -v $fw_sysupgrade $fw_sdst
}
case $1 in
p|pr|pre|prep) prep;;
s|sa|sav|save) save;;
*) usage;;
esac
Calling 'wrt prep' from the buildroot before starting the build will create two files in ./files/etc/firmware: version has one line like 'wrt1900acs-20220506-231206ad23-1', i.e. target, build date, git revision and a number incremented with each 'wrt prep'. config is a copy of .config created with 'make menuconfig'
After flashing the image and ssh-ing into the router they are available in /etc/firmware/.
Calling wrt save after the build will use the string in ./files/etc/firmware/version as basename for 3 files copied to $buildroot/..: $version_string.fac.img is the factory image, $version_string.sys.bin is a sysupdate image and $version_string.config is again a copy of ./.config.