• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..21-Mar-2021-

Makefile.amH A D08-Dec-20193.2 KiB186125

Makefile.inH A D21-Mar-202134.8 KiB969831

ahbjtag.cH A D08-Dec-20197.8 KiB321202

arm9tdmi.cH A D08-Dec-201914.8 KiB570364

au1500.cH A D08-Dec-20197.2 KiB316204

avr32.cH A D08-Dec-201921 KiB828628

bcm1250.cH A D08-Dec-201912.7 KiB544398

bf518f_ezbrd.cH A D08-Dec-20191.8 KiB6432

bf533_stamp.cH A D08-Dec-20192.3 KiB8651

bf537_stamp.cH A D08-Dec-20192.4 KiB7543

bf548_ezkit.cH A D08-Dec-20192.4 KiB8752

bf561_ezkit.cH A D08-Dec-20191.7 KiB6232

blackfin.cH A D08-Dec-20199.6 KiB359279

blackfin.hH A D08-Mar-20172.4 KiB9965

bscoach.cH A D08-Dec-201910.7 KiB393250

buses.cH A D08-Dec-20197.4 KiB257193

buses.hH A D08-Mar-20171,006 325

buses_list.hH A D08-Dec-20192.9 KiB148117

ejtag.cH A D08-Dec-201927.3 KiB781621

ejtag_dma.cH A D08-Dec-201920.9 KiB702532

fjmem.cH A D08-Dec-201920.3 KiB747527

generic_bus.cH A D08-Dec-20193.2 KiB16086

generic_bus.hH A D08-Mar-20171.6 KiB4717

h7202.cH A D08-Dec-20197.5 KiB313203

ixp425.cH A D08-Dec-20197 KiB305205

ixp435.cH A D08-Dec-20196.7 KiB293192

ixp465.cH A D08-Dec-20197.4 KiB317202

jopcyc.cH A D08-Dec-201921.4 KiB709508

lh7a400.cH A D08-Dec-20197.9 KiB342219

mpc5200.cH A D08-Dec-201910.3 KiB416298

mpc824x.cH A D08-Dec-201916.1 KiB598430

mpc8313.cH A D08-Dec-20199.4 KiB376259

mpc837x.cH A D08-Dec-201913.1 KiB510381

ppc405ep.cH A D08-Dec-20196.4 KiB282183

ppc440gx_ebc8.cH A D08-Dec-20196.8 KiB288189

prototype.cH A D08-Dec-201914.5 KiB534408

pxa2x0.cH A D08-Dec-201921.1 KiB796569

pxa2x0_mc.hH A D08-Mar-201718 KiB437335

readmem.cH A D08-Dec-20193.6 KiB13587

s3c4510x.cH A D08-Dec-201911.5 KiB442276

sa1110.cH A D08-Dec-20198 KiB322215

sh7727.cH A D08-Dec-20198.6 KiB362252

sh7750r.cH A D08-Dec-20198.3 KiB343238

sh7751r.cH A D08-Dec-20197.9 KiB331229

sharc21065l.cH A D08-Dec-20197.7 KiB331212

sharc21369_ezkit.cH A D08-Dec-20197.6 KiB317203

slsup3.cH A D08-Dec-201911.5 KiB455315

tx4925.cH A D08-Dec-20197.6 KiB326214

writemem.cH A D08-Dec-20194.1 KiB14799

zefant-xs3.cH A D08-Dec-201929.8 KiB1,003716

readmem.c

1 /*
2  * Copyright (C) 2002 ETC s.r.o.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17  * 02111-1307, USA.
18  *
19  * Written by Marcel Telka <marcel@telka.sk>, 2002.
20  *
21  * Documentation:
22  * [1] JEDEC Solid State Technology Association, "Common Flash Interface (CFI)",
23  *     September 1999, Order Number: JESD68
24  * [2] JEDEC Solid State Technology Association, "Common Flash Interface (CFI) ID Codes",
25  *     September 2001, Order Number: JEP137-A
26  *
27  */
28 
29 #include <sysdep.h>
30 
31 #include <stdint.h>
32 #include <string.h>
33 
34 #include <urjtag/log.h>
35 #include <urjtag/error.h>
36 #include <urjtag/bus.h>
37 #include <urjtag/flash.h>
38 #include <urjtag/jtag.h>
39 
40 int
urj_bus_readmem(urj_bus_t * bus,FILE * f,uint32_t addr,uint32_t len)41 urj_bus_readmem (urj_bus_t *bus, FILE *f, uint32_t addr, uint32_t len)
42 {
43     uint32_t step;
44     uint64_t a;
45     size_t bc = 0;
46 #define BSIZE 4096
47     uint8_t b[BSIZE];
48     urj_bus_area_t area;
49     uint64_t end;
50 
51     if (!bus)
52     {
53         urj_error_set (URJ_ERROR_NO_BUS_DRIVER, _("Missing bus driver"));
54         return URJ_STATUS_FAIL;
55     }
56 
57     URJ_BUS_PREPARE (bus);
58 
59     if (URJ_BUS_AREA (bus, addr, &area) != URJ_STATUS_OK)
60         return URJ_STATUS_FAIL;
61 
62     step = area.width / 8;
63 
64     if (step == 0)
65     {
66         urj_error_set (URJ_ERROR_INVALID,  _("Unknown bus width"));
67         return URJ_STATUS_FAIL;
68     }
69     if (BSIZE % step != 0)
70     {
71         urj_error_set (URJ_ERROR_INVALID, "step %lu must divide BSIZE %d",
72                        (long unsigned) step, BSIZE);
73         return URJ_STATUS_FAIL;
74     }
75 
76     addr = addr & (~(step - 1));
77     len = (len + step - 1) & (~(step - 1));
78 
79     urj_log (URJ_LOG_LEVEL_NORMAL, _("address: 0x%08lX\n"),
80              (long unsigned) addr);
81     urj_log (URJ_LOG_LEVEL_NORMAL, _("length:  0x%08lX\n"),
82              (long unsigned) len);
83 
84     if (len == 0)
85     {
86         urj_error_set (URJ_ERROR_INVALID, _("length is 0"));
87         return URJ_STATUS_FAIL;
88     }
89 
90     a = addr;
91     end = a + len;
92     urj_log (URJ_LOG_LEVEL_NORMAL, _("reading:\n"));
93 
94     if (URJ_BUS_READ_START (bus, addr) != URJ_STATUS_OK)
95         return URJ_STATUS_FAIL;
96 
97     for (a += step; a <= end; a += step)
98     {
99         uint32_t data;
100         int j;
101 
102         if (a < end)
103             data = URJ_BUS_READ_NEXT (bus, a);
104         else
105             data = URJ_BUS_READ_END (bus);
106 
107         for (j = step; j > 0; j--)
108             if (urj_get_file_endian () == URJ_ENDIAN_BIG)
109                 b[bc++] = (data >> ((j - 1) * 8)) & 0xFF;
110             else
111             {
112                 b[bc++] = data & 0xFF;
113                 data >>= 8;
114             }
115 
116         if ((bc >= BSIZE) || (a >= end))
117         {
118             urj_log (URJ_LOG_LEVEL_NORMAL, _("addr: 0x%08llX\r"),
119                      (long long unsigned) a);
120             if (fwrite (b, bc, 1, f) != 1)
121             {
122                 urj_error_set (URJ_ERROR_FILEIO, "fwrite fails");
123                 urj_error_state.sys_errno = ferror(f);
124                 clearerr(f);
125                 return URJ_STATUS_FAIL;
126             }
127             bc = 0;
128         }
129     }
130 
131     urj_log (URJ_LOG_LEVEL_NORMAL, _("\nDone.\n"));
132 
133     return URJ_STATUS_OK;
134 }
135