Advertisement
Guest User

u-boot: ub_dev_write storage support

a guest
Jul 12th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.33 KB | None | 0 0
  1. From 8d05ccdea2fa533d6427acfe5b78300984344d5e Mon Sep 17 00:00:00 2001
  2. From: Ihar Filipau <[email protected]>
  3. Date: Tue, 12 Jul 2016 13:27:02 +0200
  4. Subject: [PATCH] storage device support for ub_dev_write
  5.  
  6. I have stumbled upon the lack of support for storage devices in API's
  7. ub_dev_write()/API_dev_write() functions. Currently the function
  8. supports only the network devices.
  9.  
  10. I have implemented the support for the storage by adapting the code
  11. from API_dev_read() function, and added the ub_dev_write() to the
  12. glue.c. Interface for the network devices is unchanged.
  13.  
  14. I could only test the ub_dev_write() for storage, but my application
  15. doesn't use the ub_dev_send() thus I can't test it (but 99% sure that
  16. it still works).
  17.  
  18. P.S. Do not blame me for the formatting inconsistent with the rest of
  19. the file - patman has insisted.
  20.  
  21.  
  22. Signed-off-by: Ihar Filipau <[email protected]>
  23. ---
  24.  
  25. api/api.c | 90 +++++++++++++++++++++++++++++++++++------------------
  26. api/api_private.h | 1 +
  27. api/api_storage.c | 21 +++++++++++++
  28. examples/api/glue.c | 20 ++++++++++++
  29. 4 files changed, 102 insertions(+), 30 deletions(-)
  30.  
  31. diff --git a/api/api.c b/api/api.c
  32. index 8a1433a..2ce5d07 100644
  33. --- a/api/api.c
  34. +++ b/api/api.c
  35. @@ -295,28 +295,44 @@ static int API_dev_close(va_list ap)
  36.  
  37.  
  38. /*
  39. - * Notice: this is for sending network packets only, as U-Boot does not
  40. - * support writing to storage at the moment (12.2007)
  41. + * pseudo signature, storage:
  42. *
  43. - * pseudo signature:
  44. + * int API_dev_write(
  45. + * struct device_info *di,
  46. + * void *buf,
  47. + * lbasize_t *len,
  48. + * lbastart_t *start,
  49. + * lbasize_t *act_len
  50. + * )
  51. *
  52. - * int API_dev_write(
  53. - * struct device_info *di,
  54. - * void *buf,
  55. - * int *len
  56. - * )
  57. + * pseudo signature, net:
  58. + *
  59. + * int API_dev_write(
  60. + * struct device_info *di,
  61. + * void *buf,
  62. + * int *len
  63. + * )
  64. + *
  65. + * buf: ptr to buffer with data to write
  66. *
  67. - * buf: ptr to buffer from where to get the data to send
  68. + * len: length to be written
  69. + * - network: len of packet to write (in bytes)
  70. + * - storage: # of blocks to write (can vary in size depending on define)
  71. *
  72. - * len: length of packet to be sent (in bytes)
  73. + * start: start block (only used for storage devices, ignored for
  74. + * network)
  75. + *
  76. + * act_len: ptr to where to put the len actually written
  77. *
  78. */
  79. static int API_dev_write(va_list ap)
  80. {
  81. struct device_info *di;
  82. void *buf;
  83. - int *len;
  84. - int err = 0;
  85. + lbasize_t *len_stor, *act_len_stor;
  86. + lbastart_t *start;
  87. + int *len_net;
  88. + int ret = 0;
  89.  
  90. /* 1. arg is ptr to the device_info struct */
  91. di = (struct device_info *)va_arg(ap, uintptr_t);
  92. @@ -328,31 +344,45 @@ static int API_dev_write(va_list ap)
  93. if (di->cookie == NULL)
  94. return API_ENODEV;
  95.  
  96. - /* 2. arg is ptr to buffer from where to get data to write */
  97. + /* 2. arg is ptr to buffer from where to put the read data */
  98. buf = (void *)va_arg(ap, uintptr_t);
  99. if (buf == NULL)
  100. return API_EINVAL;
  101.  
  102. - /* 3. arg is length of buffer */
  103. - len = (int *)va_arg(ap, uintptr_t);
  104. - if (len == NULL)
  105. - return API_EINVAL;
  106. - if (*len <= 0)
  107. - return API_EINVAL;
  108. + if (di->type & DEV_TYP_STOR) {
  109. + /* 3. arg - ptr to var with # of blocks to read */
  110. + len_stor = (lbasize_t *)va_arg(ap, uintptr_t);
  111. + if (!len_stor)
  112. + return API_EINVAL;
  113. + if (*len_stor <= 0)
  114. + return API_EINVAL;
  115.  
  116. - if (di->type & DEV_TYP_STOR)
  117. - /*
  118. - * write to storage is currently not supported by U-Boot:
  119. - * no storage device implements block_write() method
  120. - */
  121. - return API_ENODEV;
  122. + /* 4. arg - ptr to var with start block */
  123. + start = (lbastart_t *)va_arg(ap, uintptr_t);
  124.  
  125. - else if (di->type & DEV_TYP_NET)
  126. - err = dev_write_net(di->cookie, buf, *len);
  127. - else
  128. - err = API_ENODEV;
  129. + /* 5. arg - ptr to var where to put the len actually read */
  130. + act_len_stor = (lbasize_t *)va_arg(ap, uintptr_t);
  131. + if (!act_len_stor)
  132. + return API_EINVAL;
  133.  
  134. - return err;
  135. + *act_len_stor = dev_write_stor(di->cookie, buf, *len_stor,
  136. + *start);
  137. +
  138. + } else if (di->type & DEV_TYP_NET) {
  139. + /* 3. arg points to the var with length of packet to read */
  140. + len_net = (int *)va_arg(ap, uintptr_t);
  141. + if (!len_net)
  142. + return API_EINVAL;
  143. + if (*len_net <= 0)
  144. + return API_EINVAL;
  145. +
  146. + ret = dev_write_net(di->cookie, buf, *len_net);
  147. +
  148. + } else {
  149. + return API_ENODEV;
  150. + }
  151. +
  152. + return ret;
  153. }
  154.  
  155.  
  156. diff --git a/api/api_private.h b/api/api_private.h
  157. index a8866ef..86d45bc 100644
  158. --- a/api/api_private.h
  159. +++ b/api/api_private.h
  160. @@ -23,6 +23,7 @@ int dev_close_stor(void *);
  161. int dev_close_net(void *);
  162.  
  163. lbasize_t dev_read_stor(void *, void *, lbasize_t, lbastart_t);
  164. +lbasize_t dev_write_stor(void *, void *, lbasize_t, lbastart_t);
  165. int dev_read_net(void *, void *, int);
  166. int dev_write_net(void *, void *, int);
  167.  
  168. diff --git a/api/api_storage.c b/api/api_storage.c
  169. index d425a9a..efb23c1 100644
  170. --- a/api/api_storage.c
  171. +++ b/api/api_storage.c
  172. @@ -365,3 +365,24 @@ lbasize_t dev_read_stor(void *cookie, void *buf, lbasize_t len, lbastart_t start
  173.  
  174. return dd->block_read(dd, start, len, buf);
  175. }
  176. +
  177. +lbasize_t dev_write_stor(void *cookie, void *buf, lbasize_t len,
  178. + lbastart_t start)
  179. +{
  180. + int type;
  181. + block_dev_desc_t *dd = (block_dev_desc_t *)cookie;
  182. +
  183. + type = dev_stor_type(dd);
  184. + if (type == ENUM_MAX)
  185. + return 0;
  186. +
  187. + if (!dev_stor_is_valid(type, dd))
  188. + return 0;
  189. +
  190. + if ((dd->block_write) == NULL) {
  191. + debugf("no block_write() for device 0x%08x\n", cookie);
  192. + return 0;
  193. + }
  194. +
  195. + return dd->block_write(dev_stor_index(dd), start, len, buf);
  196. +}
  197. diff --git a/examples/api/glue.c b/examples/api/glue.c
  198. index 8aabf32..1a1b69b 100644
  199. --- a/examples/api/glue.c
  200. +++ b/examples/api/glue.c
  201. @@ -290,6 +290,26 @@ int ub_dev_read(int handle, void *buf, lbasize_t len, lbastart_t start,
  202. return err;
  203. }
  204.  
  205. +int ub_dev_write(int handle, void *buf, lbasize_t len, lbastart_t start,
  206. + lbasize_t *rlen)
  207. +{
  208. + struct device_info *di;
  209. + lbasize_t act_len;
  210. + int err = 0;
  211. +
  212. + if (!dev_stor_valid(handle))
  213. + return API_ENODEV;
  214. +
  215. + di = &devices[handle];
  216. + if (!syscall(API_DEV_WRITE, &err, di, buf, &len, &start, &act_len))
  217. + return API_ESYSC;
  218. +
  219. + if (!err && rlen)
  220. + *rlen = act_len;
  221. +
  222. + return err;
  223. +}
  224. +
  225. static int dev_net_valid(int handle)
  226. {
  227. if (!dev_valid(handle))
  228. --
  229. 1.9.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement