boot_pdl.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* Copyright (C) 2019 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _BOOT_PDL_H_
  13. #define _BOOT_PDL_H_
  14. #include "osi_compiler.h"
  15. #include "boot_fdl_channel.h"
  16. OSI_EXTERN_C_BEGIN
  17. /**
  18. * \brief opaque data struct for pdl engine
  19. *
  20. * PDL protocol is only used in 8910 ROM now. and 8910 bootloader
  21. * implements a minimal feature set to mimic ROM. It won't be used later,
  22. * and many irrelevent features are ignored.
  23. */
  24. typedef struct pdlEngine pdlEngine_t;
  25. /**
  26. * \brief pdl command header
  27. *
  28. * The is common to all commands. That is, the first word of command is
  29. * the command type.
  30. */
  31. typedef struct
  32. {
  33. uint32_t cmd_type; ///< command type
  34. uint32_t payload[0]; ///< command dependent data
  35. } pdlCommand_t;
  36. /**
  37. * \brief pdl data command header
  38. */
  39. typedef struct
  40. {
  41. uint32_t cmd_type; ///< command type
  42. uint32_t address; ///< data address
  43. uint32_t size; ///< size, different meaning on varioud command types
  44. uint32_t data[0]; ///< command dependent data
  45. } pdlDataCommand_t;
  46. typedef enum
  47. {
  48. PDL_CMD_CONNECT = 0,
  49. PDL_CMD_START_DATA = 4,
  50. PDL_CMD_MID_DATA,
  51. PDL_CMD_END_DATA,
  52. PDL_CMD_EXEC_DATA,
  53. } pdlCommandType_t;
  54. typedef enum
  55. {
  56. PDL_RESP_ACK = 0,
  57. PDL_RESP_PACKET_ERROR,
  58. PDL_RESP_INVALID_CMD,
  59. PDL_RESP_UNKNOWN_CMD,
  60. PDL_RESP_INVALID_ADDR,
  61. PDL_RESP_INVALID_BAUDRATE,
  62. PDL_RESP_INVALID_PARTITION,
  63. PDL_RESP_INVALID_SIZE,
  64. PDL_RESP_WAIT_TIMEOUT,
  65. PDL_RESP_VERIFY_ERROR,
  66. PDL_RESP_CHECKSUM_ERROR,
  67. PDL_RESP_OPERATION_FAILED,
  68. PDL_RESP_DEVICE_ERROR,
  69. } pdlRespType_t;
  70. /**
  71. * \brief pdl command process callback
  72. *
  73. * \param pdl the pdl engine
  74. * \param param callback context
  75. * \param cmd pdl command
  76. * \param size total size of command, including command header
  77. */
  78. typedef void (*pdlCmdProcess_t)(pdlEngine_t *pdl, void *param, pdlCommand_t *cmd, unsigned size);
  79. /**
  80. * \brief pdl polling callback
  81. *
  82. * \param pdl the pdl engine
  83. * \param param callback context
  84. * \return true for continnue, false for quit
  85. */
  86. typedef bool (*pdlPolling_t)(pdlEngine_t *pdl, void *param);
  87. /**
  88. * \brief create pdl engine
  89. *
  90. * \param ch uart or usb channel
  91. * \param max_len maximum payload len
  92. * \return
  93. * - the create pdl engine
  94. * - NULL on failed, out of memory
  95. */
  96. pdlEngine_t *pdlEngineCreate(fdlChannel_t *ch, unsigned max_len);
  97. /**
  98. * \brief delete the pdl engine
  99. *
  100. * \param d pdl engine
  101. */
  102. void pdlEngineDelete(pdlEngine_t *d);
  103. /**
  104. * \brief start pdl engine loop
  105. *
  106. * \param d pdl engine
  107. * \param proc command process callback
  108. * \param polling polling callback
  109. * \param param callback context
  110. * \return false on failed, never return true
  111. */
  112. bool pdlEngineLoop(pdlEngine_t *d, pdlCmdProcess_t proc, pdlPolling_t polling, void *param);
  113. /**
  114. * \brief send response without data
  115. *
  116. * \param d pdl engine
  117. * \param resp response code
  118. */
  119. void pdlEngineSendResp(pdlEngine_t *d, pdlRespType_t resp);
  120. /**
  121. * \brief download uimage with pdl protocol
  122. *
  123. * \param ch uart or usb channel
  124. * \param callparam parameter at jump to uimage
  125. * \param start starting address of reserved region
  126. * \param size size of reserved region
  127. * \param timeout timeout for connection, 0 for wait forever
  128. * \return
  129. * - true for timeout
  130. * - false on error
  131. */
  132. bool pdlDnldUimage(fdlChannel_t *ch, unsigned callparam, unsigned start, unsigned size, unsigned timeout);
  133. OSI_EXTERN_C_END
  134. #endif