示例#1
0
static void exit_loop_sighandler(int sig)
{
  media_cleanup();
  
  if (main_loop_)
    {
      g_main_loop_quit(main_loop_);
    }
}
示例#2
0
gint main (gint argc, gchar * argv[])
{
  ui_init();
  media_init();
  cortrol_service_init();

  gtk_main();

  media_cleanup();
  cortrol_service_cleanup();

  return 0;
}
示例#3
0
/**
 * Bootloader main entry
 */
int main(void)
{
	uint8_t boot_region = 0; /* Real boot region at this time */
#ifdef DBG_USE_USART
	uint8_t load_region = 0; /* Real region to put loaded data */
#endif
	struct regions_info info;
	void *app_addr = NULL;
	uint32_t app_size = 0;
	enum trigger_modes trigger;
	bool app_valid = false;

	wdt_disable(WDT);
	sysclk_init();
	board_init();

	/* First turn on the led to indicate the bootloader run. */
	ioport_set_pin_dir(DBG_LED_PIN, IOPORT_DIR_OUTPUT);
	ioport_set_pin_level(DBG_LED_PIN, DBG_LED_PIN_ON_LEVEL);

	dbg_init();
	dbg_print("\r\n\n----------------------\r\n");
	dbg_print("%s Bootloader\r\n", BOARD_NAME);
	dbg_print("Boot region: %x, size %dK\r\n", BOOT0_START, BOOT_SIZE /
			1024);
	dbg_print("App  region: %x, size %dK\r\n", APP0_START,
			(int)APP_SIZE / 1024);
	dbg_print(" - Code %dK + Info %dK\r\n", (int)APP_CODE_SIZE,
			(int)INFO_SIZE);
	dbg_print("----------------------\r\n");

	/* bootloader initialize */
	dbg_print("bl: init ...\r\n");
	trigger_init();
	memory_init();
	media_init(file_list, MEDIA_FILE_LIST_LEN);
	dbg_print("bl: init done\r\n");

	boot_region = _app_boot_get();
	dbg_print("bl: current boot region %d\r\n", (int)boot_region);

#ifdef MEM_LOCK_BOOT_REGION
	dbg_print("bl: lock boot region ...\r\n");
	memory_lock((void *)BOOT0_START, (void *)BOOT0_END);
	dbg_print("bl: lock boot region done\r\n");
#endif

	/* load regions information
	 * Single flash: from last page
	 * Dual flash (remap) : from last page of last physical flash
	 * Dual flash (mirror): from last page of boot flash
	 */
	dbg_print("bl: read regions info ...\r\n");
	region_info_read((void *)INFO_ADDR(true), &info); /* Read for boot */

	app_addr = (void *)(APP_START(boot_region));
	app_valid = region_check_valid(app_addr,
			info.length[boot_region], info.signature[boot_region]);
	dbg_print("bl: read regions info done\r\n");
	dbg_print("bl: trigger flag %s\r\n", trigger_modes_str[info.trigger]);
	dbg_print("bl: region\t%8d\t%8d\r\n", 0, 1);
	dbg_print("bl: size\t%8d\t%8d\r\n", (int)info.length[0],
			(int)info.length[1]);
	dbg_print("bl: sign\t%8x\t%8x\r\n", (unsigned)info.signature[0],
			(unsigned)info.signature[1]);
	dbg_print("bl: boot\t       %c\t       %c\r\n", boot_region ? ' ' : 'Y',
			boot_region ? 'Y' : ' ');
	dbg_print("bl: App @ %d, %x - data %x ...\r\n", (int)boot_region,
			(unsigned)app_addr, (unsigned)*(uint32_t *)app_addr);
	dbg_print("bl: App valid: %c\r\n", app_valid ? 'Y' : 'N');

#ifdef DBG_USE_INFO_EDIT
	/* InfoEdit */
	_app_info_edit(&info);
#endif

	/* bootloader trigger check */
	dbg_print("bl: trigger ...\r\n");
	trigger = trigger_poll(&info);
	dbg_print("bl: trigger mode %s\r\n", trigger_modes_str[trigger]);
	if (TRIGGER_BOOT == trigger) {
		goto main_run_app_check;
	}

	/* Now any other trigger load file to update application directly */
#ifdef DBG_USE_LED
	_app_led_blink(100, 1);
#endif
	/* Update media file information */
	if (info.boot_file_name[0]) {
		dbg_print("bl: boot file assigned, set it\r\n");
		media_set_file_name(info.boot_file_name);
	}

main_load_app:
	/* load new firmware */
#ifdef DBG_USE_USART
	load_region = boot_region;
	dbg_print("bl: download @ %d ...\r\n", load_region);
#endif
	app_size = _app_load(&info, true);
	if (app_size == 0) {
		_app_led_error();
		dbg_print("bl: download fail, retry\r\n");
		goto main_load_app;
	} else {
		dbg_print("bl: download done, size %d\r\n", (int)app_size);
	}

main_run_app_check:

	/* Is application valid */
	dbg_print("bl: check app @ %d is valid\r\n", (int)info.boot_region);
	app_valid = region_check_valid(app_addr, info.length[info.boot_region],
			info.signature[info.boot_region]);
	if (!app_valid) {
		dbg_print("bl: application is not valid\r\n");
		_app_led_error();
		dbg_print("bl: reload firmware\r\n");
		goto main_load_app;
	}

	dbg_print("bl: application is valid, run\r\n");


	/* Turn off the led before jump to the app. */
	_app_led_off(DBG_LED_PIN);

	/* cleanup */
	dbg_print("bl: cleanup ...\r\n");
	media_cleanup();
	trigger_cleanup();
	memory_cleanup();
	dbg_print("bl: cleanup done\r\n");

	/* load application */
	dbg_print("bl: load application ...\r\n\n");

#ifdef DBG_USE_USART
	delay_ms(50); /* Wait USART lines idle */

	dbg_cleanup();

	delay_ms(50);
#endif

	/* run application */
	_app_exec(app_addr);

	return (int)app_addr;
}