Revision 10687985 devices/PowerManagement/main.cpp

View differences:

devices/PowerManagement/main.cpp
45 45

  
46 46
Global global;
47 47

  
48
struct blVersion_t {
49
  const uint8_t identifier;
50
  const uint8_t major;
51
  const uint8_t minor;
52
  const uint8_t patch;
53
} __attribute__((packed));
54

  
48 55
void shutdownTimeoutISR(void *arg) {
49 56

  
50 57
  (void) arg;
......
828 835

  
829 836
void shellRequestGetBootloaderInfo(BaseSequentialStream* chp, int argc, char *argv[]) {
830 837
  // check the magic number
831
  if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == BL_MAGIC_NUMBER) {
832
    chprintf(chp, "Bootloader version:  %u.%u.%u\n",
833
             *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))),
834
             *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))),
835
             *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (3*4))));
836
    chprintf(chp, "Callback functions:\n");
837
    if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 2) {
838
      chprintf(chp, "\thibernate:      %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (4*4))) ? "available" : "unsupported");
839
      chprintf(chp, "\tdeepsleep:      %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (5*4))) ? "available" : "unsupported");
840
      chprintf(chp, "\ttransportation: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (6*4))) ? "available" : "unsupported");
841
      chprintf(chp, "\trestart:        %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (10*4))) ? "available" : "unsupported");
842
    } else if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 3) {
843
      chprintf(chp, "\thibernate:      %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (4*4))) ? "available" : "unsupported");
844
      chprintf(chp, "\tdeepsleep:      %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (5*4))) ? "available" : "unsupported");
845
      chprintf(chp, "\ttransportation: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (6*4))) ? "available" : "unsupported");
846
      chprintf(chp, "\trestart:        %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (7*4))) ? "available" : "unsupported");
847
      chprintf(chp, "\thandle request: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (8*4))) ? "available" : "unsupported");
848
    }
849
  } else {
850
    chprintf((BaseSequentialStream*) &SD1, "Bootloader deprecated\n");
838
  switch (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR))) {
839
    case (('A'<<24) | ('-'<<16) | ('B'<<8) | ('L'<<0)):
840
      chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n",
841
               ((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->major,
842
               ((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->minor,
843
               ((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->patch);
844
      break;
845

  
846
    case BL_MAGIC_NUMBER:
847
      chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n",
848
               *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))),
849
               *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))),
850
               *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))));
851
      break;
852

  
853
    default:
854
      chprintf((BaseSequentialStream*) &SD1, "Bootloader incompatible\n");
855
      break;
851 856
  }
852 857

  
853 858
  return;
......
951 956

  
952 957
  chprintf((BaseSequentialStream*) &SD1, "\n");
953 958
  chprintf((BaseSequentialStream*) &SD1, BOARD_NAME " " BOARD_VERSION "\n");
954
  if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == BL_MAGIC_NUMBER) {
955
    chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n",
956
             *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))),
957
             *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))),
958
             *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (3*4))));
959
  } else {
960
    chprintf((BaseSequentialStream*) &SD1, "Bootloader deprecated\n");
959
  switch (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR))) {
960
    case (('A'<<24) | ('-'<<16) | ('B'<<8) | ('L'<<0)):
961
      chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n",
962
               ((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->major,
963
               ((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->minor,
964
               ((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->patch);
965
      break;
966

  
967
    case BL_MAGIC_NUMBER:
968
      chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n",
969
               *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))),
970
               *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))),
971
               *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))));
972
      break;
973

  
974
    default:
975
      chprintf((BaseSequentialStream*) &SD1, "Bootloader incompatible\n");
976
      break;
961 977
  }
962 978
  chprintf((BaseSequentialStream*) &SD1, "ChibiOS " CH_KERNEL_VERSION "\n");
963 979
  // make sure that the info text is completetly printed
......
1084 1100
     * next wall or something like that.
1085 1101
     */
1086 1102
    if (shutdown_now != SHUTDOWN_NONE) {
1087
      if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) != BL_MAGIC_NUMBER) {
1103
      if ((*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) != (('A'<<24) | ('-'<<16) | ('B'<<8) | ('L'<<0))) && (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) != BL_MAGIC_NUMBER)) {
1088 1104
        chprintf((BaseSequentialStream*) &SD1, "ERROR: unable to shut down (bootloader deprecated).\n");
1089 1105
        shutdown_now = SHUTDOWN_NONE;
1090 1106
      } else {
1091 1107
        uint32_t blCallbackPtrAddr = BL_CALLBACK_TABLE_ADDR;
1092
        if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 2) {
1108
        // handle bootloader version 0.2.x
1109
        if ((*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == BL_MAGIC_NUMBER) &&
1110
            (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 2)) {
1093 1111
          switch (shutdown_now) {
1094 1112
            case SHUTDOWN_TRANSPORTATION:
1095 1113
              blCallbackPtrAddr += 6 * 4;
......
1108 1126
              blCallbackPtrAddr = 0;
1109 1127
              break;
1110 1128
          }
1111
        } else if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 3) {
1129
        }
1130
        // handle bootloader version 0.3.x
1131
        else if ((*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == BL_MAGIC_NUMBER) &&
1132
                 (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 3)) {
1133
          switch (shutdown_now) {
1134
            case SHUTDOWN_TRANSPORTATION:
1135
              blCallbackPtrAddr += 6 * 4;
1136
              break;
1137
            case SHUTDOWN_DEEPSLEEP:
1138
              blCallbackPtrAddr += 5 * 4;
1139
              break;
1140
            case SHUTDOWN_HIBERNATE:
1141
              blCallbackPtrAddr += 4 * 4;
1142
              break;
1143
            case SHUTDOWN_RESTART:
1144
              blCallbackPtrAddr += 7 * 4;
1145
              break;
1146
            case SHUTDOWN_HANDLE_REQUEST:
1147
              blCallbackPtrAddr += 8 * 4;
1148
              break;
1149
            default:
1150
              blCallbackPtrAddr = 0;
1151
              break;
1152
          }
1153
        }
1154
        // handle bootloader version 1.0.x
1155
        else if ((*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == (('A'<<24) | ('-'<<16) | ('B'<<8) | ('L'<<0))) &&
1156
                 ((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->major == 1 && ((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->minor == 0) {
1112 1157
          switch (shutdown_now) {
1113 1158
            case SHUTDOWN_TRANSPORTATION:
1114 1159
              blCallbackPtrAddr += 6 * 4;
......
1132 1177
        }
1133 1178

  
1134 1179
        void (*blCallback)(void) = NULL;
1135
        if (blCallbackPtrAddr) {
1180
        if (blCallbackPtrAddr > BL_CALLBACK_TABLE_ADDR) {
1136 1181
          blCallback = (void (*)(void))(*((uint32_t*)blCallbackPtrAddr));
1137 1182

  
1138 1183
          if (!blCallback) {

Also available in: Unified diff