PERFORCE change 212921 for review

Brooks Davis brooks at FreeBSD.org
Fri Jun 15 18:32:37 UTC 2012


http://p4web.freebsd.org/@@212921?ac=10

Change 212921 by brooks at brooks_ecr_current on 2012/06/15 18:32:30

	Enhance the spinner cdoe to support overlaying images above and below
	the spinner.  Add images for boot and flashing.
	
	Add some limited ability to run a command and send the output to the
	text framebuffer.  It looks like we will really need to do some tty
	initialization there to make it useful, but the goal is to try and
	who boot messages and, more importantly, show the flash process.

Affected files ...

.. //depot/projects/ctsrd/beribsd/src/ctsrd/spinner/images/Makefile#2 edit
.. //depot/projects/ctsrd/beribsd/src/ctsrd/spinner/images/boot-bottom.png#1 add
.. //depot/projects/ctsrd/beribsd/src/ctsrd/spinner/images/boot-top.png#1 add
.. //depot/projects/ctsrd/beribsd/src/ctsrd/spinner/images/upgrade-bottom.png#1 add
.. //depot/projects/ctsrd/beribsd/src/ctsrd/spinner/images/upgrade-top.png#1 add
.. //depot/projects/ctsrd/beribsd/src/ctsrd/spinner/spinner.c#2 edit

Differences ...

==== //depot/projects/ctsrd/beribsd/src/ctsrd/spinner/images/Makefile#2 (text+ko) ====

@@ -1,7 +1,9 @@
 #	From: @(#)Makefile	8.1 (Berkeley) 6/8/93
 # $FreeBSD: src/share/misc/Makefile,v 1.27 2007/12/19 01:28:17 imp Exp $
 
-FILES=	spinner00.png \
+FILES=	boot-bottom.png \
+	boot-top.png \
+	spinner00.png \
 	spinner01.png \
 	spinner02.png \
 	spinner03.png \
@@ -12,7 +14,9 @@
 	spinner08.png \
 	spinner09.png \
 	spinner10.png \
-	spinner11.png
+	spinner11.png \
+	upgrade-bottom.png \
+	upgrade-top.png
 
 NO_OBJ=
 BINDIR?=        ${SHAREDIR}

==== //depot/projects/ctsrd/beribsd/src/ctsrd/spinner/spinner.c#2 (text+ko) ====

@@ -31,24 +31,106 @@
 
 #include <sys/types.h>
 #include <sys/param.h>
+#include <sys/wait.h>
 
 #include <de4tc.h>
 #include <err.h>
+#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <time.h>
+#include <unistd.h>
 
 #define	NSPINNERS	12
+#define IMGDIR		"/usr/share/images"
+
+const int b_height = 120;
+const int t_height = 120;
+
+static void
+usage(void)
+{
+	
+	printf("usage: spinner [-b bottom] [-t top] [cmd ...]\n");
+	exit(1);
+}
+
+static void
+clean_exit(void)
+{
+	fb_fade2off();
+}
 
+static void
+poll_child(pid_t pid)
+{
+	int	status;
+
+	if (wait4(pid, &status, WNOHANG, NULL) != 0) {
+		if (WIFEXITED(status))
+			exit(WEXITSTATUS(status));
+		if (WIFSIGNALED(status))
+			fprintf(stderr, "child killed with signal %d\n",
+			    WTERMSIG(status));
+		err(1, "wait4() unknown status 0x%x", status);
+	}
+}
 int
 main(int argc, char *argv[])
 {
-	int		i;
-	char		imgpath[MAXPATHLEN];
-	u_int32_t*	spinners[NSPINNERS];
+	int		 alpha, ch, i, ofd;
+	pid_t		 pid;
+	char		*ep;
+	char		 imgpath[MAXPATHLEN];
+	u_int32_t	*bottom, *top;
+	u_int32_t	*spinners[NSPINNERS];
 	struct timespec	stime;
 
+	alpha=127;
+	bottom=NULL;
+	top=NULL;
+	while ((ch = getopt(argc, argv, "a:b:t:")) != -1) {
+		switch (ch) {
+		case 'a':
+			alpha = strtoul(optarg, &ep, 0);
+			if (*ep != '\0' || alpha < 0 || alpha > 255)
+				err(1, "invalid alpha value %s", optarg);
+			break;
+		case 'b':
+			if (optarg[0] == '/')
+				strncpy(imgpath, optarg, sizeof(imgpath));
+			else
+				snprintf(imgpath, sizeof(imgpath), "%s/%s",
+				    IMGDIR, optarg);
+			bottom = malloc(sizeof(u_int32_t) * b_height *
+			    fb_width);
+			if (bottom == NULL)
+				err(1, "malloc");
+			read_png_file(imgpath, bottom, fb_width, b_height);
+			break;
+		case 't':
+			if (optarg[0] == '/')
+				strncpy(imgpath, optarg, sizeof(imgpath));
+			else
+				snprintf(imgpath, sizeof(imgpath), "%s/%s",
+				    IMGDIR, optarg);
+			top = malloc(sizeof(u_int32_t) * t_height *
+			    fb_width);
+			if (top == NULL)
+				err(1, "malloc");
+			read_png_file(imgpath, top, fb_width, t_height);
+			break;
+		case '?':
+		default:
+		     usage();
+		}
+	}
+	argc -= optind;
+	argv += optind;
+
 	fb_init();
+	atexit(clean_exit);
 	fb_text_cursor(255, 255);
 	fb_fade2off();
 
@@ -56,24 +138,60 @@
 		spinners[i] = malloc(sizeof(u_int32_t) * fb_width * fb_height);
 		if (spinners[i] == NULL)
 			err(1, "malloc");
+		memset(spinners[i], 0, sizeof(u_int32_t) * fb_width * fb_height);
+	}
+	fb_post(spinners[0]);
+
+	if (argc > 1) {
+		fb_fade2text(alpha);
+
+		pid = fork();
+		if (pid < 0)
+			err(1, "fork");
+		else if (pid == 0) {
+			ofd = open("/dev/ttyv0", O_WRONLY);
+			if (ofd < 0)
+				err(1, "open(/dev/ttyv0)");
+			if (dup2(ofd, 1) == -1)
+				err(1, "dup2(ofd, 1)");
+			if (dup2(ofd, 2) == -1)
+				err(1, "dup2(ofd, 2)");
+			execvp(*argv, argv);
+			err(1, "execvp");
+		}
+	} else
+		fb_fade2on();
+
+
+	for (i = 0; i < NSPINNERS; i++) {
+		poll_child(pid);
 		snprintf(imgpath, sizeof(imgpath),
-		    "/usr/share/images/spinner%02d.png", i);
+		    "%s/spinner%02d.png", IMGDIR, i);
 		read_png_file(imgpath, spinners[i], fb_width, fb_height);
+
+		/*
+		 * If they exist overlay the top and bottom images on the
+		 * spinners.
+		 */
+		if (top != NULL)
+			memcpy(spinners[i], top, sizeof(u_int32_t) * fb_width *
+			    t_height);
+		if (bottom != NULL)
+			memcpy(spinners[i] +
+			    (fb_width * (fb_height - b_height)),
+			    bottom, sizeof(u_int32_t) * fb_width * b_height);
 		fb_post(spinners[i]);
-		if (i == 0)
-			fb_fade2on();
 	}
 
 	stime.tv_sec = 0;
 	stime.tv_nsec = (1000 * 1000 * 1000) / NSPINNERS;
 	for(;;) {
-		/* Exit if a signal is received */
-		if (nanosleep(&stime, NULL) == -1)
-			break;
+		nanosleep(&stime, NULL);
 		i++;
 		if (i >= NSPINNERS)
 			i = 0;
 		fb_post(spinners[i]);
+		poll_child(pid);
 	}
 
 	fb_fade2off();


More information about the p4-projects mailing list