Skip to content

Commit

Permalink
Merge pull request #796 from kernelkit/rtc
Browse files Browse the repository at this point in the history
Support for save/restore system clock from file
  • Loading branch information
troglobit authored Nov 5, 2024
2 parents bca1313 + 1323d2f commit c81b03e
Show file tree
Hide file tree
Showing 19 changed files with 761 additions and 23 deletions.
8 changes: 8 additions & 0 deletions board/aarch64/dts/styx/dcp-sc-28p.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
};
};

/*
* RTC has no valid bit, and this board does not connect any
* backup power (e.g. supercap) to it, so it returns garbage
* after every cold reset.
*/
&cp0_rtc {
status = "disabled";
};

/* UART0 (Console) */

Expand Down
49 changes: 49 additions & 0 deletions board/common/qemu/Config.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ config QEMU_DTB_EXTEND
depends on QEMU_LOADER_UBOOT
default y if QEMU_aarch64

if QEMU_ROOTFS_INITRD

config QEMU_RW
string "Writable /cfg layer"
depends on QEMU_ROOTFS_INITRD
Expand All @@ -123,6 +125,8 @@ config QEMU_RW_VAR
default "var.ext4"
endif

endif

config QEMU_VPD
bool "Emulate a Vital Product Data (VPD) Memory"

Expand All @@ -137,6 +141,51 @@ config QEMU_APPEND
config QEMU_EXTRA
string "Extra QEMU options"


comment "RTC"

choice
prompt "Mode"
default QEMU_RTC_UTC

config QEMU_RTC_UTC
bool "UTC"

config QEMU_RTC_LOCAL
bool "Local time"

config QEMU_RTC_RANDOM
bool "Random"

endchoice

choice
prompt "Clock"
default QEMU_CLOCK_HOST

config QEMU_CLOCK_HOST
bool "Host clock"

config QEMU_CLOCK_RT
bool "Independent (monotonic)"

config QEMU_CLOCK_VM
bool "Virtual"

endchoice

config QEMU_RTC
string
default "utc" if QEMU_RTC_UTC
default "localtime" if QEMU_RTC_LOCAL
default "random" if QEMU_RTC_RANDOM

config QEMU_CLOCK
string
default "host" if QEMU_CLOCK_HOST
default "rt" if QEMU_CLOCK_RT
default "vm" if QEMU_CLOCK_VM

comment "Networking"

choice
Expand Down
43 changes: 36 additions & 7 deletions board/common/qemu/qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,25 @@ EOF

wdt_args()
{
echo -n "-device i6300esb -rtc clock=host"
echo -n "-device i6300esb "
}

random_date()
{
rand=$(($(date +%_s) * $$ + $(date +%N | sed 's/^0*//')))
when=$((rand % 7258118400)) # 1970 - 2200
date -d "@$when" +"%Y-%m-%dT%H:%M:%S"
}

rtc_args()
{
rtc="${CONFIG_QEMU_RTC:-utc}"
clock="${CONFIG_QEMU_CLOCK:-host}"
if [ "$rtc" = "random" ]; then
rtc=$(random_date)
fi

echo -n "-rtc base=$rtc,clock=$clock"
}

gdb_args()
Expand All @@ -273,11 +291,19 @@ gdb_args()
run_qemu()
{
if [ "$CONFIG_QEMU_ROOTFS_VSCSI" = "y" ]; then
qemu-img create -f qcow2 -o backing_file=$CONFIG_QEMU_ROOTFS -F raw $CONFIG_QEMU_ROOTFS.qcow2 > /dev/null
if ! qemu-img check "${CONFIG_QEMU_ROOTFS}.qcow2"; then
rm -f "${CONFIG_QEMU_ROOTFS}.qcow2"
fi
if [ ! -f "${CONFIG_QEMU_ROOTFS}.qcow2" ]; then
echo "Creating qcow2 disk image for Qemu ..."
qemu-img create -f qcow2 -o backing_file="$CONFIG_QEMU_ROOTFS" \
-F raw "${CONFIG_QEMU_ROOTFS}.qcow2" > /dev/null
fi
fi

local qemu
read qemu <<EOF
$CONFIG_QEMU_MACHINE -m $CONFIG_QEMU_MACHINE_RAM \
$CONFIG_QEMU_MACHINE -nodefaults -m $CONFIG_QEMU_MACHINE_RAM \
$(loader_args) \
$(rootfs_args) \
$(serial_args) \
Expand All @@ -286,16 +312,23 @@ run_qemu()
$(host_args) \
$(net_args) \
$(wdt_args) \
$(rtc_args) \
$(vpd_args) \
$(gdb_args) \
$CONFIG_QEMU_EXTRA
EOF

echo "Starting Qemu :: Ctrl-a x -- exit | Ctrl-a c -- toggle console/monitor"
line=$(stty -g)
stty raw

if [ "$CONFIG_QEMU_KERNEL" ]; then
$qemu -append "$(append_args)" "$@"
else
$qemu "$@"
fi

stty "$line"
}

dtb_args()
Expand Down Expand Up @@ -401,8 +434,4 @@ fi

generate_dot

echo "Starting Qemu :: Ctrl-a x -- exit | Ctrl-a c -- toggle console/monitor"
line=$(stty -g)
stty raw
run_qemu $(dtb_args)
stty "$line"
2 changes: 1 addition & 1 deletion board/common/rootfs/usr/libexec/infix/mnt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ mount_overlay home "$cfgsrc" /home
mount_overlay root "$cfgsrc" /root
mount_bind "$varsrc" /var

[ "$vlibsrc" ] && mount_bind "$vlibsrc" /var/lib
[ -n "$vlibsrc" ] && mount_bind "$vlibsrc" /var/lib

for tag in $(ls /sys/bus/virtio/devices/*/mount_tag 2>/dev/null); do
if [ "$(cat $tag | tr -d '\0')" = hostfs ]; then
Expand Down
2 changes: 2 additions & 0 deletions configs/aarch64_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ BR2_PACKAGE_FINIT_PLUGIN_HOTPLUG=y
BR2_PACKAGE_FINIT_PLUGIN_HOOK_SCRIPTS=y
BR2_PACKAGE_FINIT_PLUGIN_MODULES_LOAD=y
BR2_PACKAGE_FINIT_PLUGIN_RTC=y
BR2_PACKAGE_FINIT_RTC_DATE="2024-11-04 10:54:00"
BR2_PACKAGE_FINIT_RTC_FILE="/var/lib/misc/rtc"
BR2_PACKAGE_FINIT_PLUGIN_TTY=y
BR2_PACKAGE_FINIT_PLUGIN_URANDOM=y
BR2_PACKAGE_IITO=y
Expand Down
2 changes: 2 additions & 0 deletions configs/aarch64_minimal_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ BR2_PACKAGE_FINIT_PLUGIN_HOTPLUG=y
BR2_PACKAGE_FINIT_PLUGIN_HOOK_SCRIPTS=y
BR2_PACKAGE_FINIT_PLUGIN_MODULES_LOAD=y
BR2_PACKAGE_FINIT_PLUGIN_RTC=y
BR2_PACKAGE_FINIT_RTC_DATE="2024-11-04 10:54:00"
BR2_PACKAGE_FINIT_RTC_FILE="/var/lib/misc/rtc"
BR2_PACKAGE_FINIT_PLUGIN_TTY=y
BR2_PACKAGE_FINIT_PLUGIN_URANDOM=y
BR2_PACKAGE_IITO=y
Expand Down
2 changes: 2 additions & 0 deletions configs/r2s_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ BR2_PACKAGE_FINIT_PLUGIN_HOTPLUG=y
BR2_PACKAGE_FINIT_PLUGIN_HOOK_SCRIPTS=y
BR2_PACKAGE_FINIT_PLUGIN_MODULES_LOAD=y
BR2_PACKAGE_FINIT_PLUGIN_RTC=y
BR2_PACKAGE_FINIT_RTC_DATE="2024-11-04 10:54:00"
BR2_PACKAGE_FINIT_RTC_FILE="/var/lib/misc/rtc"
BR2_PACKAGE_FINIT_PLUGIN_TTY=y
BR2_PACKAGE_FINIT_PLUGIN_URANDOM=y
BR2_PACKAGE_IITO=y
Expand Down
2 changes: 2 additions & 0 deletions configs/riscv64_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ BR2_PACKAGE_FINIT_PLUGIN_HOTPLUG=y
BR2_PACKAGE_FINIT_PLUGIN_HOOK_SCRIPTS=y
BR2_PACKAGE_FINIT_PLUGIN_MODULES_LOAD=y
BR2_PACKAGE_FINIT_PLUGIN_RTC=y
BR2_PACKAGE_FINIT_RTC_DATE="2024-11-04 10:54:00"
BR2_PACKAGE_FINIT_RTC_FILE="/var/lib/misc/rtc"
BR2_PACKAGE_FINIT_PLUGIN_TTY=y
BR2_PACKAGE_FINIT_PLUGIN_URANDOM=y
BR2_PACKAGE_IITO=y
Expand Down
2 changes: 2 additions & 0 deletions configs/x86_64_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ BR2_PACKAGE_FINIT_PLUGIN_HOTPLUG=y
BR2_PACKAGE_FINIT_PLUGIN_HOOK_SCRIPTS=y
BR2_PACKAGE_FINIT_PLUGIN_MODULES_LOAD=y
BR2_PACKAGE_FINIT_PLUGIN_RTC=y
BR2_PACKAGE_FINIT_RTC_DATE="2024-11-04 10:54:00"
BR2_PACKAGE_FINIT_RTC_FILE="/var/lib/misc/rtc"
BR2_PACKAGE_FINIT_PLUGIN_TTY=y
BR2_PACKAGE_FINIT_PLUGIN_URANDOM=y
BR2_PACKAGE_IITO=y
Expand Down
2 changes: 2 additions & 0 deletions configs/x86_64_minimal_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ BR2_PACKAGE_FINIT_PLUGIN_HOTPLUG=y
BR2_PACKAGE_FINIT_PLUGIN_HOOK_SCRIPTS=y
BR2_PACKAGE_FINIT_PLUGIN_MODULES_LOAD=y
BR2_PACKAGE_FINIT_PLUGIN_RTC=y
BR2_PACKAGE_FINIT_RTC_DATE="2024-11-04 10:54:00"
BR2_PACKAGE_FINIT_RTC_FILE="/var/lib/misc/rtc"
BR2_PACKAGE_FINIT_PLUGIN_TTY=y
BR2_PACKAGE_FINIT_PLUGIN_URANDOM=y
BR2_PACKAGE_IITO=y
Expand Down
19 changes: 18 additions & 1 deletion doc/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,25 @@ All notable changes to the project are documented in this file.

### Changes

- Support for showing interfaces owned by running containers in the CLI
command `show interfaces`. This also adds support for showing the
peer interface of VETH pairs. Issue #626
- Reboot system on kernel "oops", on "oops" the kernel now panics and
reboots after 20 seconds. Issue #740
- Update static factory-config for NanoPi R2S: enable NACM, securing all
passwords, and enabling `iburst` for the NTP client. Issue #750
- Updated QoS documentation with pictures and more information on VLAN
interface ingress/egress priority handling.
interface ingress/egress priority handling, issue #759
- Disable RTC device in Styx device tree, issue #794
- Support for saving and restoring system clock from a disk file. This
allows restoring the system clock to a sane date in case the RTC is
disabled or does not have a valid time, issue #794

### Fixes
- Fix #685: DSA conduit interface not always detected, randomly causing
major issues configuring systems with multiple switch cores
- Fix #778: reactivate OpenSSL backend for libssh/libssh2 for NanoPI R2S.
This fixes a regression in v24.10.0 causing loss of NETCONF supprt


[v24.10.1][] - 2024-10-18
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 46ffa81f5c88ce95db011369d8bfb802313e4217 Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <[email protected]>
Date: Thu, 17 Oct 2024 14:23:24 +0200
Subject: [PATCH 1/2] Only mark rdeps dirty if main service is nohup
Subject: [PATCH 1/6] Only mark rdeps dirty if main service is nohup
Organization: Addiva Elektronik

This patch changes a behavior that's been default since Finit 4.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 119e66a7e9c95283918639b51dd03a3d666955f8 Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <[email protected]>
Date: Mon, 28 Oct 2024 10:58:04 +0100
Subject: [PATCH 2/2] Reset color attributes and clear screen when starting up
Subject: [PATCH 2/6] Reset color attributes and clear screen when starting up
Organization: Addiva Elektronik

Some boot loaders, like GRUB, leave background color artifacts from
Expand Down
Loading

0 comments on commit c81b03e

Please sign in to comment.