static int config_init(int argc, char * * argv) { char const * levels; char * temp; char const * tok; int pid; if (cmdline_load(argc, argv)<0) { return -1; } #ifdef DO_DAEMONIZE if (!cmdline_get_foreground()) { if (!((pid = setup_daemon()) == 0)) { return pid; } } #endif if (d2dbs_prefs_load(cmdline_get_preffile())<0) { eventlog(eventlog_level_error,__FUNCTION__,"error loading configuration file %s",cmdline_get_preffile()); return -1; } eventlog_clear_level(); if ((levels = d2dbs_prefs_get_loglevels())) { temp = xstrdup(levels); tok = strtok(temp,","); /* strtok modifies the string it is passed */ while (tok) { if (eventlog_add_level(tok)<0) eventlog(eventlog_level_error,__FUNCTION__,"could not add log level \"%s\"",tok); tok = strtok(NULL,","); } xfree(temp); } #ifdef DO_DAEMONIZE if (cmdline_get_foreground()) { eventlog_set(stderr); } else #endif { if (cmdline_get_logfile()) { if (eventlog_open(cmdline_get_logfile())<0) { eventlog(eventlog_level_error,__FUNCTION__,"error open eventlog file %s",cmdline_get_logfile()); return -1; } } else { if (eventlog_open(d2dbs_prefs_get_logfile())<0) { eventlog(eventlog_level_error,__FUNCTION__,"error open eventlog file %s",d2dbs_prefs_get_logfile()); return -1; } } } return 0; }
int main(int argc, char *argv[]) { history = g_queue_new(); displayed = g_queue_new(); queue = g_queue_new(); cmdline_load(argc, argv); if (cmdline_get_bool("-v/-version", false, "Print version") || cmdline_get_bool("--version", false, "Print version")) { print_version(); } char *cmdline_config_path; cmdline_config_path = cmdline_get_string("-conf/-config", NULL, "Path to configuration file"); load_settings(cmdline_config_path); if (cmdline_get_bool("-h/-help", false, "Print help") || cmdline_get_bool("--help", false, "Print help")) { usage(EXIT_SUCCESS); } int owner_id = initdbus(); x_setup(); if (settings.startup_notification) { notification *n = malloc(sizeof(notification)); if(n == NULL) { die("Unable to allocate memory", EXIT_FAILURE); } n->appname = strdup("dunst"); n->summary = strdup("startup"); n->body = strdup("dunst is up and running"); n->progress = 0; n->timeout = 10; n->allow_markup = false; n->plain_text = true; n->urgency = LOW; n->icon = NULL; n->raw_icon = NULL; n->category = NULL; n->msg = NULL; n->dbus_client = NULL; n->color_strings[0] = NULL; n->color_strings[1] = NULL; n->actions = NULL; n->urls = NULL; notification_init(n, 0); } mainloop = g_main_loop_new(NULL, FALSE); GPollFD dpy_pollfd = { xctx.dpy->fd, G_IO_IN | G_IO_HUP | G_IO_ERR, 0 }; GSourceFuncs x11_source_funcs = { x_mainloop_fd_prepare, x_mainloop_fd_check, x_mainloop_fd_dispatch, NULL, NULL, NULL }; GSource *x11_source = g_source_new(&x11_source_funcs, sizeof(x11_source_t)); ((x11_source_t *) x11_source)->dpy = xctx.dpy; ((x11_source_t *) x11_source)->w = xctx.win; g_source_add_poll(x11_source, &dpy_pollfd); g_source_attach(x11_source, NULL); g_unix_signal_add(SIGUSR1, pause_signal, NULL); g_unix_signal_add(SIGUSR2, unpause_signal, NULL); run(NULL); g_main_loop_run(mainloop); dbus_tear_down(owner_id); return 0; }
extern int main(int argc, char * * argv) #endif { int a; char *pidfile; xalloc_install(); if ((a = cmdline_load(argc, argv)) != 1) return a; #ifdef DO_DAEMONIZE if ((a = fork_bnetd(cmdline_get_foreground())) != 0) return a < 0 ? a : 0; /* dont return code != 0 when things are OK! */ #endif eventlog_set(stderr); /* errors to eventlog from here on... */ if (prefs_load(cmdline_get_preffile())<0) { eventlog(eventlog_level_fatal,__FUNCTION__,"could not parse configuration file (exiting)"); return -1; } /* Start logging to log file */ if (eventlog_startup() == -1) return -1; /* eventlog goes to log file from here on... */ /* Give up root privileges */ /* Hakan: That's way too late to give up root privileges... Have to look for a better place */ if (give_up_root_privileges(prefs_get_effective_user(),prefs_get_effective_group())<0) { eventlog(eventlog_level_fatal,__FUNCTION__,"could not give up privileges (exiting)"); return -1; } /* Write the pidfile */ pidfile = write_to_pidfile(); if (cmdline_get_hexfile()) { if (!(hexstrm = fopen(cmdline_get_hexfile(),"w"))) eventlog(eventlog_level_error,__FUNCTION__,"could not open file \"%s\" for writing the hexdump (fopen: %s)",cmdline_get_hexfile(),pstrerror(errno)); else fprintf(hexstrm,"# dump generated by "PVPGN_SOFTWARE" version "PVPGN_VERSION"\n"); } /* Run the pre server stuff */ a = pre_server_startup(); /* now process connections and network traffic */ if (a == 0) { if (server_process() < 0) eventlog(eventlog_level_fatal,__FUNCTION__,"failed to initialize network (exiting)"); } // run post server stuff and exit post_server_shutdown(a); // Close hexfile if (hexstrm) { fprintf(hexstrm,"# end of dump\n"); if (fclose(hexstrm)<0) eventlog(eventlog_level_error,__FUNCTION__,"could not close hexdump file \"%s\" after writing (fclose: %s)",cmdline_get_hexfile(),pstrerror(errno)); } // Delete pidfile if (pidfile) { if (remove(pidfile)<0) eventlog(eventlog_level_error,__FUNCTION__,"could not remove pid file \"%s\" (remove: %s)",pidfile,pstrerror(errno)); xfree((void *)pidfile); /* avoid warning */ } if (a == 0) eventlog(eventlog_level_info,__FUNCTION__,"server has shut down"); prefs_unload(); eventlog_close(); cmdline_unload(); xalloc_deinstall(); if (a == 0) return 0; return -1; }
int main(void) { u32 rootfs; u8 *load_address; char *rfs_txt; u32 image = 0; struct jffs2_raw_inode *node, *mfg_node; char *cmdline = 0, *altcmdline = 0; u32 kernel_nand_addr = 0, alt_kernel_nand_addr = 0; int board_id; u32 ret = 0; u32 ret2 = 0; u8 selection = 0; u8 displayOn = 0; unsigned char cSel; #ifdef CPU_LF1000 /* disable the USB controller */ BIT_SET(REG16(LF1000_UDC_BASE+UDC_PCR), PCE); #endif adc_init(); board_id = load_board_id(); display_backlight(board_id); clock_init(); db_init(); #ifdef CONFIG_MACH_LF_LF1000 /* now that backlight is on, see if we have enough battery to boot */ if(gpio_get_val(LOW_BATT_PORT, LOW_BATT_PIN) == 0 && ADC_TO_MV(adc_get_reading(LF1000_ADC_VBATSENSE)) < BOOT_MIN_MV){ display_init(); db_puts("PANIC: battery voltage too low!\n"); guru_med(0xBA77DEAD,0x0BAD0BAD); // die(); } #endif /* CONFIG_MACH_LF_LF1000 */ #ifdef UBOOT_SUPPORT if(((REG32(LF1000_GPIO_BASE+GPIOCPAD) & BUTTON_MSK) == BUTTON_MSK)) { display_init(); displayOn = 1; fbinit(); fbclear(); renderString(5,2,"OpenDidj lightning-boot " LB_VERSION " / " __DATE__ ); renderString(5,4,"Select an option:"); db_puts("OpenDidj lightning-boot " LB_VERSION " / " __DATE__ ); db_puts("\n"); make_crc_table(); timer_init(); offset = 0; // tmr_poll_start(2000); db_puts("Switch to 115200 baud\n"); /* set the baud rate */ UART16(BRD) = 1; /* FIXME (for now "1" sets 115200 baud , "11" sets 19200 baud) */ UART16(UARTCLKGEN) = ((UARTDIV-1)<<UARTCLKDIV)|(UART_PLL<<UARTCLKSRCSEL); // Reggie added for julspower, autoboot if zimage is present on the SD card. ret2 = check_autoboot(&cSel); if ( ret2 == 0 ) { selection=cSel; db_puts("\nAutobooting zImage from SD\n"); goto selection_section; } selection = do_menu(); selection_section: load_address = (u8 *)(UBOOT_ADDR); switch ( selection ) { case 0: goto normal_boot; case 1: goto normal_boot; case 2: goto normal_boot; case 3: xmodemInit(db_putchar,db_getc_async); ret = xmodemReceive(ubcopy); break; case 4: ret = sd_load("u-boot.bin",load_address); break; case 5: ret = sd_load("zImage",load_address); break; case 6: // Reggie added, feature to load lightning-boot.bin from SD // filename *must* be 8.3 or it will fail to load, so lets // make it easy on ourselves and name it lb.bin on the sd load_address = (u8 *)(UBOOT_ADDR2); ret = sd_load("lb.bin",load_address); db_puts("\nLoading Lightning Boot from SD\n"); break; } if ( ret != 0 ) guru_med(selection,ret); db_puts("\nboot jmp\n"); /* jump to u-boot */ ((void (*)( int r0, int r1, int r2))load_address) (0, MACH_TYPE_LF1000, 0); /* never get here! */ guru_med(0x000000F0,0); // die(); } #endif /* UBOOT_SUPPORT */ normal_boot: /* Set up the kernel command line */ /* read entire /flags partition */ nand_read(fs_buffer, BOOT_FLAGS_ADDR, BOOT_FLAGS_SIZE); /* find rootfs file */ node = jffs2_cat((char *)fs_buffer, BOOT_FLAGS_SIZE, "rootfs"); rootfs = RFS0; if(node == 0) { db_puts("warning: failed to find rootfs flags!\n"); } else { rfs_txt = (char*)node+sizeof(struct jffs2_raw_inode)-4; if(!strncmp(rfs_txt, "RFS1", 4)) { db_puts("booting RFS1\n"); // this should be made to use RFS2? rootfs = RFS1; } // Reggie added to check cmdline options, if /flags/rootfs has been set to > RFS1 if (selection==1){ // set to the default SD config just in case the rootfs flag is set for didj(RFS0/1) rootfs = RFS2; db_puts("nand/SD boot\n"); { // if(!strncmp(rfs_txt, "RFS2", 4)) { // db_puts("booting SDRFS\n"); // rootfs = RFS2; // } // else if(!strncmp(rfs_txt, "RFS3", 4)) { if(!strncmp(rfs_txt, "RFS3", 4)) { db_puts("booting nand/SD DEBUG\n"); rootfs = RFS3; } } } #ifdef NFS_SUPPORT else if(!strncmp(rfs_txt, "NFS0", 4)) { db_puts("booting NFS0\n"); rootfs = NFS0; } else if(!strncmp(rfs_txt, "NFS1", 4)) { db_puts("booting NFS1\n"); rootfs = NFS1; } #endif /* NFS_SUPPORT */ else { db_puts("booting RFS0\n"); } } /* Find the mfcart file */ mfg_node = jffs2_cat((char *)fs_buffer, BOOT_FLAGS_SIZE, "mfcart"); if(mfg_node != 0) { db_puts("Booting with mfg cartridge layout.\n"); } else { // Reggie added, setup for custom command line read from /flags/cmdline // try and keep some sanity for the mfcart flag to trump everything, not // sure we really need to worry about the carts at all and could remove // the code? same with the NFS support, although that might come with // future developments if (selection == 2){ rootfs = RFS4; } } /* construct the command line */ if(mfg_node == 0) { if(rootfs == RFS0) { cmdline = CMDLINE_BASE CMDLINE_RFS0 CMDLINE_UBI; altcmdline = CMDLINE_BASE CMDLINE_RFS1 CMDLINE_UBI; kernel_nand_addr = BOOT0_ADDR; alt_kernel_nand_addr = BOOT1_ADDR; } else if(rootfs == RFS1) { cmdline = CMDLINE_BASE CMDLINE_RFS1 CMDLINE_UBI; altcmdline = CMDLINE_BASE CMDLINE_RFS0 CMDLINE_UBI; // Reggie changed, we want to boot the kernel from // kernel0 but the rootfs from RFS1 kernel_nand_addr = BOOT0_ADDR; alt_kernel_nand_addr = BOOT0_ADDR; } // Reggie added, just a copy of the RFS1 boot commands. // the kernel that boots the SD rootfs should be burnt // to kernel1 partition, this way if the SD kernel fails // it will fall back to booting the original kernel0/RFS0 // well, in theory // both RFS2/3 functions boot from the same kernel parition(kernel1) // and the same SD partition (mmcpblk0p2, ext3) // so alt_/kernel_nand_addr are set to BOOT1_ADDR, altcmdline falls // back to the other SD based RFS option else if(rootfs == RFS2) { cmdline = CMDLINE_BASE CMDLINE_RFS2 CMDLINE_UBI; altcmdline = CMDLINE_BASE CMDLINE_RFS3 CMDLINE_UBI; kernel_nand_addr = BOOT1_ADDR; alt_kernel_nand_addr = BOOT1_ADDR; } else if(rootfs == RFS3) { cmdline = CMDLINE_BASE CMDLINE_RFS3 CMDLINE_UBI; altcmdline = CMDLINE_BASE CMDLINE_RFS2 CMDLINE_UBI; kernel_nand_addr = BOOT1_ADDR; alt_kernel_nand_addr = BOOT1_ADDR; } // Reggie also added this, code to read custom cmdline from // a file called "cmdline" on the vfat SD partition, mmcblk0p1 else if (rootfs == RFS4){ // look for cmdline in the root of the vfat partition on the // uSD card and load the contents into cmdline_txt cmdline_load("cmdline", (u8 *)cmdline_txt); db_puts(cmdline_txt); cmdline = (char *)cmdline_txt; altcmdline = CMDLINE_BASE CMDLINE_RFS2 CMDLINE_UBI; // always boot the explorer kernel (BOOT1_ADDR) no matter // how the cmdline is constructed kernel_nand_addr = BOOT1_ADDR; alt_kernel_nand_addr = BOOT1_ADDR; } #ifdef NFS_SUPPORT else if(rootfs == NFS0) { cmdline = CMDLINE_BASE CMDLINE_NFS CMDLINE_UBI; altcmdline = CMDLINE_BASE CMDLINE_NFS CMDLINE_UBI; kernel_nand_addr = BOOT0_ADDR; alt_kernel_nand_addr = BOOT1_ADDR; } else if(rootfs == NFS1) { cmdline = CMDLINE_BASE CMDLINE_NFS CMDLINE_UBI; altcmdline = CMDLINE_BASE CMDLINE_NFS CMDLINE_UBI; kernel_nand_addr = BOOT1_ADDR; alt_kernel_nand_addr = BOOT0_ADDR; } #endif /* NFS_SUPPORT */ } if(tfs_load_summary(sum_buffer, kernel_nand_addr)) { db_puts("warning: booting alternative kernel!\n"); if(tfs_load_summary(sum_buffer, alt_kernel_nand_addr)) { db_puts("PANIC: unable to load alt summary\n"); guru_med(0xA0000000,1); //die(); } } db_stopwatch_start("LOAD KERNEL"); if (rootfs==RFS4){ db_puts("RFS4 loading\n"); image = load_kernel(cmdline); } else{ db_puts("normal cmdline\n"); db_puts(cmdline); image = load_kernel(cmdline); } db_stopwatch_stop(); if(image == 0) { db_puts("Warning: booting alternative kernel!\n"); if(tfs_load_summary(sum_buffer, alt_kernel_nand_addr) != 0) { guru_med(0xA0000000,2); //die(); } image = load_kernel(altcmdline); if(image == 0) { db_puts("PANIC: nothing to boot\n"); guru_med(0xA0000000,3); //die(); } } #ifdef DISPLAY_SUPPORT db_stopwatch_start("SPLASH"); db_puts("Loading bootsplash\n"); tfs_load_file("bootsplash.rgb", (u32 *)FRAME_BUFFER_ADDR); if ( !displayOn ) display_init(); mlc_set_video_mode(); //display_init(); db_stopwatch_stop(); #endif load_cart_id(); db_puts("Starting kernel...\n"); cleanup_for_linux(); /* jump to image (void, architecture ID, atags pointer) */ ((void(*)(int r0, int r1, unsigned int r2))image) (0, MACH_TYPE_LF1000, (unsigned int)params_buffer); /* never get here! */ guru_med(0x000000F0,0); //die(); }