Loader forth changes for customization
Alfred Perlstein
alfred at freebsd.org
Wed Nov 13 02:35:29 UTC 2013
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
-------------- next part --------------
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
-------------- next part --------------
: 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
;
-------------- next part --------------
loader_logo="truenas-logo"
loader_menu_title="Welcome to TrueNAS"
loader_brand="truenas-brand"
More information about the freebsd-hackers
mailing list