shell_dbg.c 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363
  1. /*
  2. * Copyright (c) 2020 Actions Semiconductor
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <sys/printk.h>
  7. #include <shell/shell.h>
  8. #include <init.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <device.h>
  12. #include <sdfs.h>
  13. #include <soc.h>
  14. #include <board_cfg.h>
  15. #include <fs/fs.h>
  16. #include <rbuf/rbuf_mem.h>
  17. #include <rbuf/rbuf_pool.h>
  18. #include <errno.h>
  19. #include <limits.h>
  20. #include <debug/ramdump.h>
  21. #define MAX_LINE_LENGTH_BYTES (64)
  22. #define DEFAULT_LINE_LENGTH_BYTES (16)
  23. #define MAX_MEM_SIZE (32*1024*1024)
  24. void print_buffer(const struct shell *shell,const char *addr, int width,
  25. int count, int linelen, unsigned long disp_addr)
  26. {
  27. int i, thislinelen;
  28. const char *data;
  29. /* linebuf as a union causes proper alignment */
  30. union linebuf {
  31. uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1];
  32. uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1];
  33. uint8_t uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1];
  34. } lb;
  35. if (linelen * width > MAX_LINE_LENGTH_BYTES)
  36. linelen = MAX_LINE_LENGTH_BYTES / width;
  37. if (linelen < 1)
  38. linelen = DEFAULT_LINE_LENGTH_BYTES / width;
  39. if (disp_addr == -1)
  40. disp_addr = (unsigned long)addr;
  41. while (count) {
  42. thislinelen = linelen;
  43. data = (const char *)addr;
  44. shell_fprintf(shell, SHELL_NORMAL, "%08x:", (unsigned int)disp_addr);
  45. /* check for overflow condition */
  46. if (count < thislinelen)
  47. thislinelen = count;
  48. /* Copy from memory into linebuf and print hex values */
  49. for (i = 0; i < thislinelen; i++) {
  50. if (width == 4) {
  51. lb.ui[i] = *(volatile uint32_t *)data;
  52. shell_fprintf(shell, SHELL_NORMAL, " %08x", lb.ui[i]);
  53. } else if (width == 2) {
  54. lb.us[i] = *(volatile uint16_t *)data;
  55. shell_fprintf(shell, SHELL_NORMAL, " %04x", lb.us[i]);
  56. } else {
  57. lb.uc[i] = *(volatile uint8_t *)data;
  58. shell_fprintf(shell, SHELL_NORMAL, " %02x", lb.uc[i]);
  59. }
  60. data += width;
  61. }
  62. while (thislinelen < linelen) {
  63. /* fill line with whitespace for nice ASCII print */
  64. for (i = 0; i < width * 2 + 1; i++)
  65. shell_fprintf(shell, SHELL_NORMAL, " ");
  66. linelen--;
  67. }
  68. /* Print data in ASCII characters */
  69. for (i = 0; i < thislinelen * width; i++) {
  70. if (lb.uc[i] < 0x20 || lb.uc[i] > 0x7e)
  71. lb.uc[i] = '.';
  72. }
  73. lb.uc[i] = '\0';
  74. shell_fprintf(shell, SHELL_NORMAL, " %s\n", lb.uc);
  75. /* update references */
  76. addr += thislinelen * width;
  77. disp_addr += thislinelen * width;
  78. count -= thislinelen;
  79. }
  80. }
  81. #if defined(CONFIG_CMD_MEMORY)
  82. #define DISP_LINE_LEN 16
  83. static int do_mem_mw(const struct shell *shell, int width, size_t argc, char **argv)
  84. {
  85. unsigned long writeval;
  86. unsigned long addr, count;
  87. char *buf;
  88. char *pend;
  89. if (argc < 3)
  90. return -EINVAL;
  91. addr = strtoul(argv[1], NULL, 16);
  92. writeval = strtoul(argv[2], NULL, 16);
  93. if (argc == 4) {
  94. errno = 0;
  95. count = strtoul(argv[3], &pend, 16);
  96. if ((pend == argv[3] || *pend != '\0') || errno == ERANGE || count > MAX_MEM_SIZE) {
  97. shell_print(shell, "params invalid.\n");
  98. return -EINVAL;
  99. }
  100. } else {
  101. count = 1;
  102. }
  103. buf = (char *)addr;
  104. if (count != ULONG_MAX) {
  105. if(count > 0) {
  106. while (count-- > 0) {
  107. if (width == 4)
  108. *((uint32_t *)buf) = (uint32_t)writeval;
  109. else if (width == 2)
  110. *((uint16_t *)buf) = (uint16_t)writeval;
  111. else
  112. *((uint8_t *)buf) = (uint8_t)writeval;
  113. buf += width;
  114. }
  115. }
  116. }
  117. return 0;
  118. }
  119. static int do_mem_md(const struct shell *shell, int width, size_t argc, char **argv)
  120. {
  121. unsigned long addr;
  122. unsigned long count;
  123. char *pend;
  124. if (argc < 2)
  125. return -EINVAL;
  126. addr = strtoul(argv[1], NULL, 16);
  127. if (argc == 3) {
  128. errno = 0;
  129. count = strtoul(argv[2], &pend, 16);
  130. if ((pend == argv[2] || *pend != '\0') || errno == ERANGE || count > MAX_MEM_SIZE) {
  131. shell_print(shell, "params invalid.\n");
  132. count = 0;
  133. return -EINVAL;
  134. }
  135. } else {
  136. count = 1;
  137. }
  138. if (count != ULONG_MAX) {
  139. print_buffer(shell, (char *)addr, width, count, DISP_LINE_LEN / width, -1);
  140. }
  141. return 0;
  142. }
  143. static int shell_cmd_mdw(const struct shell *shell, size_t argc, char **argv)
  144. {
  145. return do_mem_md(shell, 4, argc, argv);
  146. }
  147. static int shell_cmd_mdh(const struct shell *shell, size_t argc, char **argv)
  148. {
  149. return do_mem_md(shell,2, argc, argv);
  150. }
  151. static int shell_cmd_mdb(const struct shell *shell, size_t argc, char **argv)
  152. {
  153. return do_mem_md(shell,1, argc, argv);
  154. }
  155. static int shell_cmd_mww(const struct shell *shell, size_t argc, char **argv)
  156. {
  157. return do_mem_mw(shell,4, argc, argv);
  158. }
  159. static int shell_cmd_mwh(const struct shell *shell, size_t argc, char **argv)
  160. {
  161. return do_mem_mw(shell, 2, argc, argv);
  162. }
  163. static int shell_cmd_mwb(const struct shell *shell, size_t argc, char **argv)
  164. {
  165. return do_mem_mw(shell, 1, argc, argv);
  166. }
  167. #endif /* CONFIG_CMD_MEMORY */
  168. #if defined(CONFIG_SOC_SPICACHE_PROFILE)
  169. #include <spicache.h>
  170. void spicache_profile_dump(const struct shell *shell, struct spicache_profile *profile)
  171. {
  172. uint32_t interval_ms, total,hit;
  173. if (!profile)
  174. return;
  175. shell_print(shell,"s-e timer:%d, %d\n", profile->start_time, profile->end_time);
  176. interval_ms = (uint32_t) k_cyc_to_ms_floor32(profile->end_time-profile->start_time);
  177. shell_print(shell, "spicache profile: addr range 0x%08x ~ 0x%08x, profile time %d ms\n",
  178. profile->start_addr, profile->end_addr, interval_ms);
  179. hit = profile->hit_cnt*8;
  180. total = (hit + profile->miss_cnt);
  181. if (total != 0)
  182. shell_print(shell, " hit: %12d miss: %12d hit ratio: %d%%\n",
  183. hit, profile->miss_cnt,
  184. hit/ (total / 100));
  185. else
  186. shell_print(shell, "cpu not run into the specific address range!\n");
  187. if (!profile->spi_id) {
  188. hit = profile->total_hit_cnt*8;
  189. total = (hit + profile->total_miss_cnt);
  190. if (total != 0)
  191. shell_print(shell, "totoal hit: %12d totoal miss: %12d hit ratio: %d%%\n\n",
  192. hit, profile->total_miss_cnt,
  193. hit / (total / 100));
  194. } else {
  195. hit = profile->dma_hit_cnt*8;
  196. total = (hit + profile->dma_miss_cnt);
  197. if (total != 0)
  198. shell_print(shell, "dma hit: %12d dma miss: %12d hit ratio: %d%%\n\n",
  199. hit, profile->dma_miss_cnt,
  200. hit / (total / 100));
  201. }
  202. }
  203. static struct spicache_profile __act_s2_notsave profile_data;
  204. /*
  205. * cmd: spicache_profile
  206. * start start_addr end_addr
  207. * stop
  208. */
  209. static int shell_cmd_spicache_profile(const struct shell *shell,
  210. size_t argc, char **argv)
  211. {
  212. struct spicache_profile *profile;
  213. int len = strlen(argv[1]);
  214. profile = &profile_data;
  215. if (!strncmp(argv[1], "start", len)) {
  216. if (argc < 5)
  217. return -EINVAL;
  218. profile->spi_id = strtoul(argv[2], NULL, 0);
  219. if ((profile->spi_id != 0) && (profile->spi_id != 1)) {
  220. shell_print(shell, "invalid spi id:%d\n", profile->spi_id);
  221. return -EINVAL;
  222. }
  223. profile->start_addr = strtoul(argv[3], NULL, 0);
  224. profile->end_addr = strtoul(argv[4], NULL, 0);
  225. shell_print(shell, "Start profile: spi_id addr range %08x ~ %08x\n",
  226. profile->start_addr, profile->end_addr);
  227. spicache_profile_start(profile);
  228. } else if (!strncmp(argv[1], "stop", len)) {
  229. shell_print(shell, "Stop profile\n");
  230. spicache_profile_stop(profile);
  231. spicache_profile_dump(shell,profile);
  232. } else {
  233. shell_print(shell, "usage:\n");
  234. shell_print(shell, " spicache_profile start start_addr end_addr\n");
  235. shell_print(shell, " spicache_profile stop\n");
  236. return -EINVAL;
  237. }
  238. return 0;
  239. }
  240. #endif /* CONFIG_SOC_SPICACHE_PROFILE */
  241. int print_buf(const struct shell *shell, char *ptr, int len)
  242. {
  243. int i;
  244. shell_print(shell,"\n");
  245. for(i = 0; i < len; i++)
  246. {
  247. if(i % 16 == 0)
  248. printk("%8x: ", i);
  249. //shell_print(shell,"%d: ", i);
  250. //shell_print(shell,"%x ", *ptr++);
  251. printk("%2x ", *ptr++);
  252. if(i % 16 == 15)
  253. //shell_print(shell,"\n");
  254. printk("\n");
  255. }
  256. //shell_print(shell,"\n");
  257. printk("\n");
  258. return 0;
  259. }
  260. #if defined(CONFIG_CMD_SPINOR)
  261. #include <drivers/flash.h>
  262. #define READ_BLOCK_ONCE 512
  263. int test_read_speed(const struct shell *shell, const struct device *nor_dev, uint32_t offset, uint32_t size)
  264. {
  265. uint64_t start_ms;
  266. uint32_t k, btn_ms;
  267. int ret;
  268. char *buf = k_malloc(READ_BLOCK_ONCE);
  269. if(buf == NULL){
  270. shell_print(shell, "malloc fail\n");
  271. return -1;
  272. }
  273. shell_print(shell, "nor read speed size=%d kb, offset=0x%x\n", size/1024, offset);
  274. //flash_read(nor_dev, 0x0, buf, READ_BLOCK_ONCE);
  275. //print_buf(buf);
  276. start_ms = k_uptime_get();
  277. for(k = 0; k < size; k += READ_BLOCK_ONCE, offset+=READ_BLOCK_ONCE) {
  278. ret = flash_read((const struct device *)nor_dev, offset, buf, READ_BLOCK_ONCE);
  279. if(ret < 0 ) {
  280. shell_print(shell, "flash read fail\n");
  281. break;
  282. }
  283. }
  284. btn_ms = k_uptime_get() - start_ms;
  285. if(btn_ms == 0)
  286. btn_ms = 1;
  287. k_free(buf);
  288. shell_print(shell, "use %d ms, read once=%d, nor speed =%d kb/s\n", btn_ms, READ_BLOCK_ONCE, (size/1024)*1000/btn_ms );
  289. return 0;
  290. }
  291. int test_write_speed(const struct shell *shell, const struct device *nor_dev, uint32_t offset, uint32_t size)
  292. {
  293. uint64_t start_ms;
  294. uint32_t k, btn_ms, off, i;
  295. int ret;
  296. uint32_t *buf = k_malloc(READ_BLOCK_ONCE);
  297. if(buf == NULL){
  298. shell_print(shell, "malloc fail\n");
  299. return -1;
  300. }
  301. for(k = 0; k < READ_BLOCK_ONCE/4; k++)
  302. buf[k] = k;
  303. shell_print(shell,"nor write speed test, size=%d kb, offset=0x%x\n", size/1024, offset);
  304. off = offset;
  305. #if 1
  306. start_ms = k_uptime_get();
  307. //for(k = 0; k < size; k+=0x10000) {
  308. ret = flash_erase(nor_dev, offset, size);
  309. //ret = flash_erase(nor_dev, offset, size);
  310. if(ret < 0 ) {
  311. shell_print(shell,"flash erase fail\n");
  312. }
  313. //}
  314. btn_ms = k_uptime_get() - start_ms;
  315. if(btn_ms == 0)
  316. btn_ms = 1;
  317. shell_print(shell, "erase use %d ms, erase speed=%d kb/s\n", btn_ms, (size/1024)*1000/btn_ms);
  318. #endif
  319. start_ms = k_uptime_get();
  320. for(k = 0; k < size; k += READ_BLOCK_ONCE, offset+=READ_BLOCK_ONCE) {
  321. ret = flash_write(nor_dev, offset, buf, READ_BLOCK_ONCE);
  322. if(ret < 0 ) {
  323. shell_print(shell,"flash write fail\n");
  324. break;
  325. }
  326. }
  327. btn_ms = k_uptime_get() - start_ms;
  328. if(btn_ms == 0)
  329. btn_ms = 1;
  330. shell_print(shell, "use %d ms, write once=%d, nor speed =%d kb/s\n", btn_ms, READ_BLOCK_ONCE, (size/1024)*1000/btn_ms );
  331. shell_print(shell,"--cmp write and read---\n");
  332. for(k = 0; k < size; k += READ_BLOCK_ONCE, off+=READ_BLOCK_ONCE) {
  333. ret = flash_read(nor_dev, off, buf, READ_BLOCK_ONCE);
  334. if(ret < 0 ) {
  335. shell_print(shell,"flash read fail\n");
  336. break;
  337. }
  338. for(i = 0; i < READ_BLOCK_ONCE/4; i++) {
  339. if(buf[i] != i){
  340. shell_print(shell,"cmp fail: off=0x%x,val=0x%x != 0x%x\n", (off+i*4), buf[i], i);
  341. break;
  342. }
  343. }
  344. }
  345. shell_print(shell,"--cmp finshed ---\n");
  346. k_free(buf);
  347. return 0;
  348. }
  349. #define SPEEDFFSET 0x20000
  350. #define SPEEDSIZE 0xe0000
  351. int shell_nor_speed_test(const struct shell *shell,
  352. size_t argc, char **argv)
  353. {
  354. uint32_t offset, size;
  355. char *pend;
  356. const struct device *nor_dev = device_get_binding(CONFIG_SPI_FLASH_NAME);
  357. if (!nor_dev) {
  358. shell_print(shell,"nor dev binding failed!\n");
  359. return EINVAL;
  360. }
  361. if(argc == 3){
  362. offset = strtoul(argv[1], &pend, 0);
  363. size = strtoul(argv[2], &pend, 0);
  364. }else{
  365. offset = SPEEDFFSET;
  366. size = SPEEDSIZE;
  367. }
  368. shell_print(shell,"nor test: offset=0x%x, size=0x%x\n", offset, size);
  369. test_read_speed(shell, nor_dev, offset, size);
  370. test_write_speed(shell, nor_dev, offset, size);
  371. return 0;
  372. }
  373. int shell_flash_read(const struct shell *shell,
  374. size_t argc, char **argv)
  375. {
  376. uint32_t offset, size=1;
  377. char *pend;
  378. char *buf;
  379. int ret;
  380. const struct device *f_dev;
  381. if(argc != 3){
  382. shell_print(shell,"fread dev_name(sd/spi_flash/spinand) offset\n");
  383. return -1;
  384. }
  385. f_dev = device_get_binding(argv[1]);
  386. if (!f_dev) {
  387. shell_print(shell,"flash %s binding failed!\n", argv[1]);
  388. return EINVAL;
  389. }
  390. if(0 == strcmp(argv[1], "spi_flash")) // nor is size else is sector
  391. size = 512;
  392. offset = strtoul(argv[2], &pend, 0);
  393. buf = k_malloc(READ_BLOCK_ONCE);
  394. if(buf == NULL){
  395. shell_print(shell, "malloc fail\n");
  396. return -1;
  397. }
  398. shell_print(shell,"fread 512b: offset=0x%x, buf=0x%x\n", offset, (uint32_t)buf);
  399. ret = flash_read(f_dev, offset, buf, size);
  400. if(ret < 0 ) {
  401. shell_print(shell, "flash read fail\n");
  402. }else{
  403. print_buf(shell, buf, 512);
  404. }
  405. k_free(buf);
  406. return 0;
  407. }
  408. #endif
  409. #if defined(CONFIG_CMD_SPINAND)
  410. #include <drivers/flash.h>
  411. #include <drivers/spinand.h>
  412. #include <drivers/disk.h>
  413. #define SPINAND_READ_BLOCK_ONCE 2048
  414. static int shell_nand_read(const struct shell *shell,
  415. size_t argc, char **argv)
  416. {
  417. uint32_t offset, size;
  418. char *pend;
  419. char *buf;
  420. int ret;
  421. const struct device *nand_dev = device_get_binding("spinand");
  422. if (!nand_dev) {
  423. shell_print(shell,"nand dev binding failed!\n");
  424. return EINVAL;
  425. }
  426. buf = malloc(SPINAND_READ_BLOCK_ONCE);
  427. if(buf == NULL){
  428. shell_print(shell, "malloc fail\n");
  429. return -1;
  430. }
  431. if(argc == 3){
  432. offset = strtoul(argv[1], &pend, 0);
  433. size = strtoul(argv[2], &pend, 0);
  434. }else{
  435. shell_print(shell, "offset or size param setting wrong, please check!\n");
  436. return -1;
  437. }
  438. shell_print(shell,"nand read %d: offset=0x%x, buf=0x%x\n", size, offset, (uint32_t)buf);
  439. ret = flash_read(nand_dev, offset, buf, size);
  440. if(ret < 0 ) {
  441. shell_print(shell, "flash read fail\n");
  442. }else{
  443. print_buf(shell, buf, size);
  444. }
  445. free(buf);
  446. return 0;
  447. }
  448. static char wbuf[50] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, \
  449. 0xaa, 0xbb, 0xcc, 0xdd, 0xff, 0x23, 0x37, 0x49, 0x53, \
  450. 0x68, 0x73, 0x81, 0x95, 0xa3, 0xbd, 0xc8, 0xd7, 0x55, 0xaa};
  451. static int shell_nand_write(const struct shell *shell,
  452. size_t argc, char **argv)
  453. {
  454. uint32_t offset, size;
  455. char *pend;
  456. int ret;
  457. const struct device *nand_dev = device_get_binding("spinand");
  458. if (!nand_dev) {
  459. shell_print(shell,"nand dev binding failed!\n");
  460. return EINVAL;
  461. }
  462. if(argc == 3){
  463. offset = strtoul(argv[1], &pend, 0);
  464. size = strtoul(argv[2], &pend, 0);
  465. }else{
  466. shell_print(shell, "offset or size param setting wrong, please check!\n");
  467. return -1;
  468. }
  469. shell_print(shell,"nand write %d: offset=0x%x \n", size, offset);
  470. shell_print(shell, "flash write\n");
  471. ret = flash_write(nand_dev, offset, wbuf, size);
  472. shell_print(shell, "flash write finish\n");
  473. if(ret < 0 ) {
  474. shell_print(shell, "flash read fail\n");
  475. }else{
  476. shell_print(shell, "flash write offset=%d; len=%d succeed!\n", offset, size);
  477. }
  478. return 0;
  479. }
  480. extern void spinand_change_print_level(const struct device *dev, u8_t level);
  481. static int shell_nand_print_level(const struct shell *shell,
  482. size_t argc, char **argv)
  483. {
  484. int level = 0;
  485. char *pend;
  486. const struct device *nand_dev = device_get_binding("spinand");
  487. if (!nand_dev) {
  488. shell_print(shell,"nand dev binding failed!\n");
  489. return EINVAL;
  490. }
  491. if (argc == 2){
  492. level = strtoul(argv[1], &pend, 0);
  493. } else {
  494. shell_print(shell, "level param setting wrong, please check!\n");
  495. return -1;
  496. }
  497. if (level == 0 || level > 4) {
  498. shell_print(shell, "level param should be in 1--4, please check!\n");
  499. return -1;
  500. }
  501. spinand_change_print_level(nand_dev, level);
  502. return 0;
  503. }
  504. #if defined(CONFIG_SPINAND_TEST_FRAMEWORKS)
  505. static int shell_nand_ioctrl(const struct shell *shell,
  506. size_t argc, char **argv)
  507. {
  508. int ret;
  509. uint8_t hw_detect;
  510. uint32_t sector_cnt;
  511. uint32_t sector_size;
  512. uint32_t blk_erase_size;
  513. const struct device *nand_dev = device_get_binding("spinand");
  514. if (!nand_dev) {
  515. shell_print(shell,"nand dev binding failed!\n");
  516. return EINVAL;
  517. }
  518. ret = spinand_storage_ioctl((struct device *)nand_dev, DISK_IOCTL_GET_SECTOR_SIZE, (void *)&sector_size);
  519. if (ret != 0) {
  520. shell_print(shell, "spinand ioctrl DISK_IOCTL_GET_SECTOR_SIZE failed!\n");
  521. } else {
  522. shell_print(shell, "spinand ioctrl DISK_IOCTL_GET_SECTOR_SIZE get val = %d!\n", sector_size);
  523. }
  524. ret = spinand_storage_ioctl((struct device *)nand_dev, DISK_IOCTL_GET_SECTOR_COUNT, (void *)&sector_cnt);
  525. if (ret != 0) {
  526. shell_print(shell, "spinand ioctrl DISK_IOCTL_GET_SECTOR_COUNT failed!\n");
  527. } else {
  528. shell_print(shell, "spinand ioctrl DISK_IOCTL_GET_SECTOR_COUNT get val = %d!\n", sector_cnt);
  529. }
  530. ret = spinand_storage_ioctl((struct device *)nand_dev, DISK_IOCTL_GET_ERASE_BLOCK_SZ, (void *)&blk_erase_size);
  531. if (ret != 0) {
  532. shell_print(shell, "spinand ioctrl DISK_IOCTL_GET_ERASE_BLOCK_SZ failed!\n");
  533. } else {
  534. shell_print(shell, "spinand ioctrl DISK_IOCTL_GET_ERASE_BLOCK_SZ get val = %d!\n", blk_erase_size);
  535. }
  536. ret = spinand_storage_ioctl((struct device *)nand_dev, DISK_IOCTL_HW_DETECT, (void *)&hw_detect);
  537. if (ret != 0) {
  538. shell_print(shell, "spinand ioctrl DISK_IOCTL_HW_DETECT failed!\n");
  539. } else {
  540. shell_print(shell, "spinand ioctrl DISK_IOCTL_HW_DETECT get val = %d!\n", hw_detect);
  541. if (hw_detect == 2) {
  542. shell_print(shell, "spinand disk unormal, no disk!\n");
  543. } else if (hw_detect == 8) {
  544. shell_print(shell, "spinand disk normal.\n");
  545. }
  546. }
  547. ret = spinand_storage_ioctl((struct device *)nand_dev, DISK_IOCTL_CTRL_SYNC, NULL);
  548. if (ret != 0) {
  549. shell_print(shell, "spinand ioctrl DISK_IOCTL_CTRL_SYNC failed!\n");
  550. } else {
  551. shell_print(shell, "spinand ioctrl DISK_IOCTL_CTRL_SYNC success!\n");
  552. }
  553. return 0;
  554. }
  555. extern int spinand_scan_delaychain(const struct device *dev);
  556. extern int spinand_manual_flush(const struct device *dev);
  557. #if defined(CONFIG_SPINAND_TEST_FRAMEWORKS_ADDITION)
  558. extern int spinand_print_hardware_params(const struct device *dev);
  559. extern int spinand_print_software_params(const struct device *dev);
  560. extern int spinand_phy_page_write_test(const struct device *dev, u16_t blk, u16_t page, u8_t clk);
  561. extern int spinand_phy_page_read_test(const struct device *dev, u16_t blk, u16_t page, u8_t clk);
  562. extern int spinand_phy_blk_erase_test(const struct device *dev, u8_t blk);
  563. extern int spinand_read_single_page_test(const struct device *dev);
  564. extern int spinand_write_single_page_test(const struct device *dev);
  565. extern int spinand_ldl_page_readback_test(const struct device *dev);
  566. extern int spinand_zonetbl_rotation(const struct device *dev);
  567. extern int spinand_rewrite_zonetbl_test(const struct device *dev);
  568. extern int spinand_erase_zonetbl_blk(const struct device *dev);
  569. extern int spinand_api_boundary_test(const struct device *dev);
  570. extern int spinand_read_speed_test(const struct device *dev, u8_t clk);
  571. extern int spinand_write_speed_test(const struct device *dev, u8_t clk);
  572. extern int spinand_pdlinit_time_cost(const struct device *dev);
  573. extern int spinand_zonetbl_init_time_cost(const struct device *dev);
  574. extern int spinand_read_write_udisk(const struct device *dev);
  575. extern int spinand_multi_zonetbl_test(const struct device *dev);
  576. #endif
  577. static int shell_nand_delaychain_scan(const struct shell *shell,
  578. size_t argc, char **argv)
  579. {
  580. int ret;
  581. const struct device *nand_dev = device_get_binding("spinand");
  582. if (!nand_dev) {
  583. shell_print(shell,"nand dev binding failed!\n");
  584. return EINVAL;
  585. }
  586. ret = spinand_scan_delaychain(nand_dev);
  587. if(ret < 0 ) {
  588. shell_print(shell, "nand scan delaychain error!\n");
  589. }else{
  590. shell_print(shell, "nand scan delaychain finished!\n");
  591. }
  592. return 0;
  593. }
  594. static int shell_nand_flush(const struct shell *shell,
  595. size_t argc, char **argv)
  596. {
  597. const struct device *nand_dev = device_get_binding("spinand");
  598. if (!nand_dev) {
  599. shell_print(shell,"nand dev binding failed!\n");
  600. return EINVAL;
  601. }
  602. spinand_manual_flush(nand_dev);
  603. return 0;
  604. }
  605. #if defined(CONFIG_SPINAND_TEST_FRAMEWORKS_ADDITION)
  606. static int shell_nand_hardware_params(const struct shell *shell,
  607. size_t argc, char **argv)
  608. {
  609. const struct device *nand_dev = device_get_binding("spinand");
  610. if (!nand_dev) {
  611. shell_print(shell,"nand dev binding failed!\n");
  612. return EINVAL;
  613. }
  614. spinand_print_hardware_params(nand_dev);
  615. return 0;
  616. }
  617. static int shell_nand_software_params(const struct shell *shell,
  618. size_t argc, char **argv)
  619. {
  620. int ret;
  621. const struct device *nand_dev = device_get_binding("spinand");
  622. if (!nand_dev) {
  623. shell_print(shell,"nand dev binding failed!\n");
  624. return EINVAL;
  625. }
  626. ret = spinand_print_software_params(nand_dev);
  627. if(ret < 0 ) {
  628. shell_print(shell, "nand get software parms error!\n");
  629. }
  630. return 0;
  631. }
  632. static int shell_nand_page_write_test(const struct shell *shell,
  633. size_t argc, char **argv)
  634. {
  635. int ret;
  636. int clk = 96;
  637. int blk = 2;
  638. int page = 0;
  639. char *pend;
  640. const struct device *nand_dev = device_get_binding("spinand");
  641. if (!nand_dev) {
  642. shell_print(shell,"nand dev binding failed!\n");
  643. return EINVAL;
  644. }
  645. if (argc == 2){
  646. clk = strtoul(argv[1], &pend, 0);
  647. }
  648. if(argc == 3){
  649. clk = strtoul(argv[1], &pend, 0);
  650. blk = strtoul(argv[2], &pend, 0);
  651. }
  652. if(argc == 4){
  653. clk = strtoul(argv[1], &pend, 0);
  654. blk = strtoul(argv[2], &pend, 0);
  655. page = strtoul(argv[3], &pend, 0);
  656. }
  657. ret = spinand_phy_page_write_test(nand_dev, blk, page, clk);
  658. if(ret != 0 ) {
  659. shell_print(shell, "spinand page write test error!\n");
  660. }
  661. return 0;
  662. }
  663. static int shell_nand_page_read_test(const struct shell *shell,
  664. size_t argc, char **argv)
  665. {
  666. int ret;
  667. int clk = 96;
  668. int blk = 2;
  669. int page = 0;
  670. char *pend;
  671. const struct device *nand_dev = device_get_binding("spinand");
  672. if (!nand_dev) {
  673. shell_print(shell,"nand dev binding failed!\n");
  674. return EINVAL;
  675. }
  676. if (argc == 2){
  677. clk = strtoul(argv[1], &pend, 0);
  678. }
  679. if(argc == 3){
  680. clk = strtoul(argv[1], &pend, 0);
  681. blk = strtoul(argv[2], &pend, 0);
  682. }
  683. if(argc == 4){
  684. clk = strtoul(argv[1], &pend, 0);
  685. blk = strtoul(argv[2], &pend, 0);
  686. page = strtoul(argv[3], &pend, 0);
  687. }
  688. ret = spinand_phy_page_read_test(nand_dev, blk, page, clk);
  689. if(ret != 0 ) {
  690. shell_print(shell, "spinand page read test error!\n");
  691. }
  692. return 0;
  693. }
  694. static int shell_nand_blk_erase_test(const struct shell *shell,
  695. size_t argc, char **argv)
  696. {
  697. int ret;
  698. int blk;
  699. char *pend;
  700. const struct device *nand_dev = device_get_binding("spinand");
  701. if (!nand_dev) {
  702. shell_print(shell,"nand dev binding failed!\n");
  703. return EINVAL;
  704. }
  705. if(argc == 2){
  706. blk = strtoul(argv[1], &pend, 0);
  707. } else {
  708. blk = 2;
  709. }
  710. shell_print(shell, "phy blk erase blk%d. \n", blk);
  711. ret = spinand_phy_blk_erase_test(nand_dev, blk);
  712. if(ret != 0 ) {
  713. shell_print(shell, "spinand blk%d erase test error!\n", blk);
  714. }
  715. return 0;
  716. }
  717. static int shell_nand_api_boundary_test(const struct shell *shell,
  718. size_t argc, char **argv)
  719. {
  720. int ret;
  721. const struct device *nand_dev = device_get_binding("spinand");
  722. if (!nand_dev) {
  723. shell_print(shell,"nand dev binding failed!\n");
  724. return EINVAL;
  725. }
  726. ret = spinand_api_boundary_test(nand_dev);
  727. if(ret != 0 ) {
  728. shell_print(shell, "spinand api boundary test error!\n");
  729. }
  730. return 0;
  731. }
  732. static int shell_nand_read_sigle_page_test(const struct shell *shell,
  733. size_t argc, char **argv)
  734. {
  735. int ret;
  736. const struct device *nand_dev = device_get_binding("spinand");
  737. if (!nand_dev) {
  738. shell_print(shell,"nand dev binding failed!\n");
  739. return EINVAL;
  740. }
  741. ret = spinand_read_single_page_test(nand_dev);
  742. if(ret != 0 ) {
  743. shell_print(shell, "spinand read single page test error!\n");
  744. }
  745. return 0;
  746. }
  747. static int shell_nand_write_sigle_page_test(const struct shell *shell,
  748. size_t argc, char **argv)
  749. {
  750. int ret;
  751. const struct device *nand_dev = device_get_binding("spinand");
  752. if (!nand_dev) {
  753. shell_print(shell,"nand dev binding failed!\n");
  754. return EINVAL;
  755. }
  756. ret = spinand_write_single_page_test(nand_dev);
  757. if(ret != 0 ) {
  758. shell_print(shell, "spinand write single page test error!\n");
  759. }
  760. return 0;
  761. }
  762. static int shell_nand_page_readback_test(const struct shell *shell,
  763. size_t argc, char **argv)
  764. {
  765. int ret;
  766. const struct device *nand_dev = device_get_binding("spinand");
  767. if (!nand_dev) {
  768. shell_print(shell,"nand dev binding failed!\n");
  769. return EINVAL;
  770. }
  771. ret = spinand_ldl_page_readback_test(nand_dev);
  772. if(ret != 0 ) {
  773. shell_print(shell, "spinand logic page readback test error!\n");
  774. }
  775. return 0;
  776. }
  777. static int shell_nand_zonetbl_rotation_test(const struct shell *shell,
  778. size_t argc, char **argv)
  779. {
  780. int ret;
  781. const struct device *nand_dev = device_get_binding("spinand");
  782. if (!nand_dev) {
  783. shell_print(shell,"nand dev binding failed!\n");
  784. return EINVAL;
  785. }
  786. ret = spinand_zonetbl_rotation(nand_dev);
  787. if(ret != 0 ) {
  788. shell_print(shell, "spinand zonetbl rotation test error!\n");
  789. }
  790. return 0;
  791. }
  792. static int shell_nand_rewrite_zonetbl_test(const struct shell *shell,
  793. size_t argc, char **argv)
  794. {
  795. int ret;
  796. const struct device *nand_dev = device_get_binding("spinand");
  797. if (!nand_dev) {
  798. shell_print(shell,"nand dev binding failed!\n");
  799. return EINVAL;
  800. }
  801. ret = spinand_rewrite_zonetbl_test(nand_dev);
  802. if(ret != 0 ) {
  803. shell_print(shell, "spinand zonetbl rotation test error!\n");
  804. }
  805. return 0;
  806. }
  807. static int shell_nand_erase_zonetbl_blk_test(const struct shell *shell,
  808. size_t argc, char **argv)
  809. {
  810. int ret;
  811. const struct device *nand_dev = device_get_binding("spinand");
  812. if (!nand_dev) {
  813. shell_print(shell,"nand dev binding failed!\n");
  814. return EINVAL;
  815. }
  816. ret = spinand_erase_zonetbl_blk(nand_dev);
  817. if(ret != 0 ) {
  818. shell_print(shell, "spinand zonetbl rotation test error!\n");
  819. }
  820. return 0;
  821. }
  822. static int shell_nand_read_speed_test(const struct shell *shell,
  823. size_t argc, char **argv)
  824. {
  825. int ret;
  826. int clk;
  827. char *pend;
  828. const struct device *nand_dev = device_get_binding("spinand");
  829. if (!nand_dev) {
  830. shell_print(shell,"nand dev binding failed!\n");
  831. return EINVAL;
  832. }
  833. if (argc == 2){
  834. clk = strtoul(argv[1], &pend, 0);
  835. } else {
  836. clk = 96;
  837. }
  838. ret = spinand_read_speed_test(nand_dev, clk);
  839. if(ret != 0 ) {
  840. shell_print(shell, "spinand read speed test error!\n");
  841. }
  842. return 0;
  843. }
  844. static int shell_nand_write_speed_test(const struct shell *shell,
  845. size_t argc, char **argv)
  846. {
  847. int ret;
  848. int clk;
  849. char *pend;
  850. const struct device *nand_dev = device_get_binding("spinand");
  851. if (!nand_dev) {
  852. shell_print(shell,"nand dev binding failed!\n");
  853. return EINVAL;
  854. }
  855. if (argc == 2){
  856. clk = strtoul(argv[1], &pend, 0);
  857. } else {
  858. clk = 96;
  859. }
  860. ret = spinand_write_speed_test(nand_dev, clk);
  861. if(ret != 0 ) {
  862. shell_print(shell, "spinand write speed test error!\n");
  863. }
  864. return 0;
  865. }
  866. static int shell_nand_pdlinit_time_cost_test(const struct shell *shell,
  867. size_t argc, char **argv)
  868. {
  869. int ret;
  870. const struct device *nand_dev = device_get_binding("spinand");
  871. if (!nand_dev) {
  872. shell_print(shell,"nand dev binding failed!\n");
  873. return EINVAL;
  874. }
  875. ret = spinand_pdlinit_time_cost(nand_dev);
  876. if(ret != 0 ) {
  877. shell_print(shell, "spinand pdl init time cost test error!\n");
  878. }
  879. return 0;
  880. }
  881. static int shell_nand_zonetbl_init_time_cost_test(const struct shell *shell,
  882. size_t argc, char **argv)
  883. {
  884. int ret;
  885. const struct device *nand_dev = device_get_binding("spinand");
  886. if (!nand_dev) {
  887. shell_print(shell,"nand dev binding failed!\n");
  888. return EINVAL;
  889. }
  890. ret = spinand_zonetbl_init_time_cost(nand_dev);
  891. if(ret != 0 ) {
  892. shell_print(shell, "spinand zonetbl init time cost test error!\n");
  893. }
  894. return 0;
  895. }
  896. static int shell_nand_read_write_udisk(const struct shell *shell,
  897. size_t argc, char **argv)
  898. {
  899. int ret;
  900. const struct device *nand_dev = device_get_binding("spinand");
  901. if (!nand_dev) {
  902. shell_print(shell,"nand dev binding failed!\n");
  903. return EINVAL;
  904. }
  905. ret = spinand_read_write_udisk(nand_dev);
  906. if(ret != 0 ) {
  907. shell_print(shell, "spinand zonetbl init time cost test error!\n");
  908. }
  909. return 0;
  910. }
  911. #endif
  912. #endif
  913. #endif
  914. #if defined(CONFIG_DMA_DBG_DUMP)
  915. extern void dma_dump_info(void);
  916. static int shell_dma_info(const struct shell *shell,
  917. size_t argc, char **argv)
  918. {
  919. dma_dump_info();
  920. return 0;
  921. }
  922. #endif
  923. #if defined(CONFIG_KERNEL_SHOW_STACK)
  924. extern void show_stack(void);
  925. static int shell_show_stack(const struct shell *shell,
  926. size_t argc, char **argv)
  927. {
  928. show_stack();
  929. return 0;
  930. }
  931. #endif
  932. #if defined(CONFIG_SD_FS)
  933. static int shell_sdfs_dump(const struct shell *shell,
  934. size_t argc, char **argv)
  935. {
  936. struct sd_file *sf;
  937. uint32_t size, fsize, i;
  938. char *pend;
  939. char buf[32];
  940. if (argc != 3)
  941. return -EINVAL;
  942. sf = sd_fopen(argv[1]);
  943. if(sf == NULL){
  944. shell_print(shell, "sdfs open %s fail\n", argv[1]);
  945. return -EINVAL;
  946. }
  947. fsize= sd_fsize(argv[1]);
  948. size = strtoul(argv[2], &pend, 0);
  949. if(size > fsize)
  950. size = fsize;
  951. shell_print(shell, "dump %s, size=0x%x, all=0x%x:\n", argv[1], size, fsize);
  952. for(i = 0; i < size; i+=32){
  953. sd_fread(sf, buf, 32);
  954. print_buf(shell, buf, 32);
  955. }
  956. sd_fclose(sf);
  957. return 0;
  958. }
  959. #endif
  960. #ifdef CONFIG_DISPLAY_ENGINE
  961. extern void de_dump(void);
  962. static int shell_de_dump(const struct shell *shell,
  963. size_t argc, char **argv)
  964. {
  965. de_dump();
  966. return 0;
  967. }
  968. #endif /* CONFIG_DISPLAY_ENGINE */
  969. #if defined(CONFIG_DISPLAY_LCDC)
  970. extern void lcdc_dump(void);
  971. static int shell_lcd_dump(const struct shell *shell,
  972. size_t argc, char **argv)
  973. {
  974. lcdc_dump();
  975. #ifdef CONFIG_DISPLAY_ENGINE
  976. de_dump();
  977. #endif
  978. return 0;
  979. }
  980. #endif /* CONFIG_DISPLAY_LCDC */
  981. #if defined(CONFIG_NVRAM_CONFIG)
  982. #include <drivers/nvram_config.h>
  983. static int shell_nvram_dump(const struct shell *shell,
  984. size_t argc, char **argv)
  985. {
  986. nvram_config_dump(shell);
  987. return 0;
  988. }
  989. static int shell_nvram_cmd(const struct shell *shell,
  990. size_t argc, char **argv)
  991. {
  992. char rdata[64];
  993. int ret;
  994. if(argc == 2){
  995. memset(rdata, 0 ,64);
  996. ret = nvram_config_get(argv[1], rdata, 63);
  997. if(ret < 0 ) {
  998. shell_print(shell, "nvram get: %s fail\n", argv[1]);
  999. }else{
  1000. shell_print(shell, "nvram get(len=%d): %s\n", ret, argv[1]);
  1001. print_buffer(shell, rdata, 1, ret, 16, 0);
  1002. }
  1003. }else if (argc == 3){
  1004. ret = nvram_config_set(argv[1], argv[2], strlen(argv[2]));
  1005. if(ret < 0 ){
  1006. shell_print(shell, "nvram set: %s=%s fail\n", argv[1], argv[2]);
  1007. }else{
  1008. shell_print(shell, "nvram set: %s=%s ok\n", argv[1], argv[2]);
  1009. }
  1010. }else{
  1011. return -1;
  1012. }
  1013. return 0;
  1014. }
  1015. #endif
  1016. #if defined(CONFIG_BT_DRV)
  1017. int bt_vs_write_bb_reg(uint32_t addr, uint32_t val);
  1018. int bt_vs_read_bb_reg(uint32_t addr, uint8_t size);
  1019. int bt_vs_write_rf_reg(uint16_t addr, uint16_t val);
  1020. int bt_vs_read_rf_reg(uint16_t addr, uint8_t size);
  1021. static int shell_cmd_bqb_bb(const struct shell *shell,
  1022. size_t argc, char **argv)
  1023. {
  1024. uint32_t addr = strtoul(argv[2], NULL, 16);
  1025. uint32_t val = strtoul(argv[3], NULL, 16);
  1026. uint8_t size = strtoul(argv[3], NULL, 10);
  1027. if (!strcmp(argv[1], "read")) {
  1028. bt_vs_read_bb_reg(addr, size);
  1029. } else if (!strcmp(argv[1], "write")) {
  1030. bt_vs_write_bb_reg(addr, val);
  1031. } else {
  1032. return -EINVAL;
  1033. }
  1034. return 0;
  1035. }
  1036. static int shell_cmd_bqb_rf(const struct shell *shell,
  1037. size_t argc, char **argv)
  1038. {
  1039. uint16_t addr = strtoul(argv[2], NULL, 16);
  1040. uint16_t val = strtoul(argv[3], NULL, 16);
  1041. uint8_t size = strtoul(argv[3], NULL, 10);
  1042. if (!strcmp(argv[1], "read")) {
  1043. bt_vs_read_rf_reg(addr, size);
  1044. } else if (!strcmp(argv[1], "write")) {
  1045. bt_vs_write_rf_reg(addr, val);
  1046. } else {
  1047. return -EINVAL;
  1048. }
  1049. return 0;
  1050. }
  1051. #endif
  1052. #if defined(CONFIG_PM_LOG_LEVEL_INF)
  1053. #include <pm/pm.h>
  1054. static int shell_cmd_sleep(const struct shell *shell,
  1055. size_t argc, char **argv)
  1056. {
  1057. static struct pm_state_info pm_stat;
  1058. if(argc != 2)
  1059. return 0;
  1060. if( !strcmp(argv[1], "s3")) {
  1061. shell_print(shell, "enter deep sleep\n");
  1062. pm_stat.state = PM_STATE_SUSPEND_TO_RAM;
  1063. //pm_power_state_force(pm_stat);
  1064. sys_pm_enter_deep_sleep();
  1065. shell_print(shell, "exit deep sleep\n");
  1066. }else if( !strcmp(argv[1], "s2")) {
  1067. shell_print(shell, "enter sleep\n");
  1068. pm_stat.state = PM_STATE_STANDBY;
  1069. pm_power_state_force(pm_stat);
  1070. shell_print(shell, "exit sleep\n");
  1071. }else{
  1072. uint8_t mode = strtoul(argv[1], NULL, 10);
  1073. soc_set_sleep_mode(mode);
  1074. }
  1075. return 0;
  1076. }
  1077. #endif
  1078. static int shell_cmd_reboot(const struct shell *shell,
  1079. size_t argc, char **argv)
  1080. {
  1081. if(argc == 2) {
  1082. if(!strcmp(argv[1], "adfu")){
  1083. shell_print(shell, "reboot adfu\n");
  1084. sys_pm_reboot(REBOOT_TYPE_GOTO_ADFU);
  1085. }else if(!strcmp(argv[1], "poweroff")){
  1086. shell_print(shell, "poweroff\n");
  1087. sys_pm_poweroff();
  1088. }else{
  1089. #if defined(CONFIG_SOC_LARK)
  1090. if(!strcmp(argv[1], "jtag")){
  1091. shell_print(shell, "reboot jtag\n");
  1092. sys_pm_reboot(REBOOT_TYPE_GOTO_SWJTAG);
  1093. }
  1094. #endif
  1095. }
  1096. }
  1097. k_msleep(200);
  1098. shell_print(shell, "reboot\n");
  1099. sys_pm_reboot(REBOOT_TYPE_NORMAL);
  1100. return 0;
  1101. }
  1102. extern void libc_heap_dump(void);
  1103. static int shell_cmd_khead_dump(const struct shell *shell,
  1104. size_t argc, char **argv)
  1105. {
  1106. struct k_heap * k_h;
  1107. if(argc == 2){
  1108. k_h = (struct k_heap *) strtoul(argv[1], NULL, 16);
  1109. STRUCT_SECTION_FOREACH(k_heap, h) {
  1110. if(h == k_h){
  1111. shell_print(shell, "dump heap=%p:\n", h);
  1112. sys_heap_dump(&h->heap);
  1113. }else{
  1114. shell_print(shell, "heap=%p != %p\n", h, k_h);
  1115. }
  1116. }
  1117. }else{
  1118. shell_print(shell, "----dump libc heap:---\n");
  1119. libc_heap_dump();
  1120. STRUCT_SECTION_FOREACH(k_heap, h) {
  1121. shell_print(shell, "----dump heap=%p:---\n", h);
  1122. sys_heap_dump(&h->heap);
  1123. }
  1124. }
  1125. return 0;
  1126. }
  1127. #if defined(CONFIG_TOOL)
  1128. int shell_data_discard(void)
  1129. {
  1130. int count = 0;
  1131. #if defined(CONFIG_SHELL_BACKEND_SERIAL)
  1132. uint32_t bytes, temp;
  1133. const struct shell *shell;
  1134. extern const struct shell *shell_backend_uart_get_ptr(void);
  1135. shell = shell_backend_uart_get_ptr();
  1136. while (1)
  1137. {
  1138. (void)shell->iface->api->read(shell->iface, &temp, sizeof(temp), &bytes);
  1139. if (bytes < sizeof(temp))
  1140. {
  1141. break;
  1142. }
  1143. count += bytes;
  1144. }
  1145. #endif
  1146. return count;
  1147. }
  1148. #if 0
  1149. int tool_init(char *type, unsigned int dev_type);
  1150. static int shell_cmd_tool_connect(const struct shell *shell,
  1151. size_t argc, char **argv)
  1152. {
  1153. char *tool_type;
  1154. if(argc >= 2)
  1155. {
  1156. tool_type = argv[1];
  1157. }
  1158. else
  1159. {
  1160. tool_type = "aset";
  1161. }
  1162. shell_print(shell, "%s\n", tool_type);
  1163. shell_data_discard();
  1164. (void)shell->iface->api->uninit(shell->iface);
  1165. tool_init(tool_type, 3);
  1166. return 0;
  1167. }
  1168. #endif
  1169. int shell_data_write(const uint8_t *data, uint32_t size, uint32_t timeout_ms)
  1170. {
  1171. int count = 0;
  1172. #if defined(CONFIG_SHELL_BACKEND_SERIAL)
  1173. const struct shell *shell;
  1174. extern const struct shell *shell_backend_uart_get_ptr(void);
  1175. shell = shell_backend_uart_get_ptr();
  1176. (void)shell->iface->api->write(shell->iface, data, size, &count);
  1177. #endif
  1178. return count;
  1179. }
  1180. void shell_dbg_disable(void)
  1181. {
  1182. #if defined(CONFIG_SHELL_BACKEND_SERIAL)
  1183. const struct shell *shell;
  1184. extern const struct shell *shell_backend_uart_get_ptr(void);
  1185. shell = shell_backend_uart_get_ptr();
  1186. shell_data_discard();
  1187. (void)shell->iface->api->uninit(shell->iface);
  1188. #endif
  1189. }
  1190. void shell_dbg_restore(void)
  1191. {
  1192. #if defined(CONFIG_SHELL_BACKEND_SERIAL)
  1193. #include <shell/shell_uart.h>
  1194. const struct shell *shell;
  1195. const struct shell_uart *sh_uart;
  1196. extern const struct shell *shell_backend_uart_get_ptr(void);
  1197. shell = shell_backend_uart_get_ptr();
  1198. sh_uart = (const struct shell_uart *)shell->iface->ctx;
  1199. (void)shell->iface->api->init(shell->iface, sh_uart->ctrl_blk->dev,
  1200. sh_uart->ctrl_blk->handler, sh_uart->ctrl_blk->context);
  1201. #endif
  1202. }
  1203. #endif
  1204. #if defined(CONFIG_UI_MEMORY_MANAGER)
  1205. #include <ui_mem.h>
  1206. static int shell_cmd_dump_uimem(const struct shell *shell,
  1207. size_t argc, char **argv)
  1208. {
  1209. uint8_t type;
  1210. if (argc > 1) {
  1211. type = (uint8_t)atoi(argv[1]);
  1212. ui_mem_dump(type);
  1213. } else {
  1214. ui_mem_dump_all();
  1215. }
  1216. return 0;
  1217. }
  1218. #endif
  1219. #if defined(CONFIG_UI_SERVICE)
  1220. #include <view_stack.h>
  1221. #include <msgbox_cache.h>
  1222. static int shell_cmd_dump_uiview(const struct shell *shell,
  1223. size_t argc, char **argv)
  1224. {
  1225. view_manager_dump();
  1226. view_stack_dump();
  1227. view_cache_dump();
  1228. msgbox_cache_dump();
  1229. return 0;
  1230. }
  1231. #endif
  1232. #if defined(CONFIG_THREAD_RUNTIME_STATS)
  1233. /*
  1234. * cmd: cpuload
  1235. * start
  1236. * stop
  1237. */
  1238. void cpuload_stat_start(int interval_ms);
  1239. void cpuload_stat_stop(void);
  1240. static int shell_cmd_cpuload(const struct shell *shell,
  1241. size_t argc, char **argv)
  1242. {
  1243. int interval_ms;
  1244. int len = strlen(argv[1]);
  1245. if (!strncmp(argv[1], "start", len)) {
  1246. if (argc > 2)
  1247. interval_ms = strtoul(argv[2], NULL, 0);
  1248. else
  1249. interval_ms = 2000; /* default interval: 2s */
  1250. shell_print(shell,"Start cpu load statistic, interval %d ms\n",
  1251. interval_ms);
  1252. cpuload_stat_start(interval_ms);
  1253. } else if (!strncmp(argv[1], "stop", len)) {
  1254. shell_print(shell,"Stop cpu load statistic\n");
  1255. cpuload_stat_stop();
  1256. } else {
  1257. shell_print(shell,"usage:\n");
  1258. shell_print(shell," cpuload start\n");
  1259. shell_print(shell," cpuload stop\n");
  1260. return -EINVAL;
  1261. }
  1262. return 0;
  1263. }
  1264. #endif /* CONFIG_CPU_LOAD_STAT */
  1265. #if defined(CONFIG_FAT_FILESYSTEM_ELM)
  1266. static int shell_cmd_dumpbuf(const struct shell *shell,
  1267. size_t argc, char **argv)
  1268. {
  1269. struct fs_file_t zfp;
  1270. uint32_t addr, len;
  1271. int res;
  1272. if (argc < 4) {
  1273. shell_print(shell, "usage:\n");
  1274. shell_print(shell, " dumpbuf addr len path\n");
  1275. return -EINVAL;
  1276. }
  1277. fs_file_t_init(&zfp);
  1278. res = fs_open(&zfp, argv[3], FS_O_WRITE | FS_O_CREATE);
  1279. if (res < 0) {
  1280. shell_print(shell,"fail to open %s\n", argv[3]);
  1281. return res;
  1282. }
  1283. addr = strtoul(argv[1], NULL, 0);
  1284. len = strtoul(argv[2], NULL, 0);
  1285. fs_write(&zfp, (void *)addr, len);
  1286. fs_close(&zfp);
  1287. shell_print(shell,"done dumping to %s\n", argv[3]);
  1288. return 0;
  1289. }
  1290. #endif /* CONFIG_FAT_FILESYSTEM_ELM */
  1291. #if defined(CONFIG_MSG_MANAGER)
  1292. extern void msg_manager_dump_busy_msg(void);
  1293. static int shell_cmd_dumpmsg(const struct shell *shell,
  1294. size_t argc, char **argv)
  1295. {
  1296. msg_manager_dump_busy_msg();
  1297. return 0;
  1298. }
  1299. #endif /* defined(CONFIG_MSG_MANAGER) */
  1300. #if RBUF_POOL_DBG && defined(CONFIG_RBUF_LIB)
  1301. static int shell_cmd_dumprbuf(const struct shell *shell,
  1302. size_t argc, char **argv)
  1303. {
  1304. rbuf_pool_dump((rbuf_pool_t *)RB_ST_POOL);
  1305. return 0;
  1306. }
  1307. #endif
  1308. #if defined(CONFIG_UI_INPUT_RECORDER)
  1309. #include <input_recorder.h>
  1310. #if defined(CONFIG_FILE_STREAM)
  1311. #include <file_stream.h>
  1312. #define INPUTREC_BUFFER_SIZE 0
  1313. #ifdef CONFIG_MASS_STORAGE_DISK_NAME
  1314. #define INPUTREC_DEFAULT_FILE_PATH "/" CONFIG_MASS_STORAGE_DISK_NAME ":/.input.rec"
  1315. #else
  1316. #define INPUTREC_DEFAULT_FILE_PATH "/SD:/.input.rec"
  1317. #endif
  1318. static int shell_cmd_input_record(const struct shell *shell,
  1319. size_t argc, char **argv)
  1320. {
  1321. #if INPUTREC_BUFFER_SIZE > 0
  1322. static uint8_t rec_buffer[INPUTREC_BUFFER_SIZE];
  1323. static uint32_t rec_size;
  1324. #else
  1325. static io_stream_t rec_stream;
  1326. #endif
  1327. bool to_capture;
  1328. bool to_start;
  1329. bool repeat = false;
  1330. int res = 0;
  1331. if (argc < 3) {
  1332. shell_print(shell, "usage:\n");
  1333. shell_print(shell, " inputrec {record|play} {repeat|start|stop} [file]\n");
  1334. return -EINVAL;
  1335. }
  1336. if (strcmp(argv[1], "record") == 0) {
  1337. to_capture = true;
  1338. } else if (strcmp(argv[1], "play") == 0) {
  1339. to_capture = false;
  1340. } else {
  1341. return -EINVAL;
  1342. }
  1343. if (strcmp(argv[2], "start") == 0) {
  1344. to_start = true;
  1345. } else if (strcmp(argv[2], "stop") == 0) {
  1346. to_start = false;
  1347. } else if (!to_capture && strcmp(argv[2], "repeat") == 0) {
  1348. to_start = true;
  1349. repeat = true;
  1350. } else {
  1351. return -EINVAL;
  1352. }
  1353. #if INPUTREC_BUFFER_SIZE > 0
  1354. if (to_capture) {
  1355. if (to_start) {
  1356. res = input_capture_buffer_start(rec_buffer, sizeof(rec_buffer));
  1357. } else {
  1358. int num = input_capture_stop();
  1359. if (num >= 0) {
  1360. rec_size = num * sizeof(input_rec_data_t);
  1361. shell_print(shell, "save %d records\n", num);
  1362. }
  1363. }
  1364. } else {
  1365. if (to_start) {
  1366. res = input_playback_buffer_start(rec_buffer, rec_size, repeat);
  1367. //input_playback_slide_fixstep_start(10, 300, 10, true);
  1368. } else {
  1369. input_playback_stop();
  1370. }
  1371. }
  1372. #else /* INPUTREC_BUFFER_SIZE > 0 */
  1373. if (to_start) {
  1374. const char *path = (argc > 3) ? argv[3] : INPUTREC_DEFAULT_FILE_PATH;
  1375. if (rec_stream) {
  1376. shell_print(shell, "must stop last record/play first\n");
  1377. return -EPERM;
  1378. }
  1379. rec_stream = file_stream_create(path);
  1380. if (rec_stream) {
  1381. if (stream_open(rec_stream, to_capture ? MODE_OUT : MODE_IN)) {
  1382. stream_destroy(rec_stream);
  1383. rec_stream = NULL;
  1384. }
  1385. }
  1386. if (rec_stream == NULL) {
  1387. shell_print(shell, "failed to open file %s\n", path);
  1388. return -EPERM;
  1389. }
  1390. } else if (rec_stream == NULL) {
  1391. return 0;
  1392. }
  1393. if (to_capture) {
  1394. if (to_start) {
  1395. res = input_capture_stream_start(rec_stream);
  1396. } else {
  1397. shell_print(shell, "save %d records\n", input_capture_stop());
  1398. }
  1399. } else {
  1400. if (to_start) {
  1401. res = input_playback_stream_start(rec_stream, repeat);
  1402. //input_playback_slide_fixstep_start(10, 300, 10, true);
  1403. } else {
  1404. input_playback_stop();
  1405. }
  1406. }
  1407. if (!to_start || res) {
  1408. if (rec_stream) {
  1409. stream_close(rec_stream);
  1410. stream_destroy(rec_stream);
  1411. rec_stream = NULL;
  1412. }
  1413. }
  1414. #endif /* INPUTREC_BUFFER_SIZE > 0 */
  1415. return res;
  1416. }
  1417. #endif /* defined(CONFIG_STREAM) */
  1418. static int shell_cmd_input_autoscrl(const struct shell *shell,
  1419. size_t argc, char **argv)
  1420. {
  1421. bool to_start = true;
  1422. bool is_vert = true;
  1423. int16_t start, stop, step;
  1424. int res = -EINVAL;
  1425. if (argc < 2) {
  1426. goto exit;
  1427. }
  1428. if (strcmp(argv[1], "stop") == 0) {
  1429. to_start = false;
  1430. } else {
  1431. if (argc < 5) {
  1432. goto exit;
  1433. }
  1434. if (strcmp(argv[1], "hstart") == 0) {
  1435. is_vert = false;
  1436. } else if (strcmp(argv[1], "vstart") == 0) {
  1437. is_vert = true;
  1438. } else {
  1439. goto exit;
  1440. }
  1441. }
  1442. start = (int16_t)atoi(argv[2]);
  1443. stop = (int16_t)atoi(argv[3]);
  1444. step = (int16_t)atoi(argv[4]);
  1445. if (to_start) {
  1446. input_playback_slide_fixstep_start(start, stop, step, is_vert);
  1447. } else {
  1448. input_playback_stop();
  1449. }
  1450. res = 0;
  1451. exit:
  1452. if (res) {
  1453. shell_print(shell, "usage:\n");
  1454. shell_print(shell, " inputscrl {hstart|vstart|stop} [{start_coord} {end_coord} {step}]\n");
  1455. }
  1456. return 0;
  1457. }
  1458. #endif /* defined(CONFIG_UI_INPUT_RECORDER) */
  1459. #if defined(CONFIG_INPUT_DEV_ACTS_CST816S_TP_KEY)
  1460. extern void tpkey_acts_dump(void);
  1461. static int shell_cmd_tp(const struct shell *shell,
  1462. size_t argc, char **argv)
  1463. {
  1464. tpkey_acts_dump();
  1465. return 0;
  1466. }
  1467. #endif
  1468. #if defined(CONFIG_EXTEND_GPIO_ET6416_SHELL)
  1469. #include <drivers/gpio.h>
  1470. static int shell_cmd_exgpio(const struct shell *shell,
  1471. size_t argc, char **argv)
  1472. {
  1473. int gpio, val = 0;
  1474. const struct device *gpio_dev;
  1475. if (argc < 3) {
  1476. shell_print(shell, "exgpio in/out num [val]\n");
  1477. return -EINVAL;
  1478. }
  1479. gpio = strtoul(argv[2], NULL, 0);
  1480. if (argc >= 4)
  1481. val = strtoul(argv[3], NULL, 0);
  1482. gpio_dev = device_get_binding(CONFIG_EXTEND_GPIO_NAME);
  1483. if (!gpio_dev){
  1484. shell_print(shell,"extern gpio dev get fail\n");
  1485. return -EINVAL;
  1486. }
  1487. if(strcmp(argv[1], "out") == 0){
  1488. gpio_pin_configure(gpio_dev, gpio, GPIO_OUTPUT);
  1489. gpio_pin_set(gpio_dev, gpio, val);
  1490. shell_print(shell,"exgpio%d,out, val=%d\n", gpio, val);
  1491. }else{
  1492. gpio_pin_configure(gpio_dev, gpio, GPIO_INPUT);
  1493. k_msleep(100);
  1494. val = gpio_pin_get(gpio_dev, gpio);
  1495. shell_print(shell,"exgpio%d, in, val=%d\n", gpio, val);
  1496. }
  1497. return 0;
  1498. }
  1499. #endif
  1500. #if defined(CONFIG_ACTIONS_PRINTK_DMA)
  1501. static int shell_cmd_printk_by_dma_cpu(const struct shell *shell,
  1502. size_t argc, char **argv)
  1503. {
  1504. if(argc != 2){
  1505. shell_print(shell, "dbgsw cpu[dma]\n");
  1506. return -EINVAL;
  1507. }
  1508. if (strcmp(argv[1], "cpu") == 0){
  1509. shell_print(shell, "switch to cpu print\n");
  1510. printk_dma_switch(0);
  1511. }else{
  1512. shell_print(shell, "switch to dma print\n");
  1513. printk_dma_switch(1);
  1514. }
  1515. return 0;
  1516. }
  1517. #endif
  1518. #if defined(CONFIG_SOC_SPICACHE_PROFILE_STAT)
  1519. extern int shell_cmd_spicache_profile_stat(const struct shell *shell,
  1520. size_t argc, char **argv);
  1521. #endif
  1522. #if defined(CONFIG_TRACING_IRQ_PROFILER)
  1523. #include <arch/cpu.h>
  1524. #if defined(CONFIG_CPU_CORTEX_M)
  1525. #include <arch/arm/aarch32/cortex_m/cmsis.h>
  1526. #elif defined(CONFIG_CPU_CORTEX_A) || defined(CONFIG_CPU_CORTEX_R)
  1527. #include <drivers/interrupt_controller/gic.h>
  1528. #endif
  1529. void dump_irqstat(void)
  1530. {
  1531. struct _isr_table_entry *ite;
  1532. int i;
  1533. printk("IRQ statistics:\n");
  1534. printk("irq prio count max_time (us) total (us) isr\n");
  1535. for (i = 0; i < IRQ_TABLE_SIZE; i++) {
  1536. ite = &_sw_isr_table[i];
  1537. if (ite->isr != z_irq_spurious) {
  1538. if(irq_is_enabled(i)){
  1539. printk("%2d(*) %2d %10d", i, NVIC_GetPriority(i), ite->irq_cnt);
  1540. }else{
  1541. printk("%2d %2d %10d", i, NVIC_GetPriority(i), ite->irq_cnt);
  1542. }
  1543. printk(" %10d",
  1544. (u32_t)(k_cyc_to_ns_floor64(ite->max_irq_cycles) / 1000));
  1545. printk(" %10d",
  1546. ite->irq_total_us);
  1547. #ifdef CONFIG_KALLSYMS
  1548. print_symbol(" %s", (unsigned long)ite->isr);
  1549. #endif
  1550. printk("\n");
  1551. }
  1552. }
  1553. }
  1554. static int shell_cmd_irqstat(const struct shell *shell,int argc, char *argv[])
  1555. {
  1556. struct _isr_table_entry *ite;
  1557. int i;
  1558. unsigned int key;
  1559. ARG_UNUSED(argc);
  1560. ARG_UNUSED(argv);
  1561. dump_irqstat();
  1562. if (argc >= 2 && !strncmp(argv[1], "clear", strlen(argv[1]))) {
  1563. key = irq_lock();
  1564. /* clear irq statistics */
  1565. for (i = 0; i < IRQ_TABLE_SIZE; i++) {
  1566. ite = &_sw_isr_table[i];
  1567. if (ite->isr != z_irq_spurious) {
  1568. ite->irq_cnt = 0;
  1569. ite->max_irq_cycles = 0;
  1570. ite->irq_total_us = 0;
  1571. }
  1572. }
  1573. irq_unlock(key);
  1574. }
  1575. return 0;
  1576. }
  1577. #endif /* CONFIG_IRQ_STAT */
  1578. #if defined(CONFIG_RES_MANAGER)
  1579. extern void res_manager_dump_info(void);
  1580. extern void bitmap_font_dump_info(void);
  1581. static int shell_cmd_dump_res(const struct shell *shell,
  1582. size_t argc, char **argv)
  1583. {
  1584. res_manager_dump_info();
  1585. bitmap_font_dump_info();
  1586. return 0;
  1587. }
  1588. #endif
  1589. #ifdef CONFIG_ACTS_HRTIMER
  1590. #include <drivers/hrtimer.h>
  1591. static struct hrtimer g_ht;
  1592. static void htimer_fun(struct hrtimer *ttimer, void *expiry_fn_arg)
  1593. {
  1594. static int t;
  1595. printk("%d ---htimer--\n", t++);
  1596. }
  1597. static void htimer_test(unsigned int ms)
  1598. {
  1599. hrtimer_init(&g_ht, htimer_fun, NULL);
  1600. hrtimer_start(&g_ht, 1000*ms, 1000*ms);
  1601. }
  1602. static int shell_cmd_wksrc(const struct shell *shell,
  1603. size_t argc, char **argv)
  1604. {
  1605. unsigned int ms=1000;
  1606. if(argc == 2)
  1607. ms = strtoul(argv[1], NULL, 10);
  1608. htimer_test(ms);
  1609. sys_s3_wksrc_set(SLEEP_WK_SRC_T1);
  1610. shell_print(shell, "set t1 %dms wakeup\n", ms);
  1611. return 0;
  1612. }
  1613. #endif
  1614. #if defined(CONFIG_RTC_ACTS)
  1615. #include <drivers/rtc.h>
  1616. static void rtc_help(void)
  1617. {
  1618. printk("usage:\n");
  1619. printk("Get the current rtc time e.g. rtc\n");
  1620. printk("Set the rtc time e.g. rtc set 2019-09-11 18:14:54\n");
  1621. }
  1622. static void show_rtc_time(void)
  1623. {
  1624. struct rtc_time tm;
  1625. const struct device *dev = device_get_binding(CONFIG_RTC_0_NAME);
  1626. if (!dev) {
  1627. printk("rtc dev binding failed!\n");
  1628. return;
  1629. }
  1630. rtc_get_time(dev, &tm);
  1631. print_rtc_time(&tm);
  1632. }
  1633. static void ymdstring_to_tm(const char *timestr, struct rtc_time *tm)
  1634. {
  1635. #ifdef CONFIG_MINIMAL_LIBC
  1636. char *p, *s;
  1637. const char *split = "-";
  1638. if (!timestr || !tm)
  1639. return ;
  1640. p = strtok_r((char *)timestr, split, &s);
  1641. if (!p)
  1642. return;
  1643. tm->tm_year = strtoul(p, NULL, 10);
  1644. tm->tm_year -= 1900;
  1645. p = strtok_r(NULL, split, &s);
  1646. if (!p)
  1647. return;
  1648. tm->tm_mon = strtoul(p, NULL, 10);
  1649. tm->tm_mon -= 1;
  1650. p = strtok_r(NULL, split, &s);
  1651. if (!p)
  1652. return;
  1653. tm->tm_mday = strtoul(p, NULL, 10);
  1654. #else
  1655. char *p;
  1656. const char *split = "-";
  1657. if (!timestr || !tm)
  1658. return ;
  1659. p = strtok((char *)timestr, split);
  1660. if (!p)
  1661. return;
  1662. tm->tm_year = strtoul(p, NULL, 10);
  1663. tm->tm_year -= 1900;
  1664. p = strtok(NULL, split);
  1665. if (!p)
  1666. return;
  1667. tm->tm_mon = strtoul(p, NULL, 10);
  1668. tm->tm_mon -= 1;
  1669. p = strtok(NULL, split);
  1670. if (!p)
  1671. return;
  1672. tm->tm_mday = strtoul(p, NULL, 10);
  1673. #endif
  1674. }
  1675. static void hmsstring_to_tm(const char *timestr, struct rtc_time *tm)
  1676. {
  1677. #ifdef CONFIG_MINIMAL_LIBC
  1678. char *p, *s;
  1679. const char *split = ":";
  1680. if (!timestr || !tm)
  1681. return ;
  1682. p = strtok_r((char *)timestr, split, &s);
  1683. if (!p)
  1684. return;
  1685. tm->tm_hour = strtoul(p, NULL, 10);
  1686. p = strtok_r(NULL, split, &s);
  1687. if (!p)
  1688. return;
  1689. tm->tm_min = strtoul(p, NULL, 10);
  1690. p = strtok_r(NULL, split, &s);
  1691. if (!p)
  1692. return;
  1693. tm->tm_sec = strtoul(p, NULL, 10);
  1694. #else
  1695. char *p;
  1696. const char *split = ":";
  1697. if (!timestr || !tm)
  1698. return ;
  1699. p = strtok((char *)timestr, split);
  1700. if (!p)
  1701. return;
  1702. tm->tm_hour = strtoul(p, NULL, 10);
  1703. p = strtok(NULL, split);
  1704. if (!p)
  1705. return;
  1706. tm->tm_min = strtoul(p, NULL, 10);
  1707. p = strtok(NULL, split);
  1708. if (!p)
  1709. return;
  1710. tm->tm_sec = strtoul(p, NULL, 10);
  1711. #endif
  1712. }
  1713. static int shell_cmd_rtc(const struct shell *shell, size_t argc, char **argv)
  1714. {
  1715. struct rtc_time tm = {0};
  1716. const struct device *dev = device_get_binding(CONFIG_RTC_0_NAME);
  1717. if (!dev) {
  1718. printk("Failed to get the RTC device\n");
  1719. return -ENXIO;
  1720. }
  1721. if (!strcmp(argv[1], "help")) {
  1722. rtc_help();
  1723. } else if (!strcmp(argv[1], "set")) {
  1724. if (argc != 4) {
  1725. rtc_help();
  1726. return -EPERM;
  1727. }
  1728. ymdstring_to_tm(argv[2], &tm);
  1729. hmsstring_to_tm(argv[3], &tm);
  1730. print_rtc_time(&tm);
  1731. if (rtc_set_time(dev, &tm))
  1732. printk("Failed to set rtc time\n");
  1733. else
  1734. printk("rtc set time successfully\n");
  1735. } else {
  1736. show_rtc_time();
  1737. }
  1738. return 0;
  1739. }
  1740. #endif
  1741. #ifdef CONFIG_ALARM8HZ_ACTS
  1742. #include <drivers/alarm.h>
  1743. void shell_cmd_alarm8hz_cb_func(const void *cb_data)
  1744. {
  1745. const struct device *dev = (const struct device *)cb_data;
  1746. struct alarm_config config = {0};
  1747. config.alarm_msec = 1000;
  1748. config.cb_fn = shell_cmd_alarm8hz_cb_func;
  1749. config.cb_data = dev;
  1750. printk("** On alarm8hz **\n");
  1751. acts_alarm_set_alarm(dev, &config, true);
  1752. }
  1753. static int shell_cmd_alarm8hz(const struct shell *shell, size_t argc, char **argv)
  1754. {
  1755. const struct device *dev = device_get_binding(CONFIG_ALARM8HZ_0_NAME);
  1756. struct alarm_config config = {0};
  1757. uint32_t alarm_msec = 1000;
  1758. if (!dev) {
  1759. printk("failed to get alarm8hz device:%s\n", CONFIG_ALARM8HZ_0_NAME);
  1760. return -ENXIO;
  1761. }
  1762. if ((argc > 1) && (!strcmp(argv[1], "enable"))) {
  1763. config.alarm_msec = alarm_msec;
  1764. config.cb_fn = shell_cmd_alarm8hz_cb_func;
  1765. config.cb_data = dev;
  1766. acts_alarm_set_alarm(dev, &config, true);
  1767. } else if ((argc > 1) && (!strcmp(argv[1], "disable"))) {
  1768. acts_alarm_set_alarm(dev, NULL, false);
  1769. }
  1770. return 0;
  1771. }
  1772. #endif
  1773. #if defined(CONFIG_ACTIONS_ARM_MPU)
  1774. #include <act_arm_mpu.h>
  1775. static int shell_mpu_set(const struct shell *shell, size_t argc, char **argv)
  1776. {
  1777. uint32_t mpu_base, mpu_size, attr;
  1778. if (argc != 4 ) {
  1779. shell_print(shell, "usage: mpu_set mem_base size ro[no/rw/ro] \n");
  1780. return -1;
  1781. }
  1782. mpu_base = strtoul(argv[1], NULL, 0);
  1783. mpu_size = strtoul(argv[2], NULL, 0);
  1784. if(!strcmp("no", argv[3]))
  1785. attr = 0;
  1786. else if (!strcmp("rw", argv[3]))
  1787. attr = 1;
  1788. else
  1789. attr = 2;
  1790. if(mpu_base)
  1791. act_mpu_set(MPU_CHAN_SHELL, mpu_base, mpu_size, attr);
  1792. else
  1793. act_mpu_unset(MPU_CHAN_SHELL);
  1794. return 0;
  1795. }
  1796. #endif
  1797. #if defined(CONFIG_ACTS_DVFS_DYNAMIC_LEVEL)
  1798. #include <dvfs.h>
  1799. static int shell_cmd_dvfs(const struct shell *shell, size_t argc, char **argv)
  1800. {
  1801. uint32_t level;
  1802. if (argc != 3) {
  1803. printk("usage: dvfs set/unset level\n");
  1804. return -1;
  1805. }
  1806. level = strtoul(argv[2], NULL, 10);
  1807. if (!strcmp(argv[1], "set")) {
  1808. dvfs_set_level(level, "shell_dvfs");
  1809. } else if (!strcmp(argv[1], "unset")) {
  1810. dvfs_unset_level(level, "shell_dvfs");
  1811. }
  1812. return 0;
  1813. }
  1814. #endif
  1815. //#define CONFIG_ACTS_POWER_ONOFF_TEST
  1816. #if defined(CONFIG_ACTS_POWER_ONOFF_TEST)
  1817. #include <drivers/nvram_config.h>
  1818. static struct k_delayed_work power_work;
  1819. static void power_off_work(struct k_work *work)
  1820. {
  1821. unsigned int power_cnt = 0;
  1822. if(nvram_config_get("power_cnt", &power_cnt, 4) < 0){
  1823. printk("nvram get power_cnt fail\n");
  1824. }
  1825. power_cnt++;
  1826. nvram_config_set("power_cnt", &power_cnt, 4);
  1827. printk("------power off count=%d----------\n", power_cnt);
  1828. soc_pmu_alarm8hz_enable(4000); //4 s wakeup
  1829. sys_pm_poweroff();
  1830. }
  1831. static void power_off_test(void)
  1832. {
  1833. unsigned int power_en = 0;
  1834. if(nvram_config_get("power_en", &power_en, 4) < 0){
  1835. printk("nvram get power_en fail\n");
  1836. }else{
  1837. printk("nvram get power_en=%d\n", power_en);
  1838. }
  1839. if(power_en){
  1840. printk("----power_off_test---\n");
  1841. k_delayed_work_init(&power_work, power_off_work);
  1842. k_delayed_work_submit(&power_work, K_MSEC(8000));
  1843. }
  1844. }
  1845. void power_onoff_test(unsigned int enable)
  1846. {
  1847. unsigned int power_cnt = 0;
  1848. nvram_config_set("power_en", &enable, 4);
  1849. if(enable){
  1850. nvram_config_set("power_cnt", &power_cnt, 4);
  1851. printk("******power onoff test start*********\n");
  1852. power_off_work(NULL);
  1853. }else{
  1854. printk("******power onoff test stop*********\n");
  1855. }
  1856. }
  1857. static int shell_cmd_onoff(const struct shell *shell, size_t argc, char **argv)
  1858. {
  1859. if (argc != 2) {
  1860. printk("usage: onoff enable/disable\n");
  1861. return -1;
  1862. }
  1863. if (!strcmp(argv[1], "enable")) {
  1864. power_onoff_test(1);
  1865. }else if (!strcmp(argv[1], "disable")){
  1866. power_onoff_test(0);
  1867. }else{
  1868. printk("err usage: onoff enable/disable\n");
  1869. }
  1870. return 0;
  1871. }
  1872. static int power_onoff_init(const struct device *arg)
  1873. {
  1874. power_off_test();
  1875. return 0;
  1876. }
  1877. SYS_INIT(power_onoff_init, APPLICATION, 91);
  1878. #endif
  1879. #if defined(CONFIG_DEBUG_RAMDUMP)
  1880. static int shell_cmd_ramdump(const struct shell *shell, size_t argc, char **argv)
  1881. {
  1882. if (argc != 2) {
  1883. printk("usage: ramdump save/dump\n");
  1884. return -1;
  1885. }
  1886. if (!strcmp(argv[1], "save")) {
  1887. ramdump_save(NULL, 0);
  1888. }else if (!strcmp(argv[1], "dump")){
  1889. ramdump_dump();
  1890. }else{
  1891. printk("usage: ramdump save/dump\n");
  1892. }
  1893. return 0;
  1894. }
  1895. #endif
  1896. SHELL_STATIC_SUBCMD_SET_CREATE(sub_dbg,
  1897. #if defined(CONFIG_CMD_MEMORY)
  1898. SHELL_CMD(mdw, NULL, "display memory by word: mdw address [,count]" , shell_cmd_mdw ),
  1899. SHELL_CMD(mdh, NULL, "display memory by half-word: mdh address [,count]" , shell_cmd_mdh),
  1900. SHELL_CMD(mdb, NULL, "display memory by byte: mdb address [,count]" , shell_cmd_mdb),
  1901. SHELL_CMD(mww, NULL, "memory write (fill) by word: mww address value [,count]" , shell_cmd_mww),
  1902. SHELL_CMD(mwh, NULL, "memory write (fill) by half-word: mwh address value [,count]" , shell_cmd_mwh),
  1903. SHELL_CMD(mwb, NULL,"memory write (fill) by byte: mwb address value [,count]" , shell_cmd_mwb),
  1904. #endif
  1905. #if defined(CONFIG_SOC_SPICACHE_PROFILE)
  1906. SHELL_CMD(spicache_profile, NULL, "spicache_profile.", shell_cmd_spicache_profile),
  1907. #endif
  1908. #if defined(CONFIG_SOC_SPICACHE_PROFILE_STAT)
  1909. SHELL_CMD(spicache_stat, NULL, "spicache_profile stat.", shell_cmd_spicache_profile_stat),
  1910. #endif
  1911. #if defined(CONFIG_CMD_SPINOR)
  1912. SHELL_CMD(snort, NULL, "nor test : snort address size", shell_nor_speed_test),
  1913. SHELL_CMD(fread, NULL, "flash read : fread dev[sd/spi_flash/spinand] offset", shell_flash_read),
  1914. #endif
  1915. #if defined(CONFIG_CMD_SPINAND)
  1916. SHELL_CMD(snandr, NULL, "nand logic read: offset start address; size read len;", shell_nand_read),
  1917. SHELL_CMD(snandw, NULL, "nand logic write: offset start address; size read len;", shell_nand_write),
  1918. SHELL_CMD(snand_printlevel, NULL, "set spinand lib print level(1:err;2:warn;3:info;4:debug);", shell_nand_print_level),
  1919. #if defined(CONFIG_SPINAND_TEST_FRAMEWORKS)
  1920. SHELL_CMD(snand_ioctrl, NULL, "spinand ioctrl test.", shell_nand_ioctrl),
  1921. //SHELL_CMD(snandlt, NULL, "nand logic test: offset start address; size read len;", shell_nand_logic_speed_test),
  1922. SHELL_CMD(snand_sdc, NULL, "nand delaychain scan.", shell_nand_delaychain_scan),
  1923. SHELL_CMD(snand_flush, NULL, "nand manual flush.", shell_nand_flush),
  1924. #if defined(CONFIG_SPINAND_TEST_FRAMEWORKS_ADDITION)
  1925. SHELL_CMD(snand_hardware_params, NULL, "spinand print hardware params.", shell_nand_hardware_params),
  1926. SHELL_CMD(snand_software_params, NULL, "spinand print software params.", shell_nand_software_params),
  1927. SHELL_CMD(snand_blk_erase_test, NULL, "spinand blk phy erase and readback test.", shell_nand_blk_erase_test),
  1928. SHELL_CMD(snand_phy_page_write_test, NULL, "spinand phy page write test.", shell_nand_page_write_test),
  1929. SHELL_CMD(snand_phy_page_read_test, NULL, "spinand phy page read test.", shell_nand_page_read_test),
  1930. SHELL_CMD(snand_api_boundary_test, NULL, "spinand api boundary test.", shell_nand_api_boundary_test),
  1931. SHELL_CMD(snand_ldl_page_read_test, NULL, "spinand ldl single page read test.", shell_nand_read_sigle_page_test),
  1932. SHELL_CMD(snand_ldl_page_write_test, NULL, "spinand ldl single page write test.", shell_nand_write_sigle_page_test),
  1933. SHELL_CMD(snand_page_readback_test, NULL, "spinand logic page readback test.", shell_nand_page_readback_test),
  1934. SHELL_CMD(snand_zonetbl_rotation_test, NULL, "spinand zonetbl rotation test.", shell_nand_zonetbl_rotation_test),
  1935. SHELL_CMD(snand_zonetbl_rewrite_test, NULL, "spinand zonetbl rewrite test.", shell_nand_rewrite_zonetbl_test),
  1936. SHELL_CMD(snand_erase_zonetbl_blk_test, NULL, "spinand erase zonetbl blk test.", shell_nand_erase_zonetbl_blk_test),
  1937. SHELL_CMD(snand_read_speed_test, NULL, "spinand read speed test.", shell_nand_read_speed_test),
  1938. SHELL_CMD(snand_write_speed_test, NULL, "spinand write speed test.", shell_nand_write_speed_test),
  1939. SHELL_CMD(snand_pdlinit_time_cost_test, NULL, "spinand pdl init time cost test.", shell_nand_pdlinit_time_cost_test),
  1940. SHELL_CMD(snand_zonetbl_init_time_cost_test, NULL, "spinand zonetbl init time cost test.", shell_nand_zonetbl_init_time_cost_test),
  1941. SHELL_CMD(snand_read_write_udisk, NULL, "spinand write and read udisk test.", shell_nand_read_write_udisk),
  1942. #endif
  1943. #endif
  1944. #endif
  1945. #if defined(CONFIG_DMA_DBG_DUMP)
  1946. SHELL_CMD(dma_dump, NULL, "dma info", shell_dma_info),
  1947. #endif
  1948. #if defined(CONFIG_SD_FS)
  1949. SHELL_CMD(sdfs, NULL, "sdfs name size", shell_sdfs_dump),
  1950. #endif
  1951. #if defined(CONFIG_NVRAM_CONFIG)
  1952. SHELL_CMD(nvdump, NULL, "nvram dump", shell_nvram_dump),
  1953. SHELL_CMD(nvram, NULL, "nvram name (val)", shell_nvram_cmd),
  1954. #endif
  1955. #if defined(CONFIG_DISPLAY_ENGINE)
  1956. SHELL_CMD(de_dump, NULL, "de dump", shell_de_dump),
  1957. #endif
  1958. #if defined(CONFIG_DISPLAY_LCDC)
  1959. SHELL_CMD(lcd_dump, NULL, "lcdc dump", shell_lcd_dump),
  1960. #endif
  1961. #if defined(CONFIG_BT_DRV)
  1962. SHELL_CMD(bb-reg, NULL, "read/write btc bb ctl", shell_cmd_bqb_bb),
  1963. SHELL_CMD(rf-reg, NULL, "read/write btc rf ctl", shell_cmd_bqb_rf),
  1964. #endif
  1965. #if defined(CONFIG_PM_LOG_LEVEL_INF)
  1966. SHELL_CMD(sleep, NULL, "sleep", shell_cmd_sleep),
  1967. #endif
  1968. #if defined(CONFIG_KERNEL_SHOW_STACK)
  1969. SHELL_CMD(show_stack, NULL, "show kernel stack", shell_show_stack),
  1970. #endif
  1971. SHELL_CMD(reboot, NULL, "reboot [adfu]", shell_cmd_reboot),
  1972. SHELL_CMD(kheap, NULL, "kheap [addr]", shell_cmd_khead_dump),
  1973. #if defined(CONFIG_UI_MEMORY_MANAGER)
  1974. SHELL_CMD(uimem, NULL, "uimem dump [0|1|2], where 0-FB, 1-LVGL, 2-RES", shell_cmd_dump_uimem),
  1975. #endif
  1976. #if defined(CONFIG_UI_SERVICE)
  1977. SHELL_CMD(uiview, NULL, "view dump", shell_cmd_dump_uiview),
  1978. #endif
  1979. #if defined(CONFIG_THREAD_RUNTIME_STATS)
  1980. SHELL_CMD(cpuload, NULL, "show cpu load statistic preriodically", shell_cmd_cpuload),
  1981. #endif
  1982. #if defined(CONFIG_FAT_FILESYSTEM_ELM)
  1983. SHELL_CMD(dumpbuf, NULL, "dump buffer to file system: dumpbuf addr len path", shell_cmd_dumpbuf),
  1984. #endif
  1985. #if defined(CONFIG_MSG_MANAGER)
  1986. SHELL_CMD(dumpmsg, NULL, "dump message: dumpmsg", shell_cmd_dumpmsg),
  1987. #endif
  1988. #if RBUF_POOL_DBG && defined(CONFIG_RBUF_LIB)
  1989. SHELL_CMD(dumprbuf, NULL, "dump rbuf in share ram", shell_cmd_dumprbuf),
  1990. #endif
  1991. #if defined(CONFIG_UI_INPUT_RECORDER)
  1992. SHELL_CMD(inputscrl, NULL, "input scroll forth and back at hort/vert dir:"
  1993. "inputscrl {hstart|vstart|stop} {start_coord} {end_coord} {step}",
  1994. shell_cmd_input_autoscrl),
  1995. #if defined(CONFIG_FILE_STREAM)
  1996. SHELL_CMD(inputrec, NULL, "input record: inputrec {record|play} {repeat|start|stop} [file]", shell_cmd_input_record),
  1997. #endif
  1998. #endif
  1999. #if defined(CONFIG_INPUT_DEV_ACTS_CST816S_TP_KEY)
  2000. SHELL_CMD(tpnotify, NULL, "dump gesture and location", shell_cmd_tp),
  2001. #endif
  2002. #if defined(CONFIG_EXTEND_GPIO_ET6416_SHELL)
  2003. SHELL_CMD(exgpio, NULL, "exgpio in/out num [val]", shell_cmd_exgpio),
  2004. #endif
  2005. #if defined(CONFIG_ACTIONS_PRINTK_DMA)
  2006. SHELL_CMD(dbgsw, NULL, "dbgsw cpu[dma]", shell_cmd_printk_by_dma_cpu),
  2007. #endif
  2008. #if defined(CONFIG_TRACING_IRQ_PROFILER)
  2009. SHELL_CMD(irqstat, NULL, "irqstat (clear)", shell_cmd_irqstat),
  2010. #endif
  2011. #if defined(CONFIG_TOOL)
  2012. //SHELL_CMD(tool, NULL, "tool [aset]", shell_cmd_tool_connect),
  2013. #endif
  2014. #if defined(CONFIG_RES_MANAGER)
  2015. SHELL_CMD(resman, NULL, "resource dump", shell_cmd_dump_res),
  2016. #endif
  2017. #if defined(CONFIG_ACTS_HRTIMER)
  2018. SHELL_CMD(wksrct, NULL, "wksrct ms", shell_cmd_wksrc),
  2019. #endif
  2020. #if defined(CONFIG_RTC_ACTS)
  2021. SHELL_CMD(rtc, NULL, "rtc get/set current time", shell_cmd_rtc),
  2022. #endif
  2023. #if defined(CONFIG_ALARM8HZ_ACTS)
  2024. SHELL_CMD(alarm8hz, NULL, "alarm8hz set alarm time", shell_cmd_alarm8hz),
  2025. #endif
  2026. #if defined(CONFIG_ACTS_DVFS_DYNAMIC_LEVEL)
  2027. SHELL_CMD(dvfs, NULL, "dvfs set/unset level", shell_cmd_dvfs),
  2028. #endif
  2029. #if defined(CONFIG_ACTIONS_ARM_MPU)
  2030. SHELL_CMD(mpu_set, NULL, "mpu_set mem_base size ro[no/rw/ro]", shell_mpu_set),
  2031. #endif
  2032. #if defined(CONFIG_ACTS_POWER_ONOFF_TEST)
  2033. SHELL_CMD(onoff, NULL, "onoff enable/disable", shell_cmd_onoff),
  2034. #endif
  2035. #if defined(CONFIG_DEBUG_RAMDUMP)
  2036. SHELL_CMD(ramdump, NULL, "dump ram to flash", shell_cmd_ramdump),
  2037. #endif
  2038. SHELL_SUBCMD_SET_END /* Array terminated. */
  2039. );
  2040. SHELL_CMD_REGISTER(dbg, &sub_dbg, "dbg commands", NULL);