1 34 files changed, 1687 insertions(+), 235 deletions(-)
3 diff --git a/Makefile.in b/Makefile.in
4 index 01771db..23135aa 100644
7 @@ -21,7 +21,12 @@ ENABLE_PS3 = @ENABLE_PS3@
11 +INSTALL_DATA = @INSTALL_DATA@
12 +INSTALL_PROGRAM = @INSTALL_PROGRAM@
13 +INSTALL_SCRIPT = @INSTALL_SCRIPT@
14 +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
20 @@ -34,5 +39,6 @@ localstatedir = @localstatedir@
23 top_srcdir = @top_srcdir@
26 include $(top_srcdir)/rules.mk
27 diff --git a/configure.ac b/configure.ac
28 index cb43f8c..fa40f34 100644
31 @@ -35,9 +35,7 @@ AC_ARG_ENABLE([ps3],
35 -AS_IF([test "x$enable_ps3" != xno],
36 - [AC_SUBST([ENABLE_PS3], ["y"])],
37 - [AC_SUBST([ENABLE_PS3], ["n"])])
38 +AS_IF([test "x$enable_ps3" != xno], [AC_SUBST([ENABLE_PS3], ["y"])], [])
41 [AS_HELP_STRING([--with-twin],
42 diff --git a/discover/kboot-parser.c b/discover/kboot-parser.c
43 index e688c22..7c7cb5d 100644
44 --- a/discover/kboot-parser.c
45 +++ b/discover/kboot-parser.c
46 @@ -133,10 +133,11 @@ static int kboot_parse(struct discover_context *dc)
47 conf = talloc_zero(dc, struct conf_context);
54 conf->global_options = kboot_global_options,
55 + conf_init_global_options(conf);
56 conf->conf_files = kboot_conf_files,
57 conf->process_pair = kboot_process_pair;
58 conf->parser_info = (void *)kboot_ignored_names,
59 diff --git a/discover/parser-conf.c b/discover/parser-conf.c
60 index 14f847d..88e96b7 100644
61 --- a/discover/parser-conf.c
62 +++ b/discover/parser-conf.c
63 @@ -121,6 +121,18 @@ int conf_param_in_list(const char *const *list, const char *param)
67 + * conf_init_global_options - Zero the global option table.
70 +void conf_init_global_options(struct conf_context *conf)
74 + for (i = 0; conf->global_options[i].name; i++)
75 + conf->global_options[i].value = NULL;
79 * conf_set_global_option - Set a value in the global option table.
81 * Check if an option (name=value) is a global option. If so, store it in
82 @@ -136,7 +148,7 @@ int conf_set_global_option(struct conf_context *conf, const char *name,
83 if (streq(name, conf->global_options[i].name)) {
84 conf->global_options[i].value
85 = talloc_strdup(conf, value);
86 - pb_log("%s: %s:%s\n", __func__, name, value);
87 + pb_log("%s: @%s@%s@\n", __func__, name, value);
91 @@ -158,8 +170,11 @@ const char *conf_get_global_option(struct conf_context *conf,
94 for (i = 0; conf->global_options[i].name ;i++)
95 - if (streq(name, conf->global_options[i].name))
96 + if (streq(name, conf->global_options[i].name)) {
97 + pb_log("%s: @%s@%s@\n", __func__, name,
98 + conf->global_options[i].value);
99 return conf->global_options[i].value;
102 assert(0 && "unknown global name");
104 diff --git a/discover/parser-conf.h b/discover/parser-conf.h
105 index 09015d1..3325faf 100644
106 --- a/discover/parser-conf.h
107 +++ b/discover/parser-conf.h
108 @@ -41,6 +41,7 @@ struct conf_context {
109 int conf_parse(struct conf_context *conf);
110 char *conf_get_param_pair(char *str, char **name_out, char **value_out,
112 +void conf_init_global_options(struct conf_context *conf);
113 const char *conf_get_global_option(struct conf_context *conf,
115 int conf_set_global_option(struct conf_context *conf, const char *name,
116 diff --git a/discover/parser.c b/discover/parser.c
117 index 2b4ddd2..8f2735c 100644
118 --- a/discover/parser.c
119 +++ b/discover/parser.c
120 @@ -13,16 +13,16 @@ extern struct parser __start_parsers[], __stop_parsers[];
121 void iterate_parsers(struct discover_context *ctx)
123 struct parser *parser;
124 + unsigned int count = 0;
126 pb_log("trying parsers for %s\n", ctx->device_path);
128 for (parser = __start_parsers; parser < __stop_parsers; parser++) {
129 pb_log("\ttrying parser '%s'\n", parser->name);
130 - /* just use a dummy device path for now */
131 - if (parser->parse(ctx))
133 + count += parser->parse(ctx);
135 - pb_log("\tno boot_options found\n");
137 + pb_log("\tno boot_options found\n");
140 static int compare_parsers(const void *a, const void *b)
141 diff --git a/discover/paths.c b/discover/paths.c
142 index 8e2a361..fe7a876 100644
143 --- a/discover/paths.c
144 +++ b/discover/paths.c
145 @@ -81,14 +81,6 @@ char *parse_device_path(void *alloc_ctx,
146 if (is_prefix(dev_str, "/dev/"))
147 dev_str += strlen("/dev/");
149 - /* PS3 hack: if we're reading from a ps3dx device, and we refer to
150 - * a sdx device, remap to ps3dx */
151 - if (cur_dev && is_prefix(cur_dev, "/dev/ps3d")
152 - && is_prefix(dev_str, "sd")) {
153 - snprintf(tmp, 255, "ps3d%s", dev_str + 2);
157 return join_paths(alloc_ctx, "/dev", dev_str);
160 diff --git a/discover/pb-discover.c b/discover/pb-discover.c
161 index d7ea0ca..bd515e3 100644
162 --- a/discover/pb-discover.c
163 +++ b/discover/pb-discover.c
166 +#if defined(HAVE_CONFIG_H)
176 #include "discover-server.h"
177 #include "device-handler.h"
179 +static void print_version(void)
181 + printf("pb-discover (" PACKAGE_NAME ") " PACKAGE_VERSION "\n");
184 +static void print_usage(void)
188 +"Usage: pb-discover [-h, --help] [-l, --log log-file] [-V, --version]\n");
192 + * enum opt_value - Tri-state options variables.
195 +enum opt_value {opt_undef = 0, opt_yes, opt_no};
198 + * struct opts - Values from command line options.
202 + enum opt_value show_help;
203 + const char *log_file;
204 + enum opt_value show_version;
208 + * opts_parse - Parse the command line options.
211 +static int opts_parse(struct opts *opts, int argc, char *argv[])
213 + static const struct option long_options[] = {
214 + {"help", no_argument, NULL, 'h'},
215 + {"log", required_argument, NULL, 'l'},
216 + {"version", no_argument, NULL, 'V'},
217 + { NULL, 0, NULL, 0},
219 + static const char short_options[] = "hl:V";
220 + static const struct opts default_values = {
221 + .log_file = "pb-discover.log",
224 + *opts = default_values;
227 + int c = getopt_long(argc, argv, short_options, long_options,
235 + opts->show_help = opt_yes;
238 + opts->log_file = optarg;
241 + opts->show_version = opt_yes;
244 + opts->show_help = opt_yes;
249 + return optind != argc;
254 static void sigint_handler(int __attribute__((unused)) signum)
255 @@ -18,15 +96,31 @@ static void sigint_handler(int __attribute__((unused)) signum)
260 +int main(int argc, char *argv[])
262 struct device_handler *handler;
263 struct discover_server *server;
266 struct user_event *uev;
269 - log = fopen("pb-discover.log", "a");
270 + if (opts_parse(&opts, argc, argv)) {
272 + return EXIT_FAILURE;
275 + if (opts.show_help == opt_yes) {
277 + return EXIT_SUCCESS;
280 + if (opts.show_version == opt_yes) {
282 + return EXIT_SUCCESS;
285 + log = fopen(opts.log_file, "a");
287 pb_log_set_stream(log);
289 diff --git a/discover/yaboot-parser.c b/discover/yaboot-parser.c
290 index d9f2aff..6101cd8 100644
291 --- a/discover/yaboot-parser.c
292 +++ b/discover/yaboot-parser.c
293 @@ -15,7 +15,6 @@ struct yaboot_state {
294 struct boot_option *opt;
295 const char *desc_image;
299 const char *const *known_names;
301 @@ -56,6 +55,19 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name,
304 struct yaboot_state *state = conf->parser_info;
305 + struct fixed_pair {
307 + const char *initrd;
309 + static const struct fixed_pair suse_fp32 = {
310 + .image = "/suseboot/vmlinux32",
311 + .initrd = "/suseboot/initrd32",
313 + static const struct fixed_pair suse_fp64 = {
314 + .image = "/suseboot/vmlinux64",
315 + .initrd = "/suseboot/initrd64",
317 + const struct fixed_pair *suse_fp;
319 /* fixup for bare values */
321 @@ -73,32 +85,70 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name,
324 if (streq(name, "image")) {
325 + const char *g_boot = conf_get_global_option(conf, "boot");
326 + const char *g_part = conf_get_global_option(conf, "partition");
328 + /* First finish any previous image. */
330 if (state->opt->boot_image_file)
333 - state->opt->boot_image_file = resolve_path(state->opt, value,
334 - conf->dc->device_path);
335 - state->desc_image = talloc_strdup(state->opt, value);
336 + /* Then start the new image. */
338 + if (g_boot && g_part) {
339 + char* dev = talloc_asprintf(NULL, "%s%s", g_boot,
342 + state->opt->boot_image_file = resolve_path(state->opt,
344 + state->desc_image = talloc_asprintf(state->opt,
345 + "%s%s", dev, value);
347 + } else if (g_boot) {
348 + state->opt->boot_image_file = resolve_path(state->opt,
350 + state->desc_image = talloc_asprintf(state->opt,
351 + "%s%s", g_boot, value);
353 + state->opt->boot_image_file = resolve_path(state->opt,
354 + value, conf->dc->device_path);
355 + state->desc_image = talloc_strdup(state->opt, value);
361 - if (streq(name, "image[32bit]") || streq(name, "image[64bit]")) {
362 - state->found_suse = 1;
363 + /* Special processing for SUSE install CD. */
365 + if (streq(name, "image[32bit]"))
366 + suse_fp = &suse_fp32;
367 + else if (streq(name, "image[64bit]"))
368 + suse_fp = &suse_fp64;
373 + /* First finish any previous image. */
375 if (state->opt->boot_image_file)
378 + /* Then start the new image. */
381 state->opt->boot_image_file = resolve_path(state->opt,
382 value, conf->dc->device_path);
383 state->desc_image = talloc_strdup(state->opt, value);
386 - asprintf(&s, "/suseboot/%s", value);
387 state->opt->boot_image_file = resolve_path(state->opt,
388 - s, conf->dc->device_path);
389 - state->desc_image = talloc_strdup(state->opt, s);
391 + suse_fp->image, conf->dc->device_path);
392 + state->desc_image = talloc_strdup(state->opt,
395 + state->opt->initrd_file = resolve_path(state->opt,
396 + suse_fp->initrd, conf->dc->device_path);
397 + state->desc_initrd = talloc_asprintf(state, "initrd=%s",
402 @@ -112,19 +162,28 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name,
405 if (streq(name, "initrd")) {
406 - if (!state->found_suse || (*value == '/')) {
407 + const char *g_boot = conf_get_global_option(conf, "boot");
408 + const char *g_part = conf_get_global_option(conf, "partition");
410 + if (g_boot && g_part) {
411 + char* dev = talloc_asprintf(NULL, "%s%s", g_boot,
414 state->opt->initrd_file = resolve_path(state->opt,
415 - value, conf->dc->device_path);
416 - state->desc_initrd = talloc_asprintf(state, "initrd=%s",
419 + state->desc_initrd = talloc_asprintf(state,
420 + "initrd=%s%s", dev, value);
422 + } else if (g_boot) {
423 + state->opt->initrd_file = resolve_path(state->opt,
425 + state->desc_initrd = talloc_asprintf(state,
426 + "initrd=%s%s", g_boot, value);
429 - asprintf(&s, "/suseboot/%s", value);
430 state->opt->initrd_file = resolve_path(state->opt,
431 - s, conf->dc->device_path);
432 + value, conf->dc->device_path);
433 state->desc_initrd = talloc_asprintf(state, "initrd=%s",
440 @@ -236,10 +295,11 @@ static int yaboot_parse(struct discover_context *dc)
441 conf = talloc_zero(dc, struct conf_context);
448 conf->global_options = yaboot_global_options,
449 + conf_init_global_options(conf);
450 conf->conf_files = yaboot_conf_files,
451 conf->process_pair = yaboot_process_pair;
452 conf->finish = yaboot_finish;
453 diff --git a/lib/system/system.c b/lib/system/system.c
454 index 380dded..7371445 100644
455 --- a/lib/system/system.c
456 +++ b/lib/system/system.c
465 @@ -19,6 +20,7 @@ const struct pb_system_apps pb_system_apps = {
467 .kexec = "/sbin/kexec",
468 .mount = "/bin/mount",
469 + .shutdown = "/sbin/shutdown",
470 .sftp = "/usr/bin/sftp",
471 .tftp = "/usr/bin/tftp",
472 .umount = "/bin/umount",
473 @@ -104,13 +106,13 @@ int pb_rmdir_recursive(const char *base, const char *dir)
475 int pb_run_cmd(const char *const *cmd_argv)
488 const char *const *p = cmd_argv;
489 @@ -125,12 +127,23 @@ int pb_run_cmd(const char *const *cmd_argv)
490 pb_log("%s: %s\n", __func__, cmd_argv[0]);
495 pb_log("%s: fork failed: %s\n", __func__, strerror(errno));
500 + int log = fileno(pb_log_get_stream());
502 + /* Redirect child output to log. */
504 + status = dup2(log, STDOUT_FILENO);
505 + assert(status != -1);
507 + status = dup2(log, STDERR_FILENO);
508 + assert(status != -1);
510 execvp(cmd_argv[0], (char *const *)cmd_argv);
511 pb_log("%s: exec failed: %s\n", __func__, strerror(errno));
513 diff --git a/lib/system/system.h b/lib/system/system.h
514 index 47c7c02..1918309 100644
515 --- a/lib/system/system.h
516 +++ b/lib/system/system.h
517 @@ -5,6 +5,7 @@ struct pb_system_apps {
521 + const char *shutdown;
525 diff --git a/man/pb-cui.8 b/man/pb-cui.8
527 index 0000000..e671c20
531 +.\" Copyright (C) 2009 Sony Computer Entertainment Inc.
532 +.\" Copyright 2009 Sony Corp.
534 +.\" This program is free software; you can redistribute it and/or modify
535 +.\" it under the terms of the GNU General Public License as published by
536 +.\" the Free Software Foundation; version 2 of the License.
538 +.\" This program is distributed in the hope that it will be useful,
539 +.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
540 +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
541 +.\" GNU General Public License for more details.
543 +.\" You should have received a copy of the GNU General Public License
544 +.\" along with this program; if not, write to the Free Software
545 +.\" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
547 +.\" Maintainer's Notes:
548 +.\" * For syntax help see the man pages for 'mdoc' and 'mdoc.samples'.
549 +.\" * To check syntax use this:
550 +.\" 'groff -C -mtty-char -Tutf8 -man pb-cui.8'.
551 +.\" * To check format use this: 'less pb-cui.8'.
560 +.Nd Petitboot ncurses bootloader UI
566 +.Op Fl l, -log Ar log-file
571 +pb-cui is an ncurses based interface to the Petitboot bootloader.
573 +Petitboot is a Linux kexec based bootloader that supports loading Linux
574 +kernel and initrd images from any device that can be mounted by Linux.
575 +It can also load images from the network using the
576 +HTTP, HTTPS, NFS, SFTP, and TFTP
581 +.Bl -tag -width indent
584 +Print a help message.
586 +.It Fl l, -log Ar log-file
587 +Log messages to the file
589 +The default log is a file pb-cui.log in the directory where pb-cui
590 +is started. New messages are appended to an existing log file.
593 +Display the program version number.
597 +.Xr petitboot 8 , Xr pb-discover 8 , Xr pb-event 8
598 diff --git a/man/pb-discover.8 b/man/pb-discover.8
600 index 0000000..9123e0f
602 +++ b/man/pb-discover.8
604 +.\" Copyright (C) 2009 Sony Computer Entertainment Inc.
605 +.\" Copyright 2009 Sony Corp.
607 +.\" This program is free software; you can redistribute it and/or modify
608 +.\" it under the terms of the GNU General Public License as published by
609 +.\" the Free Software Foundation; version 2 of the License.
611 +.\" This program is distributed in the hope that it will be useful,
612 +.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
613 +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
614 +.\" GNU General Public License for more details.
616 +.\" You should have received a copy of the GNU General Public License
617 +.\" along with this program; if not, write to the Free Software
618 +.\" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
620 +.\" Maintainer's Notes:
621 +.\" * For syntax help see the man pages for 'mdoc' and 'mdoc.samples'.
622 +.\" * To check syntax use this:
623 +.\" 'groff -C -mtty-char -Tutf8 -man pb-discover.8'.
624 +.\" * To check format use this: 'less pb-discover.8'.
633 +.Nd The dynamic device discovery daemon of the Petitboot bootloader
641 +pb-discover maintains a dynamic list of boot options available to
642 +the system. On startup, the petitboot user interface clients connect to
643 +pb-discover daemon and receive boot option information.
647 +.Xr petitboot 8 , Xr pb-cui 8 , Xr pb-event 8
648 diff --git a/man/pb-event.8 b/man/pb-event.8
650 index 0000000..dc123e1
654 +.\" Copyright (C) 2009 Sony Computer Entertainment Inc.
655 +.\" Copyright 2009 Sony Corp.
657 +.\" This program is free software; you can redistribute it and/or modify
658 +.\" it under the terms of the GNU General Public License as published by
659 +.\" the Free Software Foundation; version 2 of the License.
661 +.\" This program is distributed in the hope that it will be useful,
662 +.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
663 +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
664 +.\" GNU General Public License for more details.
666 +.\" You should have received a copy of the GNU General Public License
667 +.\" along with this program; if not, write to the Free Software
668 +.\" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
670 +.\" Maintainer's Notes:
671 +.\" * For syntax help see the man pages for 'mdoc' and 'mdoc.samples'.
672 +.\" * To check syntax use this:
673 +.\" 'groff -C -mtty-char -Tutf8 -man pb-event.8'.
674 +.\" * To check format use this: 'less pb-event.8'.
683 +.Nd Event helper for the Petitboot bootloader
691 +The pb-event utility is used to send user mode events to pb-discover, the
692 +petitboot device discovery daemon.
696 +.Xr petitboot 8 , Xr pb-cui 8 , Xr pb-discover 8
697 diff --git a/man/petitboot.8 b/man/petitboot.8
699 index 0000000..9dc2222
701 +++ b/man/petitboot.8
703 +.\" Copyright (C) 2009 Sony Computer Entertainment Inc.
704 +.\" Copyright 2009 Sony Corp.
706 +.\" This program is free software; you can redistribute it and/or modify
707 +.\" it under the terms of the GNU General Public License as published by
708 +.\" the Free Software Foundation; version 2 of the License.
710 +.\" This program is distributed in the hope that it will be useful,
711 +.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
712 +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
713 +.\" GNU General Public License for more details.
715 +.\" You should have received a copy of the GNU General Public License
716 +.\" along with this program; if not, write to the Free Software
717 +.\" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
719 +.\" Maintainer's Notes:
720 +.\" * For syntax help see the man pages for 'mdoc' and 'mdoc.samples'.
721 +.\" * To check syntax use this:
722 +.\" 'groff -C -mtty-char -Tutf8 -man petitboot.8'.
723 +.\" * To check format use this: 'less petitboot.8'.
732 +.Nd The Petitboot bootloader
736 +Petitboot is a platform independent bootloader based on Linux kexec.
737 +Petitboot can load Linux kernel and initrd images from any device that
738 +can be mounted by Linux, and can also load images from the network
740 +HTTP, HTTPS, NFS, SFTP, and TFTP
743 +Petitboot looks for bootloader configuration files on mountable devices
744 +in the system, and can also be configured to use boot information
749 +.Xr pb-cui 8 , Xr pb-discover 8 , Xr pb-event 8
750 diff --git a/rules.mk b/rules.mk
751 index e743338..3b1dcfe 100644
754 @@ -19,8 +19,8 @@ parser_test = test/parser-test
755 # install targets and components
756 daemons = $(pb_discover)
757 parsers = event kboot yaboot
758 -uis = $(pb_cui) $(pb_test)
759 -tests = $(parser_test)
761 +tests = $(parser_test) $(pb_test)
765 @@ -29,6 +29,7 @@ endif
768 artwork = background.jpg cdrom.png hdd.png usbpen.png tux.png cursor.gz
769 +man8 = pb-cui.8 pb-discover.8 pb-event.8 petitboot.8
770 rules = utils/99-petitboot.rules
771 udhcpc = utils/udhcpc
773 @@ -48,10 +49,11 @@ discover_objs = discover/event.o discover/user-event.o discover/udev.o \
774 discover/parser-utils.o
777 -ui_common_objs = ui/common/discover-client.o ui/common/loader.o \
778 - ui/common/ui-system.o ui/common/url.o
779 -ncurses_objs = ui/ncurses/nc-scr.o ui/ncurses/nc-menu.o \
780 - ui/ncurses/nc-ked.o ui/ncurses/nc-cui.o
781 +ui_common_objs = ui/common/discover-client.o ui/common/joystick.o \
782 + ui/common/loader.o ui/common/ui-system.o ui/common/timer.o \
784 +ncurses_objs = ui/ncurses/nc-scr.o ui/ncurses/nc-menu.o ui/ncurses/nc-ked.o \
785 + ui/ncurses/nc-cui.o
786 twin_objs = ui/twin/pb-twin.o
789 @@ -68,6 +70,7 @@ client_objs = $(lib_objs) $(ui_common_objs)
790 all: $(uis) $(daemons) $(utils)
793 +pb_cui_objs-y$(ENABLE_PS3) += ui/ncurses/pb-cui.o
794 pb_cui_objs-$(ENABLE_PS3) += ui/ncurses/ps3-cui.o ui/common/ps3.o
795 pb_cui_ldflags-$(ENABLE_PS3) += -lps3-utils
797 @@ -120,13 +123,16 @@ parser-test: $(parser_test)
799 install: all $(rules) $(udhcpc)
800 $(INSTALL) -d $(DESTDIR)$(sbindir)/
801 - $(INSTALL) $(daemons) $(uis) $(utils) $(DESTDIR)$(sbindir)/
802 + $(INSTALL_PROGRAM) $(daemons) $(uis) $(utils) $(DESTDIR)$(sbindir)/
803 $(INSTALL) -d $(DESTDIR)$(pkgdatadir)/artwork/
804 - $(INSTALL) $(addprefix $(top_srcdir)/ui/twin/artwork/,$(artwork)) \
805 + $(INSTALL_DATA) $(addprefix $(top_srcdir)/ui/twin/artwork/,$(artwork)) \
806 $(DESTDIR)$(pkgdatadir)/artwork/
807 $(INSTALL) -d $(DESTDIR)$(pkgdatadir)/utils
808 - $(INSTALL) -m 644 $(top_srcdir)/$(rules) $(DESTDIR)$(pkgdatadir)/utils
809 - $(INSTALL) -m 644 $(top_srcdir)/$(udhcpc) $(DESTDIR)$(pkgdatadir)/utils
810 + $(INSTALL_DATA) $(top_srcdir)/$(rules) $(DESTDIR)$(pkgdatadir)/utils
811 + $(INSTALL_DATA) $(top_srcdir)/$(udhcpc) $(DESTDIR)$(pkgdatadir)/utils
812 + $(INSTALL) -d $(DESTDIR)$(mandir)/man8/
813 + $(INSTALL_DATA) $(addprefix $(top_srcdir)/man/, $(man8)) \
814 + $(DESTDIR)$(mandir)/man8/
816 dist: $(PACKAGE)-$(VERSION).tar.gz
818 diff --git a/ui/common/joystick.c b/ui/common/joystick.c
820 index 0000000..94c85fe
822 +++ b/ui/common/joystick.c
825 + * Copyright (C) 2009 Sony Computer Entertainment Inc.
826 + * Copyright 2009 Sony Corp.
828 + * This program is free software; you can redistribute it and/or modify
829 + * it under the terms of the GNU General Public License as published by
830 + * the Free Software Foundation; version 2 of the License.
832 + * This program is distributed in the hope that it will be useful,
833 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
834 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
835 + * GNU General Public License for more details.
837 + * You should have received a copy of the GNU General Public License
838 + * along with this program; if not, write to the Free Software
839 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
842 +#if defined(HAVE_CONFIG_H)
851 +#include <sys/stat.h>
852 +#include <sys/types.h>
854 +#include "log/log.h"
855 +#include "talloc/talloc.h"
856 +#include "joystick.h"
859 + * pjs_process_event - Read joystick event and map to UI key code.
861 + * Returns a map routine UI key code or zero.
864 +int pjs_process_event(const struct pjs *pjs)
871 + result = read(pjs->fd, &e, sizeof(e));
873 + if (result != sizeof(e)) {
874 + pb_log("%s: read failed: %s\n", __func__, strerror(errno));
878 + return pjs->map(&e);
882 + * pjs_destructor - The talloc destructor for a joystick handler.
885 +static int pjs_destructor(void *arg)
887 + struct pjs *pjs = pjs_from_arg(arg);
896 + * pjs_init - Initialize the joystick event handler.
899 +struct pjs *pjs_init(void *ctx, int (*map)(const struct js_event *))
901 + static const char dev_name[] = "/dev/input/js0";
904 + pjs = talloc_zero(ctx, struct pjs);
910 + pjs->fd = open(dev_name, O_RDONLY | O_NONBLOCK);
913 + pb_log("%s: open %s failed: %s\n", __func__, dev_name,
918 + talloc_set_destructor(pjs, pjs_destructor);
920 + pb_log("%s: using %s\n", __func__, dev_name);
930 diff --git a/ui/common/joystick.h b/ui/common/joystick.h
932 index 0000000..cf3fc45
934 +++ b/ui/common/joystick.h
937 + * Copyright (C) 2009 Sony Computer Entertainment Inc.
938 + * Copyright 2009 Sony Corp.
940 + * This program is free software; you can redistribute it and/or modify
941 + * it under the terms of the GNU General Public License as published by
942 + * the Free Software Foundation; version 2 of the License.
944 + * This program is distributed in the hope that it will be useful,
945 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
946 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
947 + * GNU General Public License for more details.
949 + * You should have received a copy of the GNU General Public License
950 + * along with this program; if not, write to the Free Software
951 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
954 +#if !defined(_PB_JOYSTICK_H)
955 +#define _PB_JOYSTICK_H
957 +#include <linux/joystick.h>
960 + * struct pjs - Petitboot joystick event handler.
961 + * @map: Routine to map from a Linux struct js_event to a ui key code.
966 + int (*map)(const struct js_event *e);
969 +struct pjs *pjs_init(void *ctx, int (*map)(const struct js_event *));
970 +int pjs_process_event(const struct pjs *pjs);
972 +static inline struct pjs *pjs_from_arg(void *arg)
977 +static inline int pjs_get_fd(const struct pjs *pjs)
983 diff --git a/ui/common/loader.c b/ui/common/loader.c
984 index babca28..5c69533 100644
985 --- a/ui/common/loader.c
986 +++ b/ui/common/loader.c
987 @@ -227,7 +227,7 @@ enum wget_flags {
988 static char *pb_load_wget(void *ctx, struct pb_url *url, enum wget_flags flags)
991 - const char *argv[6];
992 + const char *argv[7];
996 @@ -238,12 +238,15 @@ static char *pb_load_wget(void *ctx, struct pb_url *url, enum wget_flags flags)
999 *p++ = pb_system_apps.wget; /* 1 */
1000 - *p++ = "-O"; /* 2 */
1001 - *p++ = local; /* 3 */
1002 - *p++ = url->full; /* 4 */
1003 +#if !defined(DEBUG)
1004 + *p++ = "--quiet"; /* 2 */
1006 + *p++ = "-O"; /* 3 */
1007 + *p++ = local; /* 4 */
1008 + *p++ = url->full; /* 5 */
1009 if (flags & wget_no_check_certificate)
1010 - *p++ = "--no-check-certificate"; /* 5 */
1011 - *p++ = NULL; /* 6 */
1012 + *p++ = "--no-check-certificate"; /* 6 */
1013 + *p++ = NULL; /* 7 */
1015 result = pb_run_cmd(argv);
1017 @@ -260,16 +263,22 @@ fail:
1019 * pb_load_file - Loads a remote file and returns the local file path.
1020 * @ctx: The talloc context to associate with the returned string.
1021 + * @remote: The remote file URL.
1022 + * @tempfile: An optional variable pointer to be set when a temporary local
1023 + * file is created.
1025 * Returns the local file path in a talloc'ed character string on success,
1029 -char *pb_load_file(void *ctx, const char *remote)
1030 +char *pb_load_file(void *ctx, const char *remote, unsigned int *tempfile)
1033 struct pb_url *url = pb_url_parse(NULL, remote);
1041 @@ -277,19 +286,28 @@ char *pb_load_file(void *ctx, const char *remote)
1044 local = pb_load_wget(ctx, url, 0);
1045 + if (tempfile && local)
1049 - local = pb_load_wget(ctx, url,
1050 - wget_no_check_certificate);
1051 + local = pb_load_wget(ctx, url, wget_no_check_certificate);
1052 + if (tempfile && local)
1056 local = pb_load_nfs(ctx, url);
1057 + if (tempfile && local)
1061 local = pb_load_sftp(ctx, url);
1062 + if (tempfile && local)
1066 local = pb_load_tftp(ctx, url);
1067 + if (tempfile && local)
1071 local = talloc_strdup(ctx, url->full);
1072 diff --git a/ui/common/loader.h b/ui/common/loader.h
1073 index b06bb43..42d4d4b 100644
1074 --- a/ui/common/loader.h
1075 +++ b/ui/common/loader.h
1077 #if !defined(_PB_FILE_LOADER_H)
1078 #define _PB_FILE_LOADER_H
1080 -char *pb_load_file(void *ctx, const char *remote);
1081 +char *pb_load_file(void *ctx, const char *remote, unsigned int *tempfile);
1084 diff --git a/ui/common/ps3.c b/ui/common/ps3.c
1085 index 5c83289..cb1c8d1 100644
1086 --- a/ui/common/ps3.c
1087 +++ b/ui/common/ps3.c
1088 @@ -49,6 +49,11 @@ static const struct os_area_db_id id_flags =
1089 .owner = OS_AREA_DB_OWNER_PETITBOOT, /* 3 */
1092 +static const struct os_area_db_id id_timeout =
1094 + .owner = OS_AREA_DB_OWNER_PETITBOOT, /* 3 */
1098 struct ps3_flash_ctx {
1100 @@ -59,6 +64,8 @@ struct ps3_flash_ctx {
1102 static void ps3_flash_close(struct ps3_flash_ctx *fc)
1109 @@ -104,19 +111,19 @@ int ps3_flash_get_values(struct ps3_flash_values *values)
1110 struct ps3_flash_ctx fc;
1113 - memset(values, 0, sizeof(*values));
1115 result = ps3_flash_open(&fc, "r");
1121 result = os_area_db_read(&fc.db, &fc.header, fc.dev);
1123 + ps3_flash_close(&fc);
1126 pb_log("%s: os_area_db_read failed: %s\n", __func__,
1132 sum = result = os_area_db_get(&fc.db, &id_default_item, &tmp);
1133 @@ -124,21 +131,25 @@ int ps3_flash_get_values(struct ps3_flash_values *values)
1135 values->default_item = (uint32_t)tmp;
1137 - sum += result = os_area_db_get(&fc.db, &id_video_mode, &tmp);
1138 + result = os_area_db_get(&fc.db, &id_timeout, &tmp);
1141 - values->video_mode = (uint16_t)tmp;
1142 + values->timeout = (uint8_t)tmp;
1144 + sum += result = os_area_db_get(&fc.db, &id_video_mode, &tmp);
1146 - pb_log("%s: default_item: %u\n", __func__, values->default_item);
1147 - pb_log("%s: video_mode: %u\n", __func__, values->video_mode);
1149 + values->video_mode = (uint16_t)tmp;
1151 - ps3_flash_close(&fc);
1154 + pb_log("%s: default_item: %x\n", __func__,
1155 + (unsigned int)values->default_item);
1156 + pb_log("%s: timeout: %u\n", __func__,
1157 + (unsigned int)values->timeout);
1158 + pb_log("%s: video_mode: %u\n", __func__,
1159 + (unsigned int)values->video_mode);
1162 - ps3_flash_close(&fc);
1164 + return (result || sum) ? -1 : 0;
1168 @@ -177,6 +188,8 @@ int ps3_flash_set_values(const struct ps3_flash_values *values)
1172 + /* timeout is currently read-only, set with ps3-bl-option */
1174 result = os_area_db_set_32(&fc.db, &id_default_item,
1175 values->default_item);
1176 result += os_area_db_set_16(&fc.db, &id_video_mode,
1177 diff --git a/ui/common/ps3.h b/ui/common/ps3.h
1178 index 8a7fe1c..5ba8afe 100644
1179 --- a/ui/common/ps3.h
1180 +++ b/ui/common/ps3.h
1181 @@ -33,9 +33,14 @@ enum ps3_flash_flags {
1182 ps3_flag_telnet = 1,
1185 +enum ps3_timeouts {
1186 + ps3_timeout_forever = 255,
1190 * struct ps3_flash_values - Values from PS3 flash memory.
1191 * @default_item: The default menu item.
1192 + * @timeout: The timeout in seconds.
1193 * @video_mode: The default video_mode.
1194 * @flags: Logical OR of enum ps3_flash_flags.
1196 @@ -44,6 +49,13 @@ struct ps3_flash_values {
1197 uint32_t default_item;
1198 uint16_t video_mode;
1199 /* uint16_t flags; */
1203 +static const struct ps3_flash_values ps3_flash_defaults = {
1204 + .default_item = 0,
1206 + .timeout = ps3_timeout_forever,
1209 int ps3_flash_get_values(struct ps3_flash_values *values);
1210 diff --git a/ui/common/timer.c b/ui/common/timer.c
1211 new file mode 100644
1212 index 0000000..954a18a
1214 +++ b/ui/common/timer.c
1217 + * Copyright (C) 2009 Sony Computer Entertainment Inc.
1218 + * Copyright 2009 Sony Corp.
1220 + * This program is free software; you can redistribute it and/or modify
1221 + * it under the terms of the GNU General Public License as published by
1222 + * the Free Software Foundation; version 2 of the License.
1224 + * This program is distributed in the hope that it will be useful,
1225 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1226 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1227 + * GNU General Public License for more details.
1229 + * You should have received a copy of the GNU General Public License
1230 + * along with this program; if not, write to the Free Software
1231 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1234 +#if defined(HAVE_CONFIG_H)
1235 +#include "config.h"
1238 +#define _GNU_SOURCE
1239 +#include <assert.h>
1240 +#include <limits.h>
1241 +#include <unistd.h>
1243 +#include "log/log.h"
1247 + * ui_timer_init - Initialize the timer for use.
1248 + * @seconds: The final timeout value in seconds.
1251 +void ui_timer_init(struct ui_timer *timer, unsigned int seconds)
1253 + pb_log("%s: %u\n", __func__, seconds);
1254 + assert(!timer->disabled);
1255 + timer->timeout = seconds;
1259 + * ui_timer_next - Calculate the next timer interval.
1262 +static unsigned int ui_timer_next(unsigned int seconds)
1264 + unsigned int next;
1266 + if (seconds == 0) {
1271 + if (seconds <= 10) {
1276 + if (seconds <= 60) {
1277 + next = seconds % 5;
1278 + next = next ? next : 5;
1282 + next = seconds % 10;
1283 + next = next ? next : 10;
1286 + pb_log("%s: %u = %u\n", __func__, seconds, next);
1291 + * ui_timer_kick - Kickstart the next timer interval.
1294 +void ui_timer_kick(struct ui_timer *timer)
1296 + unsigned int next;
1298 + if(timer->disabled)
1301 + if (timer->update_display)
1302 + timer->update_display(timer, timer->timeout);
1304 + next = ui_timer_next(timer->timeout);
1305 + timer->timeout -= next;
1312 + pb_log("%s: timed out\n", __func__);
1314 + ui_timer_disable(timer);
1315 + timer->handle_timeout(timer);
1319 + * ui_timer_disable - Stop and disable the timer.
1322 +void ui_timer_disable(struct ui_timer *timer)
1324 + if (timer->disabled)
1327 + pb_log("%s\n", __func__);
1328 + timer->disabled = 1;
1329 + timer->timeout = UINT_MAX;
1334 + * ui_timer_sigalrm
1336 + * Called at SIGALRM.
1339 +void ui_timer_sigalrm(struct ui_timer *timer)
1341 + timer->signaled = 1;
1345 + * ui_timer_process_sig - Process a timer signal
1348 +void ui_timer_process_sig(struct ui_timer *timer)
1350 + while (timer->signaled) {
1351 + timer->signaled = 0;
1352 + ui_timer_kick(timer);
1355 diff --git a/ui/common/timer.h b/ui/common/timer.h
1356 new file mode 100644
1357 index 0000000..781b442
1359 +++ b/ui/common/timer.h
1362 + * Copyright (C) 2009 Sony Computer Entertainment Inc.
1363 + * Copyright 2009 Sony Corp.
1365 + * This program is free software; you can redistribute it and/or modify
1366 + * it under the terms of the GNU General Public License as published by
1367 + * the Free Software Foundation; version 2 of the License.
1369 + * This program is distributed in the hope that it will be useful,
1370 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1371 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1372 + * GNU General Public License for more details.
1374 + * You should have received a copy of the GNU General Public License
1375 + * along with this program; if not, write to the Free Software
1376 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1379 +#if !defined(_PB_UI_TIMER_H)
1380 +#define _PB_UI_TIMER_H
1382 +#include <signal.h>
1385 + * struct ui_timer - UI timeout.
1389 + unsigned int timeout;
1390 + unsigned int disabled;
1391 + sig_atomic_t signaled;
1392 + void (*update_display)(struct ui_timer *timer, unsigned int timeout);
1393 + void (*handle_timeout)(struct ui_timer *timer);
1396 +void ui_timer_init(struct ui_timer *timer, unsigned int seconds);
1397 +void ui_timer_kick(struct ui_timer *timer);
1398 +void ui_timer_disable(struct ui_timer *timer);
1399 +void ui_timer_sigalrm(struct ui_timer *timer);
1400 +void ui_timer_process_sig(struct ui_timer *timer);
1403 diff --git a/ui/common/ui-system.c b/ui/common/ui-system.c
1404 index 3f54191..0140f0e 100644
1405 --- a/ui/common/ui-system.c
1406 +++ b/ui/common/ui-system.c
1408 #include "ui-system.h"
1411 - * run_kexec_local - Final kexec helper.
1412 + * kexec_load - kexec load helper.
1413 * @l_image: The local image file for kexec to execute.
1414 * @l_initrd: Optional local initrd file for kexec --initrd, can be NULL.
1415 * @args: Optional command line args for kexec --append, can be NULL.
1418 -static int run_kexec_local(const char *l_image, const char *l_initrd,
1419 +static int kexec_load(const char *l_image, const char *l_initrd,
1423 - const char *argv[8];
1424 + const char *argv[6];
1426 + char *s_initrd = NULL;
1427 + char *s_args = NULL;
1430 - *p++ = pb_system_apps.kexec; /* 1 */
1431 + *p++ = pb_system_apps.kexec; /* 1 */
1432 + *p++ = "-l"; /* 2 */
1435 - *p++ = "--initrd"; /* 2 */
1436 - *p++ = l_initrd; /* 3 */
1437 + s_initrd = talloc_asprintf(NULL, "--initrd=%s", l_initrd);
1439 + *p++ = s_initrd; /* 3 */
1443 - *p++ = "--append"; /* 4 */
1444 - *p++ = args; /* 5 */
1445 + s_args = talloc_asprintf(NULL, "--append=%s", args);
1447 + *p++ = s_args; /* 4 */
1450 - /* First try by telling kexec to run shutdown */
1451 + *p++ = l_image; /* 5 */
1452 + *p++ = NULL; /* 6 */
1454 - *(p + 0) = l_image;
1456 + result = pb_run_cmd(argv);
1459 + pb_log("%s: failed: (%d)\n", __func__, result);
1461 + talloc_free(s_initrd);
1462 + talloc_free(s_args);
1468 + * kexec_reboot - Helper to boot the new kernel.
1470 + * Must only be called after a successful call to kexec_load().
1473 +static int kexec_reboot(void)
1476 + const char *argv[4];
1479 + /* First try running shutdown. Init scripts should run 'exec -e' */
1482 + *p++ = pb_system_apps.shutdown; /* 1 */
1483 + *p++ = "-r"; /* 2 */
1484 + *p++ = "now"; /* 3 */
1485 + *p++ = NULL; /* 4 */
1487 result = pb_run_cmd(argv);
1489 - /* kexec will return zero on success */
1490 - /* On error, force a kexec with the -f option */
1491 + /* On error, force a kexec with the -e option */
1494 - *(p + 0) = "-f"; /* 6 */
1495 - *(p + 1) = l_image; /* 7 */
1496 - *(p + 2) = NULL; /* 8 */
1498 + *p++ = pb_system_apps.kexec; /* 1 */
1499 + *p++ = "-e"; /* 2 */
1500 + *p++ = NULL; /* 3 */
1502 result = pb_run_cmd(argv);
1504 @@ -85,38 +119,51 @@ static int run_kexec_local(const char *l_image, const char *l_initrd,
1507 * pb_run_kexec - Run kexec with the supplied boot options.
1509 - * For the convenience of the user, tries to load both files before
1510 - * returning error.
1513 int pb_run_kexec(const struct pb_kexec_data *kd)
1518 + char *l_image = NULL;
1519 + char *l_initrd = NULL;
1520 + unsigned int clean_image = 0;
1521 + unsigned int clean_initrd = 0;
1523 pb_log("%s: image: '%s'\n", __func__, kd->image);
1524 pb_log("%s: initrd: '%s'\n", __func__, kd->initrd);
1525 pb_log("%s: args: '%s'\n", __func__, kd->args);
1528 - l_image = pb_load_file(NULL, kd->image);
1531 - pb_log("%s: error null image\n", __func__);
1535 + l_image = pb_load_file(NULL, kd->image, &clean_image);
1541 + l_initrd = pb_load_file(NULL, kd->initrd, &clean_initrd);
1546 - l_initrd = kd->initrd ? pb_load_file(NULL, kd->initrd) : NULL;
1547 + if (!l_image && !l_initrd)
1550 + result = kexec_load(l_image, l_initrd, kd->args);
1552 - if (!l_image || (kd->initrd && !l_initrd))
1555 - result = run_kexec_local(l_image, l_initrd, kd->args);
1562 talloc_free(l_image);
1563 talloc_free(l_initrd);
1566 + result = kexec_reboot();
1571 diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c
1572 index 2a4c971..aed5ff7 100644
1573 --- a/ui/ncurses/nc-cui.c
1574 +++ b/ui/ncurses/nc-cui.c
1576 #include "ui/common/discover-client.h"
1580 static struct cui_opt_data *cod_from_item(struct pmenu_item *item)
1583 @@ -61,6 +60,35 @@ void cui_resize(struct cui *cui)
1587 + * cui_make_item_name - Format the menu item name srting.
1589 + * Returns a talloc string.
1592 +static char *cui_make_item_name(struct pmenu_item *i, struct cui_opt_data *cod)
1596 + assert(cod->name);
1599 + name = talloc_asprintf(i, "%s:", cod->name);
1601 + if (cod->kd->image)
1602 + name = talloc_asprintf_append(name, " %s", cod->kd->image);
1604 + if (cod->kd->initrd)
1605 + name = talloc_asprintf_append(name, " initrd=%s",
1608 + if (cod->kd->args)
1609 + name = talloc_asprintf_append(name, " %s", cod->kd->args);
1611 + DBGS("@%s@\n", name);
1616 * cui_on_exit - A generic main menu ESC callback.
1619 @@ -109,8 +137,8 @@ static int cui_run_kexec(struct pmenu_item *item)
1620 assert(cui->current == &cui->main->scr);
1621 assert(cui->on_kexec);
1623 - pb_log("%s: %s\n", __func__, cod->dev->name, cod->opt->name);
1624 - nc_scr_status_printf(cui->current, "Booting %s...", cod->opt->name);
1625 + pb_log("%s: %s\n", __func__, cod->name);
1626 + nc_scr_status_printf(cui->current, "Booting %s...", cod->name);
1630 @@ -141,9 +169,10 @@ static void cui_ked_on_exit(struct ked *ked, enum ked_result ked_result,
1632 struct cui *cui = cui_from_arg(ked->scr.ui_ctx);
1634 - if (ked_result == ked_update || ked_result == ked_boot) {
1635 + if (ked_result == ked_update) {
1636 struct pmenu_item *i = pmenu_find_selected(cui->main);
1637 struct cui_opt_data *cod = cod_from_item(i);
1642 @@ -151,7 +180,13 @@ static void cui_ked_on_exit(struct ked *ked, enum ked_result ked_result,
1643 talloc_free(cod->kd);
1646 - pb_log("%s: updating opt '%s'\n", __func__, cod->opt->name);
1647 + name = cui_make_item_name(i, cod);
1648 + pmenu_item_replace(i, name);
1650 + /* FIXME: need to make item visible somehow */
1651 + set_current_item(cui->main->ncm, i->nci);
1653 + pb_log("%s: updating opt '%s'\n", __func__, cod->name);
1654 pb_log(" image '%s'\n", cod->kd->image);
1655 pb_log(" initrd '%s'\n", cod->kd->initrd);
1656 pb_log(" args '%s'\n", cod->kd->args);
1657 @@ -160,20 +195,15 @@ static void cui_ked_on_exit(struct ked *ked, enum ked_result ked_result,
1658 cui_set_current(cui, &cui->main->scr);
1662 - if (ked_result == ked_boot) {
1663 - struct pmenu_item *i = pmenu_find_selected(cui->main);
1668 int cui_ked_run(struct pmenu_item *item)
1670 struct cui *cui = cui_from_item(item);
1671 + struct cui_opt_data *cod = cod_from_item(item);
1674 - ked = ked_init(cui, cod_from_item(item)->kd, cui_ked_on_exit);
1676 + ked = ked_init(cui, cod->kd, cui_ked_on_exit);
1677 cui_set_current(cui, &ked->scr);
1680 @@ -200,14 +230,43 @@ struct nc_scr *cui_set_current(struct cui *cui, struct nc_scr *scr)
1685 + * cui_process_key - Process input on stdin.
1688 static int cui_process_key(void *arg)
1690 struct cui *cui = cui_from_arg(arg);
1692 assert(cui->current);
1694 + ui_timer_disable(&cui->timer);
1695 cui->current->process_key(cui->current);
1701 + * cui_process_js - Process joystick events.
1704 +static int cui_process_js(void *arg)
1706 + struct cui *cui = cui_from_arg(arg);
1709 + c = pjs_process_event(cui->pjs);
1713 + cui_process_key(arg);
1719 + * cui_client_process_socket - Process a socket event from the discover server.
1722 static int cui_client_process_socket(void *arg)
1724 @@ -218,6 +277,24 @@ static int cui_client_process_socket(void *arg)
1728 + * cui_handle_timeout - Handle the timeout.
1731 +static void cui_handle_timeout(struct ui_timer *timer)
1733 + struct cui *cui = cui_from_timer(timer);
1734 + struct pmenu_item *i = pmenu_find_selected(cui->main);
1738 + struct cui_opt_data *cod = cod_from_item(i);
1739 + assert(cod && (cod->opt_hash == cui->default_item));
1746 * cui_handle_resize - Handle the term resize.
1749 @@ -243,6 +320,46 @@ static void cui_handle_resize(struct cui *cui)
1753 + * cui_on_open - Open new item callback.
1756 +void cui_on_open(struct pmenu *menu)
1758 + unsigned int insert_pt;
1759 + struct pmenu_item *i;
1760 + struct cui_opt_data *cod;
1762 + menu->scr.unpost(&menu->scr);
1764 + /* This disconnects items array from menu. */
1766 + set_menu_items(menu->ncm, NULL);
1768 + /* Insert new items at insert_pt. */
1770 + insert_pt = pmenu_grow(menu, 1);
1771 + i = pmenu_item_alloc(menu);
1773 + i->on_edit = cui_ked_run;
1774 + i->on_execute = cui_run_kexec;
1775 + i->data = cod = talloc_zero(i, struct cui_opt_data);
1777 + cod->name = talloc_asprintf(i, "User item %u:", insert_pt);
1778 + cod->kd = talloc_zero(i, struct pb_kexec_data);
1780 + pmenu_item_setup(menu, i, insert_pt, talloc_strdup(i, cod->name));
1782 + /* Re-attach the items array. */
1784 + set_menu_items(menu->ncm, menu->items);
1786 + menu->scr.post(&menu->scr);
1787 + set_current_item(menu->ncm, i->nci);
1793 * cui_device_add - Client device_add callback.
1795 * Creates menu_items for all the device boot_options and inserts those
1796 @@ -284,23 +401,11 @@ static int cui_device_add(struct device *dev, void *arg)
1797 struct pmenu_item *i;
1798 struct cui_opt_data *cod;
1800 - char *description;
1802 /* Save the item in opt->ui_info for cui_device_remove() */
1804 opt->ui_info = i = pmenu_item_alloc(cui->main);
1806 - name = talloc_asprintf(i, "%s: %s", opt->name,
1807 - opt->description);
1809 - description = talloc_asprintf(i,
1810 - " kexec: image='%s' initrd='%s' args='%s'",
1811 - opt->boot_image_file,
1815 - pmenu_item_setup(cui->main, i, insert_pt, name, description);
1817 i->on_edit = cui_ked_run;
1818 i->on_execute = cui_run_kexec;
1819 i->data = cod = talloc(i, struct cui_opt_data);
1820 @@ -308,23 +413,29 @@ static int cui_device_add(struct device *dev, void *arg)
1823 cod->opt_hash = pb_opt_hash(dev, opt);
1824 + cod->name = opt->name;
1825 cod->kd = talloc(i, struct pb_kexec_data);
1827 cod->kd->image = talloc_strdup(cod->kd, opt->boot_image_file);
1828 cod->kd->initrd = talloc_strdup(cod->kd, opt->initrd_file);
1829 cod->kd->args = talloc_strdup(cod->kd, opt->boot_args);
1833 - /* If this is the default_item select it. */
1834 + name = cui_make_item_name(i, cod);
1835 + pmenu_item_setup(cui->main, i, insert_pt, name);
1837 - if (cod->opt_hash == cui->default_item)
1838 - selected = i->nci;
1841 - pb_log("%s: adding opt '%s'\n", __func__, cod->opt->name);
1842 + pb_log("%s: adding opt '%s'\n", __func__, cod->name);
1843 pb_log(" image '%s'\n", cod->kd->image);
1844 pb_log(" initrd '%s'\n", cod->kd->initrd);
1845 pb_log(" args '%s'\n", cod->kd->args);
1847 + /* If this is the default_item select it and start timer. */
1849 + if (cod->opt_hash == cui->default_item) {
1850 + selected = i->nci;
1851 + ui_timer_kick(&cui->timer);
1855 /* Re-attach the items array. */
1856 @@ -340,6 +451,9 @@ static int cui_device_add(struct device *dev, void *arg)
1857 item_count(cui->main->ncm) + 1);
1860 + /* FIXME: need to make item visible somehow */
1861 + menu_driver(cui->main->ncm, REQ_SCR_UPAGE);
1862 + menu_driver(cui->main->ncm, REQ_SCR_DPAGE);
1863 set_current_item(cui->main->ncm, selected);
1865 if (cui->current == &cui->main->scr)
1866 @@ -375,9 +489,15 @@ static void cui_device_remove(struct device *dev, void *arg)
1868 list_for_each_entry(&dev->boot_options, opt, list) {
1869 struct pmenu_item *i = pmenu_item_from_arg(opt->ui_info);
1870 + struct cui_opt_data *cod = cod_from_item(i);
1872 - assert(pb_protocol_device_cmp(dev, cod_from_item(i)->dev));
1873 + assert(pb_protocol_device_cmp(dev, cod->dev));
1874 pmenu_remove(cui->main, i);
1876 + /* If this is the default_item disable timer. */
1878 + if (cod->opt_hash == cui->default_item)
1879 + ui_timer_disable(&cui->timer);
1882 /* Re-attach the items array. */
1883 @@ -397,10 +517,6 @@ static void cui_device_remove(struct device *dev, void *arg)
1884 cui->current->post(cui->current);
1888 - * cui_client_process_socket - Process a socket event from the discover server.
1891 static struct discover_client_ops cui_client_ops = {
1892 .device_add = cui_device_add,
1893 .device_remove = cui_device_remove,
1894 @@ -417,7 +533,8 @@ static struct discover_client_ops cui_client_ops = {
1897 struct cui *cui_init(void* platform_info,
1898 - int (*on_kexec)(struct cui *, struct cui_opt_data *))
1899 + int (*on_kexec)(struct cui *, struct cui_opt_data *),
1900 + int (*js_map)(const struct js_event *e))
1903 struct discover_client *client;
1904 @@ -434,6 +551,7 @@ struct cui *cui_init(void* platform_info,
1905 cui->c_sig = pb_cui_sig;
1906 cui->platform_info = platform_info;
1907 cui->on_kexec = on_kexec;
1908 + cui->timer.handle_timeout = cui_handle_timeout;
1910 /* Loop here for scripts that just started the server. */
1912 @@ -462,6 +580,15 @@ struct cui *cui_init(void* platform_info,
1914 waiter_register(STDIN_FILENO, WAIT_IN, cui_process_key, cui);
1918 + cui->pjs = pjs_init(cui, js_map);
1921 + waiter_register(pjs_get_fd(cui->pjs), WAIT_IN,
1922 + cui_process_js, cui);
1928 @@ -501,6 +628,8 @@ int cui_run(struct cui *cui, struct pmenu *main, unsigned int default_item)
1932 + ui_timer_process_sig(&cui->timer);
1934 while (cui->resize) {
1936 cui_handle_resize(cui);
1937 diff --git a/ui/ncurses/nc-cui.h b/ui/ncurses/nc-cui.h
1938 index 668776e..94fef6b 100644
1939 --- a/ui/ncurses/nc-cui.h
1940 +++ b/ui/ncurses/nc-cui.h
1945 +#include "ui/common/joystick.h"
1946 +#include "ui/common/timer.h"
1947 #include "nc-menu.h"
1951 struct cui_opt_data {
1953 + struct pb_kexec_data *kd;
1955 + /* optional data */
1956 const struct device *dev;
1957 const struct boot_option *opt;
1959 - struct pb_kexec_data *kd;
1963 @@ -49,13 +53,16 @@ struct cui {
1964 sig_atomic_t resize;
1965 struct nc_scr *current;
1967 + struct ui_timer timer;
1969 void *platform_info;
1970 unsigned int default_item;
1971 int (*on_kexec)(struct cui *cui, struct cui_opt_data *cod);
1974 struct cui *cui_init(void* platform_info,
1975 - int (*on_kexec)(struct cui *, struct cui_opt_data *));
1976 + int (*on_kexec)(struct cui *, struct cui_opt_data *),
1977 + int (*js_map)(const struct js_event *e));
1978 struct nc_scr *cui_set_current(struct cui *cui, struct nc_scr *scr);
1979 int cui_run(struct cui *cui, struct pmenu *main, unsigned int default_item);
1980 int cui_ked_run(struct pmenu_item *item);
1981 @@ -65,6 +72,7 @@ int cui_ked_run(struct pmenu_item *item);
1982 void cui_abort(struct cui *cui);
1983 void cui_resize(struct cui *cui);
1984 void cui_on_exit(struct pmenu *menu);
1985 +void cui_on_open(struct pmenu *menu);
1986 int cui_run_cmd(struct pmenu_item *item);
1988 static inline struct cui *cui_from_arg(void *arg)
1989 @@ -85,4 +93,15 @@ static inline struct cui *cui_from_item(struct pmenu_item *item)
1990 return cui_from_pmenu(item->pmenu);
1993 +static inline struct cui *cui_from_timer(struct ui_timer *timer)
1997 + cui = (struct cui *)((char *)timer
1998 + - (size_t)&((struct cui *)0)->timer);
1999 + assert(cui->c_sig == pb_cui_sig);
2005 diff --git a/ui/ncurses/nc-ked.c b/ui/ncurses/nc-ked.c
2006 index 3bdbd6c..806d389 100644
2007 --- a/ui/ncurses/nc-ked.c
2008 +++ b/ui/ncurses/nc-ked.c
2009 @@ -48,12 +48,15 @@ static struct ked *ked_from_arg(void *arg)
2010 * @req: An ncurses request or char to send to form_driver().
2013 -static void ked_move_cursor(struct ked *ked, int req)
2014 +static int ked_move_cursor(struct ked *ked, int req)
2018 wchgat(ked->scr.sub_ncw, 1, ked_attr_field_selected, 0, 0);
2019 - form_driver(ked->ncf, req);
2020 + result = form_driver(ked->ncf, req);
2021 wchgat(ked->scr.sub_ncw, 1, ked->attr_cursor, 0, 0);
2022 wrefresh(ked->scr.main_ncw);
2027 @@ -93,12 +96,15 @@ static void ked_insert_mode_tog(struct ked *ked)
2028 * @req: An ncurses request to send to form_driver().
2031 -static void ked_move_field(struct ked *ked, int req)
2032 +static int ked_move_field(struct ked *ked, int req)
2036 set_field_back(current_field(ked->ncf), ked_attr_field_normal);
2037 - form_driver(ked->ncf, req);
2038 + result = form_driver(ked->ncf, req);
2039 set_field_back(current_field(ked->ncf), ked_attr_field_selected);
2040 ked_move_cursor(ked, REQ_END_FIELD);
2044 static int ked_post(struct nc_scr *scr)
2045 @@ -143,9 +149,10 @@ static char *ked_chomp(char *s)
2046 for (; s < s_end; s++)
2047 if (*s != ' ' && *s != '\t')
2051 - for (++s; s < s_end; s++)
2054 + for (; s < s_end; s++)
2055 if (*s != ' ' && *s != '\t')
2058 @@ -183,41 +190,33 @@ static struct pb_kexec_data *ked_prepare_data(struct ked *ked)
2059 static void ked_process_key(struct nc_scr *scr)
2061 struct ked *ked = ked_from_scr(scr);
2062 + struct pb_kexec_data *kd;
2070 + /* DBGS("%d (%o)\n", c, c); */
2074 ked_move_cursor(ked, c);
2081 - case 2: { /* CTRL-B */
2082 - struct pb_kexec_data *kd;
2084 - form_driver(ked->ncf, REQ_VALIDATION);
2085 - kd = ked_prepare_data(ked);
2086 - ked->on_exit(ked, ked_boot, kd);
2091 ked->on_exit(ked, ked_cancel, NULL);
2096 - struct pb_kexec_data *kd;
2099 form_driver(ked->ncf, REQ_VALIDATION);
2100 kd = ked_prepare_data(ked);
2101 ked->on_exit(ked, ked_update, kd);
2108 @@ -252,8 +251,8 @@ static void ked_process_key(struct nc_scr *scr)
2109 ked_move_cursor(ked, REQ_RIGHT_CHAR);
2112 - ked_move_cursor(ked, REQ_LEFT_CHAR);
2113 - ked_move_cursor(ked, REQ_DEL_CHAR);
2114 + if (ked_move_cursor(ked, REQ_LEFT_CHAR) == E_OK)
2115 + ked_move_cursor(ked, REQ_DEL_CHAR);
2118 ked_move_cursor(ked, REQ_DEL_CHAR);
2119 @@ -325,7 +324,7 @@ struct ked *ked_init(void *ui_ctx, const struct pb_kexec_data *kd,
2121 ked->scr.frame.title = talloc_strdup(ked, "Petitboot Option Editor");
2122 ked->scr.frame.help = talloc_strdup(ked,
2123 - "ESC=cancel, Enter=accept, Ctrl-b=boot");
2124 + "ESC=cancel, Enter=accept");
2126 ked->on_exit = on_exit;
2128 diff --git a/ui/ncurses/nc-ked.h b/ui/ncurses/nc-ked.h
2129 index 36ed4f1..62fddd6 100644
2130 --- a/ui/ncurses/nc-ked.h
2131 +++ b/ui/ncurses/nc-ked.h
2133 #define _PB_NC_KED_H
2136 +#include <linux/input.h> /* This must be included before ncurses.h */
2139 #include "pb-protocol/pb-protocol.h"
2140 @@ -40,13 +41,11 @@ enum ked_attr_cursor {
2141 * enum ked_result - Result code for ked:on_exit().
2142 * @ked_cancel: The user canceled the operation.
2143 * @ked_update: The args were updated.
2144 - * @ked_boot: The user requested a boot of this item.
2154 diff --git a/ui/ncurses/nc-menu.c b/ui/ncurses/nc-menu.c
2155 index 0a76b11..f96eb82 100644
2156 --- a/ui/ncurses/nc-menu.c
2157 +++ b/ui/ncurses/nc-menu.c
2158 @@ -91,17 +91,17 @@ struct pmenu_item *pmenu_item_alloc(struct pmenu *menu)
2161 struct pmenu_item *pmenu_item_setup(struct pmenu *menu, struct pmenu_item *i,
2162 - unsigned int index, const char *name,
2163 - const char *description)
2164 + unsigned int index, const char *name)
2172 i->i_sig = pb_item_sig;
2174 - i->nci = new_item(name, description);
2175 + i->nci = new_item(name, NULL);
2179 @@ -115,6 +115,67 @@ struct pmenu_item *pmenu_item_setup(struct pmenu *menu, struct pmenu_item *i,
2183 +static int pmenu_item_get_index(const struct pmenu_item *item)
2187 + for (i = 0; i < item->pmenu->item_count; i++)
2188 + if (item->pmenu->items[i] == item->nci)
2191 + pb_log("%s: not found: %p %s\n", __func__, item,
2192 + (item ? item->nci->name.str : "(null)"));
2197 + * pmenu_item_replace - Replace the menu item with a new one.
2199 + * Use this routine to change a menu item's text.
2202 +int pmenu_item_replace(struct pmenu_item *i, const char *name)
2204 + struct pmenu *menu;
2212 + index = pmenu_item_get_index(i);
2215 + assert(0 && "get_index failed");
2219 + nci = new_item(name, NULL);
2222 + assert(0 && "new_item failed");
2226 + set_item_userptr(nci, i);
2228 + menu->scr.unpost(&menu->scr);
2229 + set_menu_items(menu->ncm, NULL);
2231 + // FIXME: need to assure item name is a talloc string.
2232 + /* talloc_free((char *)item_name(i->nci)); */
2234 + free_item(i->nci);
2235 + menu->items[index] = nci;
2238 + set_menu_items(menu->ncm, menu->items);
2239 + menu->scr.post(&menu->scr);
2245 * pmenu_move_cursor - Move the cursor.
2246 * @req: An ncurses request or char to send to menu_driver().
2247 @@ -143,7 +204,7 @@ static void pmenu_process_key(struct nc_scr *scr)
2251 - /* DBGS("%d (%o)\n", c, c); */
2252 + if (1) DBGS("%d (%o)\n", c, c);
2255 c = menu->hot_key(menu, item, c);
2256 @@ -174,13 +235,16 @@ static void pmenu_process_key(struct nc_scr *scr)
2258 pmenu_move_cursor(menu, REQ_DOWN_ITEM);
2265 item->on_edit(item);
2268 + DBGS("on_open: %p\n", menu->on_open);
2269 + if (menu->on_open)
2270 + menu->on_open(menu);
2274 if (item->on_execute)
2275 @@ -228,19 +292,6 @@ unsigned int pmenu_grow(struct pmenu *menu, unsigned int count)
2279 -static int pmenu_item_get_index(const struct pmenu_item *item)
2283 - for (i = 0; i < item->pmenu->item_count; i++)
2284 - if (item->pmenu->items[i] == item->nci)
2287 - pb_log("%s: not found: %p %s\n", __func__, item,
2288 - (item ? item->nci->name.str : "(null)"));
2293 * pmenu_remove - Remove an item from the item array.
2295 @@ -262,6 +313,9 @@ int pmenu_remove(struct pmenu *menu, struct pmenu_item *item)
2299 + free_item(item->nci);
2300 + talloc_free(item);
2302 /* Note that items array has a null terminator. */
2305 @@ -349,7 +403,7 @@ void pmenu_delete(struct pmenu *menu)
2306 menu->scr.sig = pb_removed_sig;
2308 for (i = item_count(menu->ncm); i; i--)
2309 - free_item(menu->items[i]);
2310 + free_item(menu->items[i - 1]);
2312 free_menu(menu->ncm);
2313 delwin(menu->scr.sub_ncw);
2314 diff --git a/ui/ncurses/nc-menu.h b/ui/ncurses/nc-menu.h
2315 index b487df9..4abec6f 100644
2316 --- a/ui/ncurses/nc-menu.h
2317 +++ b/ui/ncurses/nc-menu.h
2319 #define _PB_NC_MENU_H
2322 +#include <linux/input.h> /* This must be included before ncurses.h */
2325 #include "log/log.h"
2326 @@ -45,7 +46,8 @@ struct pmenu_item {
2328 struct pmenu_item *pmenu_item_alloc(struct pmenu *menu);
2329 struct pmenu_item *pmenu_item_setup(struct pmenu *menu, struct pmenu_item *i,
2330 - unsigned int index, const char *name, const char *description);
2331 + unsigned int index, const char *name);
2332 +int pmenu_item_replace(struct pmenu_item *i, const char *name);
2333 void pmenu_item_delete(struct pmenu_item *item);
2335 static inline struct pmenu_item *pmenu_item_from_arg(void *arg)
2336 @@ -57,10 +59,9 @@ static inline struct pmenu_item *pmenu_item_from_arg(void *arg)
2339 static inline struct pmenu_item *pmenu_item_init(struct pmenu *menu,
2340 - unsigned int index, const char *name, const char *description)
2341 + unsigned int index, const char *name)
2343 - return pmenu_item_setup(menu, pmenu_item_alloc(menu), index, name,
2345 + return pmenu_item_setup(menu, pmenu_item_alloc(menu), index, name);
2349 @@ -77,6 +78,7 @@ struct pmenu {
2350 unsigned int insert_pt;
2351 int (*hot_key)(struct pmenu *menu, struct pmenu_item *item, int c);
2352 void (*on_exit)(struct pmenu *menu);
2353 + void (*on_open)(struct pmenu *menu);
2356 struct pmenu *pmenu_init(void *ui_ctx, unsigned int item_count,
2357 diff --git a/ui/ncurses/nc-scr.h b/ui/ncurses/nc-scr.h
2358 index c08fcd4..2374c20 100644
2359 --- a/ui/ncurses/nc-scr.h
2360 +++ b/ui/ncurses/nc-scr.h
2362 #if !defined(_PB_NC_SCR_H)
2363 #define _PB_NC_SCR_H
2365 +#include <linux/input.h> /* This must be included before ncurses.h */
2366 #include <ncurses.h>
2368 #define DBG(fmt, args...) pb_log("DBG: " fmt, ## args)
2369 diff --git a/ui/ncurses/pb-cui.c b/ui/ncurses/pb-cui.c
2370 new file mode 100644
2371 index 0000000..972490a
2373 +++ b/ui/ncurses/pb-cui.c
2376 + * Petitboot generic ncurses bootloader UI
2378 + * Copyright (C) 2009 Sony Computer Entertainment Inc.
2379 + * Copyright 2009 Sony Corp.
2381 + * This program is free software; you can redistribute it and/or modify
2382 + * it under the terms of the GNU General Public License as published by
2383 + * the Free Software Foundation; version 2 of the License.
2385 + * This program is distributed in the hope that it will be useful,
2386 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2387 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2388 + * GNU General Public License for more details.
2390 + * You should have received a copy of the GNU General Public License
2391 + * along with this program; if not, write to the Free Software
2392 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2395 +#if defined(HAVE_CONFIG_H)
2396 +#include "config.h"
2399 +#define _GNU_SOURCE
2401 +#include <getopt.h>
2402 +#include <signal.h>
2403 +#include <stdlib.h>
2404 +#include <string.h>
2405 +#include <sys/time.h>
2407 +#include "log/log.h"
2408 +#include "talloc/talloc.h"
2409 +#include "waiter/waiter.h"
2410 +#include "ui/common/discover-client.h"
2411 +#include "nc-cui.h"
2413 +static void print_version(void)
2415 + printf("pb-cui (" PACKAGE_NAME ") " PACKAGE_VERSION "\n");
2418 +static void print_usage(void)
2422 +"Usage: pb-cui [-h, --help] [-l, --log log-file] [-V, --version]\n");
2426 + * enum opt_value - Tri-state options variables.
2429 +enum opt_value {opt_undef = 0, opt_yes, opt_no};
2432 + * struct opts - Values from command line options.
2436 + enum opt_value show_help;
2437 + const char *log_file;
2438 + enum opt_value show_version;
2442 + * opts_parse - Parse the command line options.
2445 +static int opts_parse(struct opts *opts, int argc, char *argv[])
2447 + static const struct option long_options[] = {
2448 + {"help", no_argument, NULL, 'h'},
2449 + {"log", required_argument, NULL, 'l'},
2450 + {"version", no_argument, NULL, 'V'},
2451 + { NULL, 0, NULL, 0},
2453 + static const char short_options[] = "hl:V";
2454 + static const struct opts default_values = {
2455 + .log_file = "pb-cui.log",
2458 + *opts = default_values;
2461 + int c = getopt_long(argc, argv, short_options, long_options,
2469 + opts->show_help = opt_yes;
2472 + opts->log_file = optarg;
2475 + opts->show_version = opt_yes;
2478 + opts->show_help = opt_yes;
2487 + * struct pb_cui - Main cui program instance.
2489 + * @svm: Set video mode menu.
2497 +static struct pb_cui *pb_from_cui(struct cui *cui)
2499 + struct pb_cui *pb;
2501 + assert(cui->c_sig == pb_cui_sig);
2502 + pb = cui->platform_info;
2503 + assert(pb->cui->c_sig == pb_cui_sig);
2508 + * pb_kexec_cb - The kexec callback.
2511 +static int pb_kexec_cb(struct cui *cui, struct cui_opt_data *cod)
2513 + struct pb_cui *pb = pb_from_cui(cui);
2515 + pb_log("%s: %s\n", __func__, cod->name);
2517 + assert(pb->cui->current == &pb->cui->main->scr);
2519 + return pb_run_kexec(cod->kd);
2523 + * pb_mm_init - Setup the main menu instance.
2526 +static struct pmenu *pb_mm_init(struct pb_cui *pb_cui)
2530 + struct pmenu_item *i;
2532 + m = pmenu_init(pb_cui->cui, 1, cui_on_exit);
2535 + pb_log("%s: failed\n", __func__);
2539 + m->on_open = cui_on_open;
2541 + m->scr.frame.title = talloc_strdup(m, "Petitboot");
2542 + m->scr.frame.help = talloc_strdup(m,
2543 + "ESC=exit, Enter=accept, e=edit, o=open");
2544 + m->scr.frame.status = talloc_strdup(m, "Welcome to Petitboot");
2546 + i = pmenu_item_init(m, 0, "Exit to Shell");
2547 + i->on_execute = pmenu_exit_cb;
2549 + result = pmenu_setup(m);
2552 + pb_log("%s:%d: pmenu_setup failed: %s\n", __func__, __LINE__,
2557 + menu_opts_off(m->ncm, O_SHOWDESC);
2558 + set_menu_mark(m->ncm, " *");
2559 + set_current_item(m->ncm, i->nci);
2568 +static struct pb_cui pb;
2570 +static void sig_handler(int signum)
2572 + DBGS("%d\n", signum);
2577 + ui_timer_sigalrm(&pb.cui->timer);
2581 + cui_resize(pb.cui);
2584 + assert(0 && "unknown sig");
2585 + /* fall through */
2590 + cui_abort(pb.cui);
2596 + * main - cui bootloader main routine.
2599 +int main(int argc, char *argv[])
2601 + static struct sigaction sa;
2602 + static struct opts opts;
2607 + result = opts_parse(&opts, argc, argv);
2611 + return EXIT_FAILURE;
2614 + if (opts.show_help == opt_yes) {
2616 + return EXIT_SUCCESS;
2619 + if (opts.show_version == opt_yes) {
2621 + return EXIT_SUCCESS;
2624 + log = fopen(opts.log_file, "a");
2626 + pb_log_set_stream(log);
2629 + pb_log_always_flush(1);
2632 + pb_log("--- pb-cui ---\n");
2634 + sa.sa_handler = sig_handler;
2635 + result = sigaction(SIGALRM, &sa, NULL);
2636 + result += sigaction(SIGHUP, &sa, NULL);
2637 + result += sigaction(SIGINT, &sa, NULL);
2638 + result += sigaction(SIGTERM, &sa, NULL);
2639 + result += sigaction(SIGWINCH, &sa, NULL);
2642 + pb_log("%s sigaction failed.\n", __func__);
2643 + return EXIT_FAILURE;
2646 + pb.cui = cui_init(&pb, pb_kexec_cb, NULL);
2649 + return EXIT_FAILURE;
2651 + pb.mm = pb_mm_init(&pb);
2652 + ui_timer_disable(&pb.cui->timer);
2654 + cui_result = cui_run(pb.cui, pb.mm, 0);
2656 + pmenu_delete(pb.mm);
2658 + talloc_free(pb.cui);
2660 + pb_log("--- end ---\n");
2662 + return cui_result ? EXIT_FAILURE : EXIT_SUCCESS;
2664 diff --git a/ui/ncurses/ps3-cui.c b/ui/ncurses/ps3-cui.c
2665 index f166c88..d9a66fa 100644
2666 --- a/ui/ncurses/ps3-cui.c
2667 +++ b/ui/ncurses/ps3-cui.c
2671 * removable media event
2672 - * resize after video mode change
2673 * ncurses mouse support
2677 #if defined(HAVE_CONFIG_H)
2682 +#include <sys/time.h>
2684 #include "log/log.h"
2685 #include "talloc/talloc.h"
2686 @@ -53,7 +52,8 @@ static void print_usage(void)
2690 -"Usage: pb-cui [-h, --help] [-l, --log log-file] [-V, --version]\n");
2691 +"Usage: pb-cui [-h, --help] [-l, --log log-file] [-r, --reset-defaults]\n"
2692 +" [-t, --timeout] [-V, --version]\n");
2696 @@ -69,6 +69,8 @@ enum opt_value {opt_undef = 0, opt_yes, opt_no};
2698 enum opt_value show_help;
2699 const char *log_file;
2700 + enum opt_value reset_defaults;
2701 + enum opt_value use_timeout;
2702 enum opt_value show_version;
2705 @@ -79,12 +81,14 @@ struct opts {
2706 static int opts_parse(struct opts *opts, int argc, char *argv[])
2708 static const struct option long_options[] = {
2709 - {"help", no_argument, NULL, 'h'},
2710 - {"log", required_argument, NULL, 'l'},
2711 - {"version", no_argument, NULL, 'V'},
2712 - { NULL, 0, NULL, 0},
2713 + {"help", no_argument, NULL, 'h'},
2714 + {"log", required_argument, NULL, 'l'},
2715 + {"reset-defaults", no_argument, NULL, 'r'},
2716 + {"timeout", no_argument, NULL, 't'},
2717 + {"version", no_argument, NULL, 'V'},
2718 + { NULL, 0, NULL, 0},
2720 - static const char short_options[] = "hl:V";
2721 + static const char short_options[] = "hl:trV";
2722 static const struct opts default_values = {
2723 .log_file = "pb-cui.log",
2725 @@ -105,6 +109,12 @@ static int opts_parse(struct opts *opts, int argc, char *argv[])
2727 opts->log_file = optarg;
2730 + opts->use_timeout = opt_yes;
2733 + opts->reset_defaults = opt_yes;
2736 opts->show_version = opt_yes;
2738 @@ -114,7 +124,7 @@ static int opts_parse(struct opts *opts, int argc, char *argv[])
2743 + return optind != argc;
2747 @@ -147,6 +157,83 @@ static struct ps3_cui *ps3_from_item(struct pmenu_item *item)
2751 + * ps3_sixaxis_map - Map a Linux joystick event to an ncurses key code.
2755 +static int ps3_sixaxis_map(const struct js_event *e)
2758 + static const int axis_map[] = {
2759 + 0, /* 0 Left thumb X */
2760 + 0, /* 1 Left thumb Y */
2761 + 0, /* 2 Right thumb X */
2762 + 0, /* 3 Right thumb Y */
2763 + 0, /* 4 nothing */
2764 + 0, /* 5 nothing */
2765 + 0, /* 6 nothing */
2766 + 0, /* 7 nothing */
2767 + 0, /* 8 Dpad Up */
2768 + 0, /* 9 Dpad Right */
2769 + 0, /* 10 Dpad Down */
2770 + 0, /* 11 Dpad Left */
2775 + 0, /* 16 Triangle */
2776 + 0, /* 17 Circle */
2778 + 0, /* 19 Square */
2779 + 0, /* 20 nothing */
2780 + 0, /* 21 nothing */
2781 + 0, /* 22 nothing */
2782 + 0, /* 23 nothing */
2783 + 0, /* 24 nothing */
2784 + 0, /* 25 nothing */
2785 + 0, /* 26 nothing */
2786 + 0, /* 27 nothing */
2789 + static const int button_map[] = {
2794 + KEY_UP, /* 4 Dpad Up */
2795 + 0, /* 5 Dpad Right */
2796 + KEY_DOWN, /* 6 Dpad Down */
2797 + 0, /* 7 Dpad Left */
2798 + KEY_UP, /* 8 L2 */
2799 + KEY_DOWN, /* 9 R2 */
2800 + KEY_HOME, /* 10 L1 */
2801 + KEY_END, /* 11 R1 */
2802 + 0, /* 12 Triangle */
2803 + 0, /* 13 Circle */
2804 + 13, /* 14 Cross */
2805 + 0, /* 15 Square */
2806 + 0, /* 16 PS Button */
2807 + 0, /* 17 nothing */
2808 + 0, /* 18 nothing */
2814 + if (e->type == JS_EVENT_BUTTON
2815 + && e->number < sizeof(button_map) / sizeof(button_map[0]))
2816 + return button_map[e->number];
2819 + if (e->type == JS_EVENT_AXIS
2820 + && e->number < sizeof(axis_map) / sizeof(axis_map[0]))
2821 + return axis_map[e->number];
2828 * ps3_set_mode - Set video mode helper.
2830 * Runs ps3_set_video_mode().
2831 @@ -183,22 +270,51 @@ static int ps3_svm_cb(struct pmenu_item *item)
2832 * ps3_kexec_cb - The kexec callback.
2834 * Writes config data to PS3 flash then calls pb_run_kexec().
2835 + * Adds a video mode arg to the kernel command line if needed.
2838 static int ps3_kexec_cb(struct cui *cui, struct cui_opt_data *cod)
2840 struct ps3_cui *ps3 = ps3_from_cui(cui);
2845 - pb_log("%s: %s:%s\n", __func__, cod->dev->name, cod->opt->name);
2846 + pb_log("%s: %s\n", __func__, cod->name);
2848 assert(ps3->cui->current == &ps3->cui->main->scr);
2850 - if (cui->default_item != cod->opt_hash || ps3->dirty_values) {
2851 + /* Save values to flash if needed */
2853 + if ((cod->opt_hash && cod->opt_hash != cui->default_item)
2854 + || ps3->dirty_values) {
2855 ps3->values.default_item = cod->opt_hash;
2856 ps3_flash_set_values(&ps3->values);
2859 - return pb_run_kexec(cod->kd);
2860 + /* Add a default kernel video mode. */
2862 + if (!cod->kd->args) {
2865 + cod->kd->args = talloc_asprintf(NULL, "video=ps3fb:mode:%u",
2866 + (unsigned int)ps3->values.video_mode);
2867 + } else if (!strstr(cod->kd->args, "video=")) {
2869 + orig_args = cod->kd->args;
2870 + cod->kd->args = talloc_asprintf(NULL, "%s video=ps3fb:mode:%u",
2871 + orig_args, (unsigned int)ps3->values.video_mode);
2875 + result = pb_run_kexec(cod->kd);
2877 + if (altered_args) {
2878 + talloc_free(cod->kd->args);
2879 + cod->kd->args = orig_args;
2886 @@ -283,6 +399,21 @@ static int ps3_hot_key(struct pmenu __attribute__((unused)) *menu,
2890 + * ps3_timer_update - Timer callback.
2893 +static void ps3_timer_update(struct ui_timer *timer, unsigned int timeout)
2895 + struct ps3_cui *ps3 = ps3_from_cui(cui_from_timer(timer));
2897 + //FIXME: make scr:timer.
2898 + // nc_scr_timer_update(&ps3.mm->scr, timeout);
2900 + nc_scr_status_printf(&ps3->mm->scr,
2901 + "Welcome to Petitboot (timeout %u sec)", timeout);
2905 * ps3_mm_init - Setup the main menu instance.
2908 @@ -291,8 +422,7 @@ static struct pmenu *ps3_mm_init(struct ps3_cui *ps3_cui)
2911 struct pmenu_item *i;
2912 - static const char *const bgo[] =
2913 - {"/usr/sbin/ps3-boot-game-os-NOT", NULL};
2914 + static const char *const bgo[] = {"/usr/sbin/ps3-boot-game-os", NULL};
2916 m = pmenu_init(ps3_cui->cui, 3, cui_on_exit);
2918 @@ -302,22 +432,26 @@ static struct pmenu *ps3_mm_init(struct ps3_cui *ps3_cui)
2921 m->hot_key = ps3_hot_key;
2922 + m->on_open = cui_on_open;
2925 + m->scr.frame.title = talloc_strdup(m,
2926 + "Petitboot PS3 (" PACKAGE_VERSION ")");
2928 m->scr.frame.title = talloc_strdup(m, "Petitboot PS3");
2930 m->scr.frame.help = talloc_strdup(m,
2931 - "ESC=exit, Enter=accept, E,e=edit");
2932 + "ESC=exit, Enter=accept, e=edit, o=open");
2933 m->scr.frame.status = talloc_strdup(m, "Welcome to Petitboot");
2935 - i = pmenu_item_init(m, 0, "Boot GameOS",
2936 - "Reboot the PS3 into the GameOS");
2937 + i = pmenu_item_init(m, 0, "Boot GameOS");
2938 i->on_execute = cui_run_cmd;
2939 i->data = (void *)bgo;
2941 - i = pmenu_item_init(m, 1, "Set Video Mode",
2942 - "Display a video mode selection menu");
2943 + i = pmenu_item_init(m, 1, "Set Video Mode");
2944 i->on_execute = ps3_mm_to_svm_cb;
2946 - i = pmenu_item_init(m, 2, "Exit to Shell",
2947 - "Exit petitboot and return to a shell prompt");
2948 + i = pmenu_item_init(m, 2, "Exit to Shell");
2949 i->on_execute = pmenu_exit_cb;
2951 result = pmenu_setup(m);
2952 @@ -360,53 +494,51 @@ static struct pmenu *ps3_svm_init(struct ps3_cui *ps3_cui)
2953 m->scr.frame.title = talloc_strdup(m, "Select PS3 Video Mode");
2954 m->scr.frame.help = talloc_strdup(m, "ESC=exit, Enter=accept");
2956 - i = pmenu_item_init(m, 0, "auto detect",
2957 - "Auto detect the best HDMI video mode");
2958 + i = pmenu_item_init(m, 0, "auto detect");
2959 i->on_execute = ps3_svm_cb;
2960 i->data = (void *)0;
2962 - i = pmenu_item_init(m, 1, "480i (576 x 384)", NULL);
2963 + i = pmenu_item_init(m, 1, "480i (576 x 384)");
2964 i->on_execute = ps3_svm_cb;
2965 i->data = (void *)1;
2967 - i = pmenu_item_init(m, 2, "480p (576 x 384)", NULL);
2968 + i = pmenu_item_init(m, 2, "480p (576 x 384)");
2969 i->on_execute = ps3_svm_cb;
2970 i->data = (void *)2;
2972 - i = pmenu_item_init(m, 3, "576i (576 x 460)", NULL);
2973 + i = pmenu_item_init(m, 3, "576i (576 x 460)");
2974 i->on_execute = ps3_svm_cb;
2975 i->data = (void *)6;
2977 - i = pmenu_item_init(m, 4, "576p (576 x 460)", NULL);
2978 + i = pmenu_item_init(m, 4, "576p (576 x 460)");
2979 i->on_execute = ps3_svm_cb;
2980 i->data = (void *)7;
2982 - i = pmenu_item_init(m, 5, "720p (1124 x 644)", NULL);
2983 + i = pmenu_item_init(m, 5, "720p (1124 x 644)");
2984 i->on_execute = ps3_svm_cb;
2985 i->data = (void *)3;
2987 - i = pmenu_item_init(m, 6, "1080i (1688 x 964)", NULL);
2988 + i = pmenu_item_init(m, 6, "1080i (1688 x 964)");
2989 i->on_execute = ps3_svm_cb;
2990 i->data = (void *)4;
2992 - i = pmenu_item_init(m, 7, "1080p (1688 x 964)", NULL);
2993 + i = pmenu_item_init(m, 7, "1080p (1688 x 964)");
2994 i->on_execute = ps3_svm_cb;
2995 i->data = (void *)5;
2997 - i = pmenu_item_init(m, 8, "wxga (1280 x 768)", NULL);
2998 + i = pmenu_item_init(m, 8, "wxga (1280 x 768)");
2999 i->on_execute = ps3_svm_cb;
3000 i->data = (void *)11;
3002 - i = pmenu_item_init(m, 9, "sxga (1280 x 1024)", NULL);
3003 + i = pmenu_item_init(m, 9, "sxga (1280 x 1024)");
3004 i->on_execute = ps3_svm_cb;
3005 i->data = (void *)12;
3007 - i = pmenu_item_init(m, 10, "wuxga (1920 x 1200)", NULL);
3008 + i = pmenu_item_init(m, 10, "wuxga (1920 x 1200)");
3009 i->on_execute = ps3_svm_cb;
3010 i->data = (void *)13;
3012 - i = pmenu_item_init(m, 11, "Return",
3013 - "Return to the main menu");
3014 + i = pmenu_item_init(m, 11, "Return");
3015 i->on_execute = ps3_svm_to_mm_cb;
3017 result = pmenu_setup(m);
3018 @@ -434,6 +566,10 @@ static void sig_handler(int signum)
3019 DBGS("%d\n", signum);
3024 + ui_timer_sigalrm(&ps3.cui->timer);
3028 cui_resize(ps3.cui);
3029 @@ -491,8 +627,9 @@ int main(int argc, char *argv[])
3030 pb_log("--- pb-cui ---\n");
3032 sa.sa_handler = sig_handler;
3033 - result = sigaction(SIGINT, &sa, NULL);
3034 + result = sigaction(SIGALRM, &sa, NULL);
3035 result += sigaction(SIGHUP, &sa, NULL);
3036 + result += sigaction(SIGINT, &sa, NULL);
3037 result += sigaction(SIGTERM, &sa, NULL);
3038 result += sigaction(SIGWINCH, &sa, NULL);
3040 @@ -501,7 +638,10 @@ int main(int argc, char *argv[])
3041 return EXIT_FAILURE;
3044 - ps3.dirty_values = ps3_flash_get_values(&ps3.values);
3045 + ps3.values = ps3_flash_defaults;
3047 + if (opts.reset_defaults != opt_yes)
3048 + ps3.dirty_values = ps3_flash_get_values(&ps3.values);
3050 result = ps3_get_video_mode(&mode);
3052 @@ -515,7 +655,7 @@ int main(int argc, char *argv[])
3053 if (!result && (ps3.values.video_mode != (uint16_t)mode))
3054 ps3_set_video_mode(ps3.values.video_mode);
3056 - ps3.cui = cui_init(&ps3, ps3_kexec_cb);
3057 + ps3.cui = cui_init(&ps3, ps3_kexec_cb, ps3_sixaxis_map);
3060 return EXIT_FAILURE;
3061 @@ -523,6 +663,14 @@ int main(int argc, char *argv[])
3062 ps3.mm = ps3_mm_init(&ps3);
3063 ps3.svm = ps3_svm_init(&ps3);
3065 + if (opts.use_timeout != opt_yes
3066 + || ps3.values.timeout == ps3_timeout_forever)
3067 + ui_timer_disable(&ps3.cui->timer);
3069 + ps3.cui->timer.update_display = ps3_timer_update;
3070 + ui_timer_init(&ps3.cui->timer, ps3.values.timeout);
3073 cui_result = cui_run(ps3.cui, ps3.mm, ps3.values.default_item);
3075 pmenu_delete(ps3.mm);