git: 53a4bf76c57b - stable/14 - stand: Print a warning of the loader is too old

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

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

commit 53a4bf76c57bc02dce7c521235d10dc7fec298a0
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:49:54 +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 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 e12f80671c00..208dbf5e12c9 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 ,