git: a2fd7ae87991 - main - stand: Print a warning of the loader is too old

From: Warner Losh <imp_at_FreeBSD.org>
Date: Mon, 29 Jul 2024 22:57:32 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=a2fd7ae87991044ca283974ced8f6ed635d1cb0c

commit a2fd7ae87991044ca283974ced8f6ed635d1cb0c
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-07-29 22:57:30 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-07-29 22:57:30 +0000

    stand: Print a warning of the loader is too old
    
    If the loader is < 3.0, print a warning that it's too old and needs to
    be upgraded.
    
    Sponsored by:           Netflix
    Reviewed by:            kevans
    Differential Revision:  https://reviews.freebsd.org/D45889
---
 stand/lua/core.lua   | 21 +++++++++++++++++++++
 stand/lua/core.lua.8 |  4 ++++
 2 files changed, 25 insertions(+)

diff --git a/stand/lua/core.lua b/stand/lua/core.lua
index 9226de564348..7b7560ddc820 100644
--- a/stand/lua/core.lua
+++ b/stand/lua/core.lua
@@ -542,6 +542,27 @@ function core.nextConsoleChoice()
 	end
 end
 
+-- Sanity check the boot loader revision
+-- Loaders with version 3.0 have everything that we need without backwards
+-- compatible hacks. Warn users that still have old versions to upgrade so
+-- that we can remove the backwards compatible hacks in the future since
+-- they have been there a long time.
+local loader_major = 3
+
+function core.loaderTooOld()
+	return loader.version == nil or loader.version < loader_major * 1000
+end
+
+if core.loaderTooOld() then
+	print("**********************************************************************")
+	print("**********************************************************************")
+	print("*****                                                            *****")
+	print("*****           BOOT LOADER IS TOO OLD. PLEASE UPGRADE.          *****")
+	print("*****                                                            *****")
+	print("**********************************************************************")
+	print("**********************************************************************")
+end
+
 recordDefaults()
 hook.register("config.reloaded", core.clearCachedKernels)
 return core
diff --git a/stand/lua/core.lua.8 b/stand/lua/core.lua.8
index 84447d7632b9..0bdf88c1a364 100644
--- a/stand/lua/core.lua.8
+++ b/stand/lua/core.lua.8
@@ -218,6 +218,10 @@ If there are no elements, this returns nil and nil.
 If there is one element, this returns the front element and an empty table.
 This will not operate on truly associative tables; numeric indices are
 required.
+.It Fn core.loaderTooOld
+Returns true if the loader is too old.
+Specifically, this means, is the loader old enough to require one or more
+workarounds in the current lua base modules.
 .El
 .Sh SEE ALSO
 .Xr loader.conf 5 ,