socsvn commit: r271791 - in soc2014/seiya/bootsplash/sys: conf dev/fb geom/eli kern sys
seiya at FreeBSD.org
seiya at FreeBSD.org
Sun Aug 3 12:15:18 UTC 2014
Author: seiya
Date: Sun Aug 3 12:15:15 2014
New Revision: 271791
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271791
Log:
support prompting for geom_eli
This commit adds new functions named prompt_*(). When you boot without
bsplash, it makes no difference. When you boot with it, it displays
prompt screens.
Also, it makes changes in geom/eli/g_eli.c to use those functions instead
of printf().
Added:
soc2014/seiya/bootsplash/sys/kern/subr_prompt.c
soc2014/seiya/bootsplash/sys/sys/prompt.h
Modified:
soc2014/seiya/bootsplash/sys/conf/files
soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c
soc2014/seiya/bootsplash/sys/dev/fb/bsplash.h
soc2014/seiya/bootsplash/sys/geom/eli/g_eli.c
Modified: soc2014/seiya/bootsplash/sys/conf/files
==============================================================================
--- soc2014/seiya/bootsplash/sys/conf/files Sun Aug 3 11:43:14 2014 (r271790)
+++ soc2014/seiya/bootsplash/sys/conf/files Sun Aug 3 12:15:15 2014 (r271791)
@@ -2971,6 +2971,7 @@
kern/subr_power.c standard
kern/subr_prf.c standard
kern/subr_prof.c standard
+kern/subr_prompt.c standard
kern/subr_rman.c standard
kern/subr_rtc.c standard
kern/subr_sbuf.c standard
Modified: soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c
==============================================================================
--- soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c Sun Aug 3 11:43:14 2014 (r271790)
+++ soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c Sun Aug 3 12:15:15 2014 (r271791)
@@ -34,6 +34,7 @@
#include <sys/libkern.h>
#include <sys/systm.h>
#include <sys/param.h>
+#include <sys/prompt.h>
#include <sys/kthread.h>
#include <dev/fb/bmp.h>
@@ -47,11 +48,12 @@
#define SCREEN_HEIGHT 768
static void update_animation(void *unused);
-static int load_bmp(video_adapter_t *adp, BMP_INFO *bmp_info, void* data);
-static int draw_bmp(int iy, int sy, int sx, int width, int height);
+static int load_bmp(BMP_INFO *bmp, void* data);
+static int draw_bmp(BMP_INFO *bmp, int iy, int sy, int sx, int width, int height);
static video_adapter_t *adp = NULL;
static BMP_INFO bmp_info;
+static int in_prompt = 0;
static int background_enabled = 1; // 1:enabled, 0:disabled
static int background_y_origin;
static int animation_enabled = 1; // 1:enabled, 0:disabled
@@ -242,7 +244,7 @@
p = preload_fetch_addr(image);
- if (load_bmp(adp, &bmp_info, p) != 0){
+ if (load_bmp(&bmp_info, p) != 0){
printf("bsplash: failed to load BMP\n");
return 1;
}
@@ -256,7 +258,8 @@
/*
* draw background
*/
- if (background_enabled && draw_bmp(background_y_origin, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) != 0){
+ if (background_enabled &&
+ draw_bmp(&bmp_info, background_y_origin, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) != 0){
printf("bsplash: failed to draw BMP (background)\n");
return 1;
}
@@ -282,74 +285,134 @@
iy = animation_y_origin;
for (;;){
// update animation
- if(!stop_animation){
- if (draw_bmp(iy, animation_y, animation_x, animation_width,
- animation_height) == 0){
- iy += animation_height;
- } else {
- if (!repeat_animation){
- stop_animation = 1;
+ if(!in_prompt){
+ if(!stop_animation){
+ if (draw_bmp(&bmp_info, iy, animation_y, animation_x,
+ animation_width, animation_height) == 0){
+ iy += animation_height;
} else {
- iy = animation_y_origin;
- // try again
- if (draw_bmp(iy, animation_y, animation_x, animation_width,
- animation_height) == 0)
- iy += animation_height;
+ if (!repeat_animation){
+ stop_animation = 1;
+ } else {
+ iy = animation_y_origin;
+ // try again
+ if (draw_bmp(&bmp_info, iy, animation_y, animation_x,
+ animation_width, animation_height) == 0)
+ iy += animation_height;
+ }
}
}
- }
- // get the progress of boot
- if ((s = getenv("BOOT_PROGRESS")) != NULL){
- progress = strtol(s, NULL, 10);
- freeenv(s);
- }
+ // get the progress of boot
+ if ((s = getenv("BOOT_PROGRESS")) != NULL){
+ progress = strtol(s, NULL, 10);
+ freeenv(s);
+ }
- // update the progress bar
- draw_bmp(progress_bar_y_origin + ((progress / 10) * progress_bar_height),
- progress_bar_y, progress_bar_x, progress_bar_width, progress_bar_height);
-
- if (progress >= 100 /* boot has finished */ || count > 50 /* FIX<E */){
- /* terminate boot splash */
- vidd_set_mode(adp, M_TEXT_80x25);
- kthread_exit();
+ // update the progress bar
+ draw_bmp(&bmp_info, progress_bar_y_origin + ((progress / 10) * progress_bar_height),
+ progress_bar_y, progress_bar_x, progress_bar_width, progress_bar_height);
+
+ if (progress >= 100 /* boot has finished */ || count > 50 /* FIX<E */){
+ /* terminate boot splash */
+ vidd_set_mode(adp, M_TEXT_80x25);
+ kthread_exit();
+ }
}
-
count++;
pause("bsplash", 3*hz /* FIXME: this is because draw_bmp() takes too long time */);
}
}
+int
+bsplash_prompt_user(const char *tag)
+{
+ char env_name[64];
+ char *s;
+ int y_origin;
+
+ in_prompt = 1;
+ snprintf(env_name, sizeof(env_name), "bsplash_%s_prompt_y_origin", tag);
+
+ if ((s = getenv((const char *) env_name)) == NULL) {
+ return 1;
+ } else {
+ y_origin = strtol(s, NULL, 10);
+ }
+ freeenv(s);
+
+ if (draw_bmp(&bmp_info, y_origin, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) != 0){
+ printf("bsplash: failed to draw BMP (tag: %s)\n", tag);
+ return 1;
+ }
+
+ return 0;
+}
+
+int
+bsplash_prompt_failure(const char *tag)
+{
+ char env_name[64];
+ char *s;
+ int y_origin;
+
+ snprintf(env_name, sizeof(env_name), "bsplash_%s_failure_y_origin", tag);
+
+ if ((s = getenv((const char *) env_name)) == NULL) {
+ return 1;
+ } else {
+ y_origin = strtol(s, NULL, 10);
+ }
+ freeenv(s);
+
+ if (draw_bmp(&bmp_info, y_origin, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) != 0){
+ printf("bsplash: failed to draw BMP (tag: %s)\n", tag);
+ return 1;
+ }
+
+ return 0;
+}
+
+int
+bsplash_prompt_success(const char *tag)
+{
+ if (draw_bmp(&bmp_info, background_y_origin, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) != 0){
+ printf("bsplash: failed to draw BMP (background)\n");
+ in_prompt = 0;
+ return 1;
+ }
+
+ in_prompt = 0;
+ return 0;
+}
+
+
static int
-load_bmp(video_adapter_t *adp, BMP_INFO *bmp_info, void* data)
+load_bmp(BMP_INFO *bmp, void* data)
{
video_info_t info;
if (vidd_get_info(adp, M_VESA_CG1024x768, &info) != 0)
return 1;
- if (bmp_init(bmp_info, (u_char *)data, info.vi_width,
+ if (bmp_init(bmp, (u_char *)data, info.vi_width,
info.vi_height, info.vi_depth) != 0)
return 1;
return 0;
}
-
static int
-draw_bmp(int iy, int sy, int sx, int width, int height)
+draw_bmp(BMP_INFO *bmp, int iy, int sy, int sx, int width, int height)
{
- if (bmp_draw(adp, &bmp_info, sx, sy, iy, width, height) != 0)
+ if (bmp_draw(adp, bmp, sx, sy, iy, width, height) != 0)
return 1;
return 0;
}
-static void bsplash_uninit (void){
-}
-
static int modevent(module_t mod, int type, void *data)
{
@@ -358,7 +421,6 @@
bsplash_init();
break;
case MOD_UNLOAD:
- bsplash_uninit();
break;
default:
return EOPNOTSUPP;
Modified: soc2014/seiya/bootsplash/sys/dev/fb/bsplash.h
==============================================================================
--- soc2014/seiya/bootsplash/sys/dev/fb/bsplash.h Sun Aug 3 11:43:14 2014 (r271790)
+++ soc2014/seiya/bootsplash/sys/dev/fb/bsplash.h Sun Aug 3 12:15:15 2014 (r271791)
@@ -27,6 +27,11 @@
#ifndef _FB_BSPLASH_H_
#define _FB_BSPLASH_H_
+#include <sys/fbio.h>
+
int bsplash_early_init (video_adapter_t *adp);
+int bsplash_prompt_user (const char *tag);
+int bsplash_prompt_success (const char *tag);
+int bsplash_prompt_failure (const char *tag);
#endif
Modified: soc2014/seiya/bootsplash/sys/geom/eli/g_eli.c
==============================================================================
--- soc2014/seiya/bootsplash/sys/geom/eli/g_eli.c Sun Aug 3 11:43:14 2014 (r271790)
+++ soc2014/seiya/bootsplash/sys/geom/eli/g_eli.c Sun Aug 3 12:15:15 2014 (r271791)
@@ -42,6 +42,7 @@
#include <sys/eventhandler.h>
#include <sys/kthread.h>
#include <sys/proc.h>
+#include <sys/prompt.h>
#include <sys/sched.h>
#include <sys/smp.h>
#include <sys/uio.h>
@@ -1090,9 +1091,9 @@
/* Ask for the passphrase if defined. */
if (md.md_iterations >= 0) {
- printf("Enter passphrase for %s: ", pp->name);
- cngets(passphrase, sizeof(passphrase),
- g_eli_visible_passphrase);
+ prompt_user("geli_passphrase", passphrase, sizeof(passphrase),
+ g_eli_visible_passphrase,
+ "Enter passphrase for %s: ", pp->name);
}
/*
@@ -1131,6 +1132,7 @@
}
G_ELI_DEBUG(0, "Wrong key for %s. Tries left: %u.",
pp->name, tries - i - 1);
+ prompt_failure("geli_passphrase", "Incorrect passphrase, try again.");
/* Try again. */
continue;
} else if (error > 0) {
@@ -1155,6 +1157,8 @@
G_ELI_SUFFIX);
return (NULL);
}
+
+ prompt_success("geli_passphrase", "");
return (gp);
}
Added: soc2014/seiya/bootsplash/sys/kern/subr_prompt.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2014/seiya/bootsplash/sys/kern/subr_prompt.c Sun Aug 3 12:15:15 2014 (r271791)
@@ -0,0 +1,88 @@
+/*-
+ * Copyright 2014 Seiya Nuta <seiya at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_bsplash.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <machine/stdarg.h>
+#include <sys/cons.h>
+#include <sys/prompt.h>
+#include <dev/fb/bsplash.h>
+
+char *
+prompt_user(const char *tag, char *buf, size_t size, int echo, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+
+#if DEV_BSPLASH
+ bsplash_prompt_user(tag);
+#endif
+
+ cngets(buf, size, echo);
+ return buf;
+}
+
+void
+prompt_success(const char *tag, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+ printf("\n");
+
+#if DEV_BSPLASH
+ bsplash_prompt_success(tag);
+#endif
+}
+
+void
+prompt_failure(const char *tag, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+ printf("\n");
+
+#if DEV_BSPLASH
+ bsplash_prompt_failure(tag);
+#endif
+}
Added: soc2014/seiya/bootsplash/sys/sys/prompt.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2014/seiya/bootsplash/sys/sys/prompt.h Sun Aug 3 12:15:15 2014 (r271791)
@@ -0,0 +1,37 @@
+/*-
+ * Copyright 2014 Seiya Nuta <seiya at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _SYS_PROMPT_H_
+#define _SYS_PROMPT_H_
+
+char *prompt_user(const char *tag, char *buf, size_t size, int echo, const char *fmt, ...);
+void prompt_success(const char *tag, const char *fmt, ...);
+void prompt_failure(const char *tag, const char *fmt, ...);
+
+#endif /* !_SYS_PROMPT_H_ */
More information about the svn-soc-all
mailing list