git: 6b0a2b19c845 - stable/13 - stand: Print a warning of the loader is too old

From: Warner Losh <imp_at_FreeBSD.org>
Date: Thu, 01 Aug 2024 14:57:37 UTC
The branch stable/13 has been updated by imp:

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

commit 6b0a2b19c84551251336efdde40f96848b199050
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-07-29 22:57:30 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-08-01 14:53:46 +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
    
    (cherry picked from commit a2fd7ae87991044ca283974ced8f6ed635d1cb0c)
---
 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 747f8c1f0fcf..81ba5d561442 100644
--- a/stand/lua/core.lua
+++ b/stand/lua/core.lua
@@ -549,6 +549,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 e1752475f942..7ab3f6e4ff12 100644
--- a/stand/lua/core.lua.8
+++ b/stand/lua/core.lua.8
@@ -224,6 +224,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 ,