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
6 Signed-off-by: Luka Perkov Luka Perkov <luka@openwrt.org>
7 Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
34 + die("\n Syntax: perl gct.pl uart_ddr_settings.conf u-boot.srec u-boot.asc\n");
37 +open(IN_UART_DDR_SETTINGS, "<$ARGV[0]") || die("failed to open uart_ddr_settings.conf\n");
38 +open(IN_UART_SREC, "<$ARGV[1]") || die("failed to open u-boot.srec\n");
39 +open(OUT_UBOOT_ASC, ">$ARGV[2]") || die("failed to open u-boot.asc\n");
42 +while ($line = <IN_UART_DDR_SETTINGS>){
44 + if($line!~/[;#\*]/){
46 + printf OUT_UBOOT_ASC ("33333333");
50 + @array=split(/ +/,$line);
52 + while(@array[$j]!~/\w/){
56 + $regval=@array[$j+1];
59 + printf OUT_UBOOT_ASC ("%08x%08x",hex($addr),hex($regval));
63 + printf OUT_UBOOT_ASC ("\n");
69 +while($i lt 8 && $i gt 0){
70 + printf OUT_UBOOT_ASC "00"x8;
75 + printf OUT_UBOOT_ASC ("\n");
78 +while($aline=<IN_UART_SREC>){
81 + next if(($aline=~/^S0/) || ($aline=~/^S7/));
82 + ($lineid, $length, $address, @bytes) = unpack"A2A2A8"."A2"x300, $aline;
83 + $length = hex($length);
84 + $address = hex($address);
90 + $addstr = sprintf("%x", $address);
91 + $addstr = "0"x(8-length($addstr)).$addstr;
92 + print OUT_UBOOT_ASC $addstr;
95 + $currentaddr=$address;
96 + $loadaddr = $addstr;
100 + $addstr = sprintf("%x", $currentaddr);
101 + $addstr = "0"x(8-length($addstr)).$addstr;
102 + print OUT_UBOOT_ASC $addstr;
106 +#printf("*** %x != %x\n", $address, $currentaddr) if $address != $currentaddr;
108 + if($currentaddr < $address) {
109 + print OUT_UBOOT_ASC "00";
116 + $bytes[$i]=~tr/ABCDEF/abcdef/;
117 + print OUT_UBOOT_ASC "$bytes[$i]";
118 + addchsum($bytes[$i]);
123 + last if($length==0);
127 + print OUT_UBOOT_ASC "\n";
133 + for($i=0;$i<(64-$count);$i++){
134 + print OUT_UBOOT_ASC "00";
137 + print OUT_UBOOT_ASC "\n";
141 +print OUT_UBOOT_ASC "11"x4;
143 +$chsum=$chsum & 0xffffffff;
144 +$chsum = sprintf("%X", $chsum);
145 +$chsum = "0"x(8-length($chsum)).$chsum;
146 +$chsum =~tr/ABCDEF/abcdef/;
147 +print OUT_UBOOT_ASC $chsum;
148 +print OUT_UBOOT_ASC "00"x60;
149 +print OUT_UBOOT_ASC "\n";
151 +print OUT_UBOOT_ASC "99"x4;
152 +print OUT_UBOOT_ASC $loadaddr;
153 +print OUT_UBOOT_ASC "00"x60;
154 +print OUT_UBOOT_ASC "\n";
156 +close OUT_UBOOT_ASC;
160 + $holder=$holder.$cc;
161 + if(length($holder)==8){
162 + $holder = hex($holder);
168 +++ b/tools/lantiq_bdi_conf.awk
172 +# Copyright (C) 2013 Luka Perkov <luka@openwrt.org>
173 +# Copyright (C) 2013 Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
176 +# awk -f lantiq_bdi_conf.awk -v soc=ar9 board=<name> PATH_TO_BOARD/ddr_settings.h
178 +# Additional information:
179 +# http://www.abatron.ch/fileadmin/user_upload/products/pdf/ManGDBR4K-3000.pdf
181 +# SPDX-License-Identifier: GPL-2.0+
184 +function print_header()
187 + print "; Copyright (C) 2013 Luka Perkov <luka@openwrt.org> "
188 + print "; Copyright (C) 2013 Daniel Schwierzeck <daniel.schwierzeck@gmail.com> "
190 + print "; This file has been generated with lantiq_bdi_conf.awk script. "
192 + print "; SPDX-License-Identifier: GPL-2.0+ "
197 +function init_ar9_prologue()
199 + print "WM32 0xBF103010 0x80 ; CGU for CPU 333Mhz, DDR 167Mhz"
200 + print "WM32 0xBF103014 0x01 ; CGU update"
201 + print "WM32 0xBF800010 0x0 ; Clear error access log register"
202 + print "WM32 0xBF800020 0x0 ; Clear error access log register"
203 + print "WM32 0xBF800060 0xD ; Enable FPI, DDR and SRAM module in memory controller"
204 + print "WM32 0xBF801030 0x0 ; Clear start bit of DDR memory controller"
207 +function init_ar9_epilogue()
209 + print "WM32 0xBE105360 0x4001D7FF ; EBU setup"
212 +function init_ddr1_epilogue()
214 + print "WM32 0xBF801030 0x100 ; Set start bit of DDR memory controller"
217 +function ar9_target()
219 + print "CPUTYPE M34K"
221 + print "JTAGCLOCK 1"
222 + print "BDIMODE AGENT ; [ LOADONLY, AGENT ]"
223 + print "RESET JTAG ; [ NONE, JTAG, HARD ]"
224 + print "POWERUP 100"
226 + print "BREAKMODE HARD ; [ SOFT, HARD ]"
227 + print "STEPMODE SWBP ; [ JTAG, HWBP, SWBP ]"
228 + print "VECTOR CATCH"
229 + print "SCANSUCC 1 5"
232 +function flash_p2601hnfx()
234 + print "CHIPTYPE MIRRORX16"
235 + print "CHIPSIZE 0x1000000"
236 + print "BUSWIDTH 16"
242 + reg_base = 0xbf801000
245 + init_ar9_prologue()
248 + print "Invalid or no value for SoC specified!"
254 + /* DC03 contains MC enable bit and must not be set here */
255 + if (tolower($2) != "mc_dc03_value")
256 + printf("WM32 0x%x %s\n", reg_base, tolower($3))
264 + init_ddr1_epilogue()
265 + init_ar9_epilogue()
271 + print "PROMPT \"ar9> \""
287 +++ b/tools/lantiq_ram_extract_magic.awk
290 +# Copyright (C) 2011-2013 Luka Perkov <luka@openwrt.org>
293 +# mips-openwrt-linux-objdump -EB -b binary -m mips:isa32r2 -D YOUR_IMAGE_DUMP | awk -f lantiq_ram_extract_magic.awk
295 +# SPDX-License-Identifier: GPL-2.0+
300 + print " * Copyright (C) 2011-2013 Luka Perkov <luka@openwrt.org> "
302 + print " * This file has been generated with lantiq_ram_extract_magic.awk script. "
304 + print " * SPDX-License-Identifier: GPL-2.0+ "
311 + mc_dc_value_print=0
312 + mc_dc_number_print=0
316 + if (right_section) {
317 + split($4, tmp, ",")
318 + mc_dc_value=sprintf("%X", tmp[2])
319 + mc_dc_value_print=1
324 + if (right_section) {
325 + split($4, tmp, ",0x")
326 + mc_dc_value=sprintf("%s", tmp[2])
327 + mc_dc_value=toupper(mc_dc_value)
328 + mc_dc_value_print=1
332 +/t2,[0-9]+\(t1\)$/ {
333 + if (right_section) {
334 + split($4, tmp, ",")
335 + split(tmp[2], tmp, "(")
336 + mc_dc_number=tmp[1]/16
337 + mc_dc_number_print=1
342 + if (right_section && mc_dc_number_print && mc_dc_value_print) {
343 + if (mc_dc_number < 10)
344 + print "#define MC_DC0" mc_dc_number "_VALUE\t0x" mc_dc_value
346 + print "#define MC_DC" mc_dc_number "_VALUE\t0x" mc_dc_value
347 + mc_dc_value_print=0
348 + mc_dc_number_print=0
351 + if ($4 == "t1,t1,0x1000")
355 + if ($4 == "t2,736(t1)")
359 +++ b/tools/lantiq_ram_init_uart.awk
363 +# Copyright (C) 2011-2012 Luka Perkov <luka@openwrt.org>
364 +# Copyright (C) 2012 Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
367 +# awk -f lantiq_ram_init_uart.awk -v soc=<danube|ar9|vr9> PATH_TO_BOARD/ddr_settings.h
369 +# SPDX-License-Identifier: GPL-2.0+
372 +function print_header()
375 + print "; Copyright (C) 2011-2013 Luka Perkov <luka@openwrt.org> "
376 + print "; Copyright (C) 2012-2013 Daniel Schwierzeck <daniel.schwierzeck@gmail.com> "
378 + print "; This file has been generated with lantiq_ram_init_uart.awk script. "
380 + print "; SPDX-License-Identifier: GPL-2.0+ "
384 +function mc_danube_prologue()
386 + /* Clear access error log registers */
387 + print "0xbf800010", "0x0"
388 + print "0xbf800020", "0x0"
390 + /* Enable DDR and SRAM module in memory controller */
391 + print "0xbf800060", "0x5"
393 + /* Clear start bit of DDR memory controller */
394 + print "0xbf801030", "0x0"
397 +function mc_ar9_prologue()
399 + /* Clear access error log registers */
400 + print "0xbf800010", "0x0"
401 + print "0xbf800020", "0x0"
403 + /* Enable FPI, DDR and SRAM module in memory controller */
404 + print "0xbf800060", "0xD"
406 + /* Clear start bit of DDR memory controller */
407 + print "0xbf801030", "0x0"
410 +function mc_ddr1_epilogue()
412 + /* Set start bit of DDR memory controller */
413 + print "0xbf801030", "0x100"
416 +function mc_ddr2_prologue()
418 + /* Put memory controller in inactive mode */
419 + print "0xbf401070", "0x0"
422 +function mc_ddr2_epilogue(mc_ccr07_value)
424 + /* Put memory controller in active mode */
425 + mc_ccr07_value = or(mc_ccr07_value, 0x100)
426 + printf("0xbf401070 0x%x\n", mc_ccr07_value)
432 + reg_base = 0xbf801000
434 + mc_danube_prologue()
437 + reg_base = 0xbf801000
442 + reg_base = 0xbf401000
447 + print "Invalid or no value for soc specified!"
455 + /* CCR07 contains MC enable bit and must not be set here */
456 + if (tolower($2) == "mc_ccr07_value")
457 + mc_ccr07_value = strtonum($3)
458 + if (tolower($2) == "mc_dc03_value")
459 + /* CCR07 contains MC enable bit and must not be set here */
461 + printf("0x%x %s\n", reg_base, tolower($3))
473 + mc_ddr2_epilogue(mc_ccr07_value)