main.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2012-2014 Wind River Systems, Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <kernel.h>
  7. #include <device.h>
  8. #include <string.h>
  9. #include <soc.h>
  10. #include <recovery.h>
  11. #include <board_cfg.h>
  12. #include <partition/partition.h>
  13. #ifdef CONFIG_WATCHDOG
  14. #include <watchdog_hal.h>
  15. #endif
  16. extern void boot_to_application(void);
  17. extern void boot_to_ota_app(void);
  18. int check_adfu(void)
  19. {
  20. #if IS_ENABLED(CONFIG_TXRX_ADFU)
  21. if(check_adfu_connect(CONFIG_ADFU_TX_GPIO, CONFIG_ADFU_RX_GPIO))
  22. return 1;
  23. #endif
  24. #if IS_ENABLED(CONFIG_GPIO_ADFU)
  25. if(check_adfu_gpiokey(CONFIG_ADFU_KEY_GPIO))
  26. return 1;
  27. #endif
  28. return 0;
  29. }
  30. int main(void)
  31. {
  32. u32_t jtag_flag = 0;
  33. u16_t reboot_type;
  34. u8_t reason;
  35. //soc_watchdog_clear();
  36. #ifdef CONFIG_WATCHDOG
  37. watchdog_clear();
  38. #endif
  39. if(partition_valid_check()){
  40. printk("part invalid,go to ota\n");
  41. goto exit_to_ota;
  42. }
  43. sys_pm_get_reboot_reason(&reboot_type, &reason);
  44. printk("reboot_type0x%x, reason=0x%x\n", reboot_type, reason);
  45. if(reboot_type == REBOOT_TYPE_GOTO_OTA){
  46. printk("reboot to ota\n");
  47. goto exit_to_ota;
  48. }
  49. if(check_adfu()){
  50. jtag_set();
  51. soc_pstore_set(SOC_PSTORE_TAG_FLAG_JTAG, 1);
  52. sys_pm_reboot(REBOOT_TYPE_GOTO_ADFU);
  53. }
  54. soc_pstore_get(SOC_PSTORE_TAG_FLAG_JTAG, &jtag_flag);
  55. if(jtag_flag){
  56. printk("jtag switch\n");
  57. jtag_set();
  58. }
  59. if (ota_upgrade_is_allowed()) {
  60. #if CONFIG_FLASH_LOAD_OFFSET
  61. boot_to_ota_app();
  62. #endif
  63. recovery_main();
  64. }
  65. //soc_watchdog_clear();
  66. #ifdef CONFIG_WATCHDOG
  67. watchdog_clear();
  68. #endif
  69. boot_to_application();
  70. sys_pm_reboot(REBOOT_TYPE_GOTO_OTA);
  71. exit_to_ota:
  72. // boot fail enter ota
  73. if(ota_main())// ota fail reboot adfu
  74. sys_pm_reboot(REBOOT_TYPE_GOTO_ADFU);
  75. else // ota ok reboot system
  76. sys_pm_reboot(REBOOT_TYPE_NORMAL);
  77. return 0;
  78. }