From owner-p4-projects@FreeBSD.ORG Fri Jun 15 18:32:36 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id ABD8C1065679; Fri, 15 Jun 2012 18:32:36 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (unknown [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6DDD11065674 for ; Fri, 15 Jun 2012 18:32:36 +0000 (UTC) (envelope-from brooks@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [69.147.83.45]) by mx1.freebsd.org (Postfix) with ESMTP id 56B578FC12 for ; Fri, 15 Jun 2012 18:32:36 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q5FIWaTq000696 for ; Fri, 15 Jun 2012 18:32:36 GMT (envelope-from brooks@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q5FIWaiX000693 for perforce@freebsd.org; Fri, 15 Jun 2012 18:32:36 GMT (envelope-from brooks@freebsd.org) Date: Fri, 15 Jun 2012 18:32:36 GMT Message-Id: <201206151832.q5FIWaiX000693@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to brooks@freebsd.org using -f From: Brooks Davis To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 212921 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Jun 2012 18:32:37 -0000 http://p4web.freebsd.org/@@212921?ac=10 Change 212921 by brooks@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 #include +#include #include #include +#include #include #include +#include #include +#include #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();