Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Nov 2013 18:35:27 -0800
From:      Alfred Perlstein <alfred@freebsd.org>
To:        "Teske, Devin" <Devin.Teske@fisglobal.com>,  FreeBSD Hackers <freebsd-hackers@freebsd.org>
Subject:   Loader forth changes for customization
Message-ID:  <5282E56F.4020307@freebsd.org>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------070004070708090008010005
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hey folks,

I added some forth using Devin's help to make it easier to customize the 
FreeBSD boot loader graphics.

Diffs are here:
https://github.com/alfredperlstein/freebsd/compare/loader_custom_rc
-or-
https://github.com/alfredperlstein/freebsd/compare/loader_custom_rc.diff


Diff attached.

Also attached is a custom loader.rc file and loader.conf file that shows 
how to set the brand/logo.

Please review.

-Alfred

--------------070004070708090008010005
Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0";
 name="loader_custom_rc.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="loader_custom_rc.diff"

diff --git a/sys/boot/forth/beastie.4th b/sys/boot/forth/beastie.4th
index 4a107af..5c5a209 100644
--- a/sys/boot/forth/beastie.4th
+++ b/sys/boot/forth/beastie.4th
@@ -251,6 +251,15 @@ variable logoY
 		2drop exit
 	then
 
+	\ if it refers to a raw symbol then run that function
+	sfind if
+	    logoX @ logoY @
+	    2 roll
+	    execute
+	else
+	    drop
+	then
+
 	2drop
 ;
 
diff --git a/sys/boot/forth/brand.4th b/sys/boot/forth/brand.4th
index b6f22c8..3230953 100644
--- a/sys/boot/forth/brand.4th
+++ b/sys/boot/forth/brand.4th
@@ -87,5 +87,14 @@ variable brandY
 		2drop exit
 	then
 
+        \ if it refers to a raw symbol then run that function
+        sfind if
+            brandX @ brandY @
+            2 roll
+            execute
+        else            
+            drop
+        then
+
 	2drop
 ;
diff --git a/sys/boot/forth/loader.rc b/sys/boot/forth/loader.rc
index a84753d..86ad695e 100644
--- a/sys/boot/forth/loader.rc
+++ b/sys/boot/forth/loader.rc
@@ -8,6 +8,11 @@ include /boot/loader.4th
 \ NOTE: Change to `initialize' if you enable the below boot menu
 start
 
+\ Load in any local forth files
+only forth also support-functions
+s" /boot/loader.rc.local" source-if-exists
+only forth also
+
 \ Tests for password -- executes autoboot first if a password was defined
 check-password
 
diff --git a/sys/boot/forth/support.4th b/sys/boot/forth/support.4th
index 645e14d..c4f96b5 100644
--- a/sys/boot/forth/support.4th
+++ b/sys/boot/forth/support.4th
@@ -861,6 +861,40 @@ only forth also support-functions definitions
   throw
 ;
 
+\ Does the file exist?
+: file-exists? ( c-addr/u -- bool )
+  O_RDONLY fopen \ open file
+  dup \ save a copy to not leak
+  -1 <> if
+    fclose true
+  else
+    drop false
+  then
+;
+
+\ Source file as code if it exists.
+: source-if-exists ( c-addr/u -- ) 
+
+  2dup file-exists? if
+    \ If file exists then prepend "include" to it
+
+    \ first allocate a string, top of stack is strlen of
+    \ the filename, so just add a comfortable 15 bytes to it.
+    dup 15 +
+    allocate if ENOMEM throw then
+    0
+
+    s" include " strcat
+    \ grab the original string up so we can strcat
+    3 roll 3 roll 
+    strcat
+
+    \ evaluate " include file"
+    2dup evaluate
+    drop free
+  then
+;
+
 : print_line line_buffer strtype cr ;
 
 : print_syntax_error

--------------070004070708090008010005
Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0";
 name="loader.rc.local"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="loader.rc.local"

: truenas-logo ( x y -- ) \ "TrueNAS" logo in B/W (13 rows x 21 columns)

        5 + swap 6 + swap

        2dup at-xy ."  ______" 1+
        2dup at-xy ." |__ ___| __ _  _  ___ " 1+
        2dup at-xy ."   | | | '__|| | |/ _ \" 1+
        2dup at-xy ."   | | | | | | | /  __/" 1+
        2dup at-xy ."   | | | | | |_| |    |" 1+
        2dup at-xy ."   |_| |_| |_____|\___|" 1+
        2dup at-xy ."  _     _   __    _____" 1+
        2dup at-xy ." | \   | | /  \  /  ___|" 1+
        2dup at-xy ." |  \  | |/ /\ \|  (__" 1+
        2dup at-xy ." | |\\ | | |__| |\___ \" 1+
        2dup at-xy ." | | \\| |  __  |____) |" 1+
        2dup at-xy ." | |  \  | |  | |      |" 1+
             at-xy ." |_|   \_|_|  |_|_____/"

        \ Put the cursor back at the bottom
        0 25 at-xy
;

: truenas-brand ( x y -- ) \ "Brand" [wide] logo in B/W (7 rows x 42 columns)
  
	2dup at-xy ."  ______              _     _   __    _____  " 1+
	2dup at-xy ." |__ ___|            | \   | | /  \  /  ___|" 1+
	2dup at-xy ."   | | ____ _  __ ___|  \  | |/ /\ \|  (__" 1+
	2dup at-xy ."   | || '__|| | |/ _ \ |\\ | | |__| |\___ \" 1+
	2dup at-xy ."   | || | | | | /  __/ | \\| |  __  |____) |" 1+
	2dup at-xy ."   | || | | |_| |    | |  \  | |  | |      |" 1+
	     at-xy ."   |_||_| |_____|\___|_|   \_|_|  |_|_____/"
	\ Put the cursor back at the bottom
	0 25 at-xy
;

--------------070004070708090008010005
Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0";
 name="loader.conf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="loader.conf"

loader_logo="truenas-logo"
loader_menu_title="Welcome to TrueNAS"
loader_brand="truenas-brand"

--------------070004070708090008010005--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5282E56F.4020307>