0017-tools-add-some-helper-tools-for-Lantiq-SoCs.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. From 1da5479d59b39d7931a2b0efabdfa314f6788b6d Mon Sep 17 00:00:00 2001
  2. From: Luka Perkov <luka@openwrt.org>
  3. Date: Sat, 2 Mar 2013 23:34:00 +0100
  4. Subject: tools: add some helper tools for Lantiq SoCs
  5. Signed-off-by: Luka Perkov Luka Perkov <luka@openwrt.org>
  6. Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  7. --- /dev/null
  8. +++ b/tools/gct.pl
  9. @@ -0,0 +1,155 @@
  10. +#!/usr/bin/perl
  11. +
  12. +#use strict;
  13. +#use Cwd;
  14. +#use Env;
  15. +
  16. +my $aline;
  17. +my $lineid;
  18. +my $length;
  19. +my $address;
  20. +my @bytes;
  21. +my $addstr;
  22. +my $chsum=0;
  23. +my $count=0;
  24. +my $firstime=1;
  25. +my $i;
  26. +my $currentaddr;
  27. +my $tmp;
  28. +my $holder="";
  29. +my $loadaddr;
  30. +
  31. +if(@ARGV < 2){
  32. + die("\n Syntax: perl gct.pl uart_ddr_settings.conf u-boot.srec u-boot.asc\n");
  33. +}
  34. +
  35. +open(IN_UART_DDR_SETTINGS, "<$ARGV[0]") || die("failed to open uart_ddr_settings.conf\n");
  36. +open(IN_UART_SREC, "<$ARGV[1]") || die("failed to open u-boot.srec\n");
  37. +open(OUT_UBOOT_ASC, ">$ARGV[2]") || die("failed to open u-boot.asc\n");
  38. +
  39. +$i=0;
  40. +while ($line = <IN_UART_DDR_SETTINGS>){
  41. + if($line=~/\w/){
  42. + if($line!~/[;#\*]/){
  43. + if($i eq 0){
  44. + printf OUT_UBOOT_ASC ("33333333");
  45. + }
  46. + chomp($line);
  47. + $line=~s/\t//;
  48. + @array=split(/ +/,$line);
  49. + $j=0;
  50. + while(@array[$j]!~/\w/){
  51. + $j=$j+1;
  52. + }
  53. + $addr=@array[$j];
  54. + $regval=@array[$j+1];
  55. + $addr=~s/0x//;
  56. + $regval=~s/0x//;
  57. + printf OUT_UBOOT_ASC ("%08x%08x",hex($addr),hex($regval));
  58. + $i=$i+1;
  59. + if($i eq 8){
  60. + $i=0;
  61. + printf OUT_UBOOT_ASC ("\n");
  62. + }
  63. + }
  64. + }
  65. +}
  66. +
  67. +while($i lt 8 && $i gt 0){
  68. + printf OUT_UBOOT_ASC "00"x8;
  69. + $i=$i+1;
  70. +}
  71. +
  72. +if($i eq 8){
  73. + printf OUT_UBOOT_ASC ("\n");
  74. +}
  75. +
  76. +while($aline=<IN_UART_SREC>){
  77. + $aline=uc($aline);
  78. + chomp($aline);
  79. + next if(($aline=~/^S0/) || ($aline=~/^S7/));
  80. + ($lineid, $length, $address, @bytes) = unpack"A2A2A8"."A2"x300, $aline;
  81. + $length = hex($length);
  82. + $address = hex($address);
  83. + $length -=5;
  84. + $i=0;
  85. +
  86. + while($length>0){
  87. + if($firstime==1){
  88. + $addstr = sprintf("%x", $address);
  89. + $addstr = "0"x(8-length($addstr)).$addstr;
  90. + print OUT_UBOOT_ASC $addstr;
  91. + addchsum($addstr);
  92. + $firstime=0;
  93. + $currentaddr=$address;
  94. + $loadaddr = $addstr;
  95. + }
  96. + else{
  97. + if($count==64){
  98. + $addstr = sprintf("%x", $currentaddr);
  99. + $addstr = "0"x(8-length($addstr)).$addstr;
  100. + print OUT_UBOOT_ASC $addstr;
  101. + addchsum($addstr);
  102. + $count=0;
  103. + }
  104. +#printf("*** %x != %x\n", $address, $currentaddr) if $address != $currentaddr;
  105. + }
  106. + if($currentaddr < $address) {
  107. + print OUT_UBOOT_ASC "00";
  108. + addchsum("00");
  109. + $count++;
  110. + $currentaddr++;
  111. + }
  112. + else {
  113. + while($count<64){
  114. + $bytes[$i]=~tr/ABCDEF/abcdef/;
  115. + print OUT_UBOOT_ASC "$bytes[$i]";
  116. + addchsum($bytes[$i]);
  117. + $i++;
  118. + $count++;
  119. + $currentaddr++;
  120. + $length--;
  121. + last if($length==0);
  122. + }
  123. + }
  124. + if($count==64){
  125. + print OUT_UBOOT_ASC "\n";
  126. + }
  127. + }
  128. +}
  129. +if($count != 64){
  130. + $tmp = "00";
  131. + for($i=0;$i<(64-$count);$i++){
  132. + print OUT_UBOOT_ASC "00";
  133. + addchsum($tmp);
  134. + }
  135. + print OUT_UBOOT_ASC "\n";
  136. +}
  137. +
  138. +
  139. +print OUT_UBOOT_ASC "11"x4;
  140. +use integer;
  141. +$chsum=$chsum & 0xffffffff;
  142. +$chsum = sprintf("%X", $chsum);
  143. +$chsum = "0"x(8-length($chsum)).$chsum;
  144. +$chsum =~tr/ABCDEF/abcdef/;
  145. +print OUT_UBOOT_ASC $chsum;
  146. +print OUT_UBOOT_ASC "00"x60;
  147. +print OUT_UBOOT_ASC "\n";
  148. +
  149. +print OUT_UBOOT_ASC "99"x4;
  150. +print OUT_UBOOT_ASC $loadaddr;
  151. +print OUT_UBOOT_ASC "00"x60;
  152. +print OUT_UBOOT_ASC "\n";
  153. +
  154. +close OUT_UBOOT_ASC;
  155. +
  156. +sub addchsum{
  157. + my $cc=$_[0];
  158. + $holder=$holder.$cc;
  159. + if(length($holder)==8){
  160. + $holder = hex($holder);
  161. + $chsum+=$holder;
  162. + $holder="";
  163. + }
  164. +}
  165. --- /dev/null
  166. +++ b/tools/lantiq_bdi_conf.awk
  167. @@ -0,0 +1,116 @@
  168. +#!/usr/bin/awk -f
  169. +#
  170. +# Copyright (C) 2013 Luka Perkov <luka@openwrt.org>
  171. +# Copyright (C) 2013 Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  172. +#
  173. +# Usage:
  174. +# awk -f lantiq_bdi_conf.awk -v soc=ar9 board=<name> PATH_TO_BOARD/ddr_settings.h
  175. +#
  176. +# Additional information:
  177. +# http://www.abatron.ch/fileadmin/user_upload/products/pdf/ManGDBR4K-3000.pdf
  178. +#
  179. +# SPDX-License-Identifier: GPL-2.0+
  180. +#
  181. +
  182. +function print_header()
  183. +{
  184. + print "; "
  185. + print "; Copyright (C) 2013 Luka Perkov <luka@openwrt.org> "
  186. + print "; Copyright (C) 2013 Daniel Schwierzeck <daniel.schwierzeck@gmail.com> "
  187. + print "; "
  188. + print "; This file has been generated with lantiq_bdi_conf.awk script. "
  189. + print "; "
  190. + print "; SPDX-License-Identifier: GPL-2.0+ "
  191. + print "; "
  192. + print ""
  193. +}
  194. +
  195. +function init_ar9_prologue()
  196. +{
  197. + print "WM32 0xBF103010 0x80 ; CGU for CPU 333Mhz, DDR 167Mhz"
  198. + print "WM32 0xBF103014 0x01 ; CGU update"
  199. + print "WM32 0xBF800010 0x0 ; Clear error access log register"
  200. + print "WM32 0xBF800020 0x0 ; Clear error access log register"
  201. + print "WM32 0xBF800060 0xD ; Enable FPI, DDR and SRAM module in memory controller"
  202. + print "WM32 0xBF801030 0x0 ; Clear start bit of DDR memory controller"
  203. +}
  204. +
  205. +function init_ar9_epilogue()
  206. +{
  207. + print "WM32 0xBE105360 0x4001D7FF ; EBU setup"
  208. +}
  209. +
  210. +function init_ddr1_epilogue()
  211. +{
  212. + print "WM32 0xBF801030 0x100 ; Set start bit of DDR memory controller"
  213. +}
  214. +
  215. +function ar9_target()
  216. +{
  217. + print "CPUTYPE M34K"
  218. + print "ENDIAN BIG"
  219. + print "JTAGCLOCK 1"
  220. + print "BDIMODE AGENT ; [ LOADONLY, AGENT ]"
  221. + print "RESET JTAG ; [ NONE, JTAG, HARD ]"
  222. + print "POWERUP 100"
  223. + print "WAKEUP 100"
  224. + print "BREAKMODE HARD ; [ SOFT, HARD ]"
  225. + print "STEPMODE SWBP ; [ JTAG, HWBP, SWBP ]"
  226. + print "VECTOR CATCH"
  227. + print "SCANSUCC 1 5"
  228. +}
  229. +
  230. +function flash_p2601hnfx()
  231. +{
  232. + print "CHIPTYPE MIRRORX16"
  233. + print "CHIPSIZE 0x1000000"
  234. + print "BUSWIDTH 16"
  235. +}
  236. +
  237. +BEGIN {
  238. + switch (soc) {
  239. + case "ar9":
  240. + reg_base = 0xbf801000
  241. + print_header()
  242. + print "[INIT]"
  243. + init_ar9_prologue()
  244. + break
  245. + default:
  246. + print "Invalid or no value for SoC specified!"
  247. + exit 1
  248. + }
  249. +}
  250. +
  251. +/^#define/ {
  252. + /* DC03 contains MC enable bit and must not be set here */
  253. + if (tolower($2) != "mc_dc03_value")
  254. + printf("WM32 0x%x %s\n", reg_base, tolower($3))
  255. +
  256. + reg_base += 0x10
  257. +}
  258. +
  259. +END {
  260. + switch (soc) {
  261. + case "ar9":
  262. + init_ddr1_epilogue()
  263. + init_ar9_epilogue()
  264. + print ""
  265. + print "[TARGET]"
  266. + ar9_target()
  267. + print ""
  268. + print "[HOST]"
  269. + print "PROMPT \"ar9> \""
  270. + print ""
  271. + break
  272. + default:
  273. + }
  274. +
  275. + switch (board) {
  276. + case "p2601hnfx":
  277. + print "[FLASH]"
  278. + flash_p2601hnfx()
  279. + print ""
  280. + break
  281. + default:
  282. + }
  283. +}
  284. --- /dev/null
  285. +++ b/tools/lantiq_ram_extract_magic.awk
  286. @@ -0,0 +1,69 @@
  287. +#
  288. +# Copyright (C) 2011-2013 Luka Perkov <luka@openwrt.org>
  289. +#
  290. +# Usage:
  291. +# mips-openwrt-linux-objdump -EB -b binary -m mips:isa32r2 -D YOUR_IMAGE_DUMP | awk -f lantiq_ram_extract_magic.awk
  292. +#
  293. +# SPDX-License-Identifier: GPL-2.0+
  294. +#
  295. +
  296. +BEGIN {
  297. + print "/* "
  298. + print " * Copyright (C) 2011-2013 Luka Perkov <luka@openwrt.org> "
  299. + print " * "
  300. + print " * This file has been generated with lantiq_ram_extract_magic.awk script. "
  301. + print " * "
  302. + print " * SPDX-License-Identifier: GPL-2.0+ "
  303. + print " */ "
  304. + print ""
  305. +
  306. + mc_dc_value=0
  307. + mc_dc_number=0
  308. + right_section=0
  309. + mc_dc_value_print=0
  310. + mc_dc_number_print=0
  311. +}
  312. +
  313. +/t2,[0-9]+$/ {
  314. + if (right_section) {
  315. + split($4, tmp, ",")
  316. + mc_dc_value=sprintf("%X", tmp[2])
  317. + mc_dc_value_print=1
  318. + }
  319. +}
  320. +
  321. +/t2,0x[0-9a-f]+$/ {
  322. + if (right_section) {
  323. + split($4, tmp, ",0x")
  324. + mc_dc_value=sprintf("%s", tmp[2])
  325. + mc_dc_value=toupper(mc_dc_value)
  326. + mc_dc_value_print=1
  327. + }
  328. +}
  329. +
  330. +/t2,[0-9]+\(t1\)$/ {
  331. + if (right_section) {
  332. + split($4, tmp, ",")
  333. + split(tmp[2], tmp, "(")
  334. + mc_dc_number=tmp[1]/16
  335. + mc_dc_number_print=1
  336. + }
  337. +}
  338. +
  339. +{
  340. + if (right_section && mc_dc_number_print && mc_dc_value_print) {
  341. + if (mc_dc_number < 10)
  342. + print "#define MC_DC0" mc_dc_number "_VALUE\t0x" mc_dc_value
  343. + else
  344. + print "#define MC_DC" mc_dc_number "_VALUE\t0x" mc_dc_value
  345. + mc_dc_value_print=0
  346. + mc_dc_number_print=0
  347. + }
  348. +
  349. + if ($4 == "t1,t1,0x1000")
  350. + right_section=1
  351. +
  352. +
  353. + if ($4 == "t2,736(t1)")
  354. + right_section=0
  355. +}
  356. --- /dev/null
  357. +++ b/tools/lantiq_ram_init_uart.awk
  358. @@ -0,0 +1,117 @@
  359. +#!/usr/bin/awk -f
  360. +#
  361. +# Copyright (C) 2011-2012 Luka Perkov <luka@openwrt.org>
  362. +# Copyright (C) 2012 Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  363. +#
  364. +# Usage:
  365. +# awk -f lantiq_ram_init_uart.awk -v soc=<danube|ar9|vr9> PATH_TO_BOARD/ddr_settings.h
  366. +#
  367. +# SPDX-License-Identifier: GPL-2.0+
  368. +#
  369. +
  370. +function print_header()
  371. +{
  372. + print "; "
  373. + print "; Copyright (C) 2011-2013 Luka Perkov <luka@openwrt.org> "
  374. + print "; Copyright (C) 2012-2013 Daniel Schwierzeck <daniel.schwierzeck@gmail.com> "
  375. + print "; "
  376. + print "; This file has been generated with lantiq_ram_init_uart.awk script. "
  377. + print "; "
  378. + print "; SPDX-License-Identifier: GPL-2.0+ "
  379. + print ""
  380. +}
  381. +
  382. +function mc_danube_prologue()
  383. +{
  384. + /* Clear access error log registers */
  385. + print "0xbf800010", "0x0"
  386. + print "0xbf800020", "0x0"
  387. +
  388. + /* Enable DDR and SRAM module in memory controller */
  389. + print "0xbf800060", "0x5"
  390. +
  391. + /* Clear start bit of DDR memory controller */
  392. + print "0xbf801030", "0x0"
  393. +}
  394. +
  395. +function mc_ar9_prologue()
  396. +{
  397. + /* Clear access error log registers */
  398. + print "0xbf800010", "0x0"
  399. + print "0xbf800020", "0x0"
  400. +
  401. + /* Enable FPI, DDR and SRAM module in memory controller */
  402. + print "0xbf800060", "0xD"
  403. +
  404. + /* Clear start bit of DDR memory controller */
  405. + print "0xbf801030", "0x0"
  406. +}
  407. +
  408. +function mc_ddr1_epilogue()
  409. +{
  410. + /* Set start bit of DDR memory controller */
  411. + print "0xbf801030", "0x100"
  412. +}
  413. +
  414. +function mc_ddr2_prologue()
  415. +{
  416. + /* Put memory controller in inactive mode */
  417. + print "0xbf401070", "0x0"
  418. +}
  419. +
  420. +function mc_ddr2_epilogue(mc_ccr07_value)
  421. +{
  422. + /* Put memory controller in active mode */
  423. + mc_ccr07_value = or(mc_ccr07_value, 0x100)
  424. + printf("0xbf401070 0x%x\n", mc_ccr07_value)
  425. +}
  426. +
  427. +BEGIN {
  428. + switch (soc) {
  429. + case "danube":
  430. + reg_base = 0xbf801000
  431. + print_header()
  432. + mc_danube_prologue()
  433. + break
  434. + case "ar9":
  435. + reg_base = 0xbf801000
  436. + print_header()
  437. + mc_ar9_prologue()
  438. + break
  439. + case "vr9":
  440. + reg_base = 0xbf401000
  441. + print_header()
  442. + mc_ddr2_prologue()
  443. + break
  444. + default:
  445. + print "Invalid or no value for soc specified!"
  446. + exit 1
  447. + }
  448. +
  449. + mc_ccr07_value = 0
  450. +}
  451. +
  452. +/^#define/ {
  453. + /* CCR07 contains MC enable bit and must not be set here */
  454. + if (tolower($2) == "mc_ccr07_value")
  455. + mc_ccr07_value = strtonum($3)
  456. + if (tolower($2) == "mc_dc03_value")
  457. + /* CCR07 contains MC enable bit and must not be set here */
  458. + else
  459. + printf("0x%x %s\n", reg_base, tolower($3))
  460. +
  461. + reg_base += 0x10
  462. +}
  463. +
  464. +END {
  465. + switch (soc) {
  466. + case "danube":
  467. + case "ar9":
  468. + mc_ddr1_epilogue()
  469. + break
  470. + case "vr9":
  471. + mc_ddr2_epilogue(mc_ccr07_value)
  472. + break
  473. + default:
  474. + }
  475. +}