Commit 8715fb65 authored by Adam Wujek's avatar Adam Wujek 💬

Merge branch 'adam-date'

Introduce saving time before restart, which is restored after restart.
Aslo report date of last firmware update.
parents da583f7b 444f580f
......@@ -1623,7 +1623,7 @@ allows to make some sense of the overall area. The structure
is filled by library functions and accessed by shared memory users.
You can see how it is used in @t{tools/wrs_dump_shmem.c}.
The following functions are defined. Pleae look in the source code
The following functions are defined. Please look in the source code
for details about how they are used:
@table @code
......@@ -1798,6 +1798,22 @@ We may also consider to use one of the kernel's mechanisms for persistent
storage of information across reboots, to recover panic messages
after a reboot.
@c ==========================================================================
@node Time keeping over restarts
@section Time keeping over restarts
At normal restart, current time is saved in @t{/update/saved_date}.
Later, at boot switch tries to retrieve correct time from ntp server
if configured in dot-config.
If no correct date can be retrieved via ntp, switch tries to set date stored in
@t{/update/saved_date}. Please note that at crash, power down or
reset by reset button no date information is saved. After such restart switch
will set date to last gentle reboot or to 1st of January 1970 if there were no
gentle restarts before.
Date set from file @t{/update/saved_date} is never correct, but is based on
best effort principle.
@c ==========================================================================
@node SDB and Hardware Information
@section SDB and Hardware Information
......
#!/bin/sh
echo "Saving time "`date +%Y.%m.%d-%H:%M:%S`
date +%Y.%m.%d-%H:%M:%S > /update/saved_date
......@@ -4,18 +4,32 @@
/wr/bin/wr_date get > /dev/null
F=/wr/etc/wr_date.conf
# if there is no config file, do nothing else.
test -f $F || exit 0
# pick the first server, if any
S=$(grep 'ntpserver' $F | sed 's/ntpserver//' | head -n 1)
date_set=0
# check whether there is config file
if [ -f $F ]; then
# pick the first server, if any
S=$(grep 'ntpserver' $F | sed 's/ntpserver//' | head -n 1)
# check whether server found
if [ -n "$S" ]; then
# if none, exit
test -z "$S" && exit 0
# pick busybox ntpd explicitly, to avoid real ntpd instances
echo "Setting host time using ntpd"
busybox ntpd -n -q -p $S
echo "Setting WR time from host time"
/wr/bin/wr_date set host
# pick busybox ntpd explicitly, to avoid real ntpd instances
echo "Setting host time using ntpd"
busybox ntpd -n -q -p $S
if [ $? == 0 ]; then
# successful
echo "Date set from $S"
date_set=1
echo "Setting WR time from host time"
/wr/bin/wr_date set host
fi
fi
fi
# if ntp failed, try to restore date saved before last reboot
if [ $date_set = 0 ] && [ -f /update/update_date ]; then
#date is not accurate but no better idea.
echo "Restore saved time"
date -s `cat /update/update_date`
echo "Setting WR time from host time"
/wr/bin/wr_date set host
fi
#!/bin/sh
if [ -n "$WRS_VERBOSE" ]; then
set -x;
SH_X="sh -x"
fi
# Stop all init scripts in /etc/init.d
# executing them in numerical order.
#
for i in /etc/init.d/K??* ;do
# Ignore dangling symlinks (if any).
[ ! -f "$i" ] && continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set stop
. $i
)
;;
*)
# No sh extension, so fork subprocess.
eval $SH_X $i stop
;;
esac
done
......@@ -123,6 +123,9 @@ mount -t ubifs ubi0:boot /boot
# Some steps later set reboot=true; prepare a sane default.
reboot=false
#whether to change date of last update
change_update_date=false
# First: update usr: we may have the whole thing, or just wrs-usr.tar.gz
if [ -f /update/$WRS_FW -o -f /update/$WRS_USR ]; then
# FIXME: save configuration somewhere, and recover it later
......@@ -171,7 +174,7 @@ if [ -f /update/$WRS_FW -o -f /update/$WRS_USR ]; then
fi
# And, to be sure, remove a file that may exist from a 4.0 install
rm -f /update/$OLD_FW_OLDNAME
change_update_date=true
fi
# Allow replacing the kernel or initramfs alone (new in v4.1 of wr-switch-sw)
......@@ -190,8 +193,12 @@ if [ -f /update/$WRS_BB ]; then
mv /update/current-$WRS_BB /update/previous-$WRS_BB
mv /update/$WRS_BB /update/current-$WRS_BB
reboot=true
change_update_date=true
fi
if $change_update_date; then
cp /update/saved_date /update/last_update > /dev/null 2>&1
fi
# If we changed bloader or kernel or initramfs, we reboot. Otherwise proceed.
if $reboot; then
umount /update
......
......@@ -29,5 +29,7 @@ ttyGS0::respawn:/bin/ash --login
ttyS0::respawn:/bin/ash --login
# Stuff to do before rebooting
# run all /etc/init.d/K* scripts
null::shutdown:/etc/init.d/rcK -a -r
null::shutdown:/bin/umount -a -r
......@@ -336,6 +336,15 @@ wrsVersionWrCoresCommitId OBJECT-TYPE
"The gateware version: commit of wr-cores"
::= { wrsVersionGroup 13 }
wrsVersionLastUpdateDate OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..32))
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Date and time of last firmware update, this information may not be
ccurate, due to hard restarts or lack of proper time."
::= { wrsVersionGroup 14 }
wrsOperationStatus OBJECT IDENTIFIER ::= { wrsExpertStatus 1 }
-- wrsCurrentTimeGroup (.7.1.1)
......
......@@ -8,7 +8,13 @@
#include "wrsSnmp.h"
#include "wrsVersionGroup.h"
/* Macros for fscanf function to read line with maximum of "x" characters
* without new line. Macro expands to something like: "%10[^\n]" */
#define LINE_READ_LEN_HELPER(x) "%"#x"[^\n]"
#define LINE_READ_LEN(x) LINE_READ_LEN_HELPER(x)
#define VERSION_COMMAND "/wr/bin/wrs_version -t"
#define LAST_UPDATE_DATE_FILE "/update/last_update"
struct wrs_v_item {
char *key;
......@@ -28,6 +34,7 @@ static struct pickinfo wrsVersion_pickinfo[] = {
FIELD(wrsVersion_s, ASN_OCTET_STR, wrsVersions[10]),
FIELD(wrsVersion_s, ASN_OCTET_STR, wrsVersions[11]),
FIELD(wrsVersion_s, ASN_OCTET_STR, wrsVersions[12]),
FIELD(wrsVersion_s, ASN_OCTET_STR, wrsVersionLastUpdateDate),
};
struct wrsVersion_s wrsVersion_s;
......@@ -50,6 +57,22 @@ static struct wrs_v_item wrs_version[] = {
[12] = {"wr-cores-commit:"},
};
static void get_last_update_date(void)
{
FILE *f;
f = fopen(LAST_UPDATE_DATE_FILE, "r");
if (f) {
/* readline without newline */
fscanf(f, LINE_READ_LEN(32),
wrsVersion_s.wrsVersionLastUpdateDate);
fclose(f);
} else {
snprintf(wrsVersion_s.wrsVersionLastUpdateDate, 32,
"0000.00.00-00:00:00");
}
}
time_t wrsVersion_data_fill(void)
{
char s[80], key[40], value[40];
......@@ -98,6 +121,8 @@ time_t wrsVersion_data_fill(void)
guess_index++;
}
pclose(f);
get_last_update_date();
return time_cur;
}
......
......@@ -5,6 +5,7 @@
struct wrsVersion_s {
char wrsVersions[13][32]; /* array of version strings */
char wrsVersionLastUpdateDate[32];
};
extern struct wrsVersion_s wrsVersion_s;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment