source: soft/giet_vm/xml/xml_driver.c @ 253

Last change on this file since 253 was 253, checked in by alain, 11 years ago

1/ introducing support to display images on the frame buffer
with the vci_chbuf_dma (in stdio.c and drivers.c)
2/ introducing support for mem_cache configuration segment
as the memory cache is considered as another addressable peripheral type
(in drivers.c)
3/ Introducing the new "increment" parameter in the mapping header.
This parameter define the virtual address increment for the vsegs
associated to the replicated peripherals (ICU, XICU, MDMA, TIMER, MMC).
This parameter is mandatory, and all map.xml files the "mappings"
directory have been updated.

File size: 16.4 KB
Line 
1////////////////////////////////////////////////////////////////////////////
2// File     : xml_driver.c
3// Date     : 04/04/2012
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6////////////////////////////////////////////////////////////////////////////
7// This program translate a binary file containing a MAPPING_INFO
8// data structure to an xml file.
9////////////////////////////////////////////////////////////////////////////
10
11#include  <stdlib.h>
12#include  <fcntl.h>
13#include  <unistd.h>
14#include  <stdio.h>
15#include  <string.h>
16#include  <stdint.h>
17#include  <mapping_info.h>
18
19//////////////////////////////////////////////////////
20void buildXml(mapping_header_t * header, FILE * fpout) {
21    const char * vobj_type[] = 
22    { 
23        "ELF",        // binary code generated by GCC
24        "BLOB",       // binary code generated by GCC
25        "PTAB",       // page table
26        "PERI",       // hardware component
27        "MWMR",       // MWMR channel
28        "LOCK",       // Spin-Lock
29        "BUFFER",     // Any "no intialiasation needed" objects (stacks...)
30        "BARRIER",    // Barrier
31        "CONST",      // Constant
32        "MEMSPACE",   // Memspace
33        "SCHED",      // Scheduler
34    };
35
36    const char * pseg_type[] = 
37    {
38        "RAM",
39        "ROM",
40        "PERI",
41    };
42
43    const char * irq_type[] =
44    {
45        "HARD",
46        "SOFT",
47    };
48
49    const char * isr_type[] =
50    {
51        "ISR_DEFAULT",
52        "ISR_SWITCH",
53        "ISR_TTY",
54        "ISR_DMA",
55        "ISR_IOC",
56        "ISR_TIMER",
57    };
58
59    const char * periph_type[] =
60    {
61        "ICU",
62        "TIM",
63        "DMA",
64        "MMC",
65        "CMA",
66        "IOC",
67        "TTY",
68        "FBF",
69        "NIC",
70        "IOB",
71        "GCD",
72        "XCU",
73    };
74
75    const char * port_direction[] =
76    {
77        "TO_COPROC",
78        "FROM_COPROC",
79    };
80
81    const char * mode_str[] = 
82    { 
83        "____",
84        "___U", 
85        "__W_", 
86        "__WU", 
87        "_X__", 
88        "_X_U", 
89        "_XW_", 
90        "_XWU", 
91        "C___", 
92        "C__U", 
93        "C_W_", 
94        "C_WU", 
95        "CX__", 
96        "CX_U", 
97        "CXW_", 
98        "CXWU", 
99    };
100
101    unsigned int vspace_id;
102    unsigned int cluster_id;
103    unsigned int pseg_id;
104    unsigned int vseg_id;
105    unsigned int vobj_id;
106    unsigned int task_id;
107    unsigned int proc_id;
108    unsigned int irq_id;
109    unsigned int coproc_id;
110    unsigned int port_id;
111    unsigned int periph_id;
112
113    mapping_cluster_t * cluster;
114    mapping_pseg_t * pseg;
115    mapping_vspace_t * vspace;
116    mapping_vseg_t * vseg;
117    mapping_vobj_t * vobj;
118    mapping_task_t * task;
119    mapping_proc_t * proc;
120    mapping_irq_t * irq;   
121    mapping_coproc_t * coproc;
122    mapping_cp_port_t * cp_port;
123    mapping_periph_t * periph;
124
125    // computes the base adresss for clusters array,
126    cluster = (mapping_cluster_t *)((char *) header +
127            MAPPING_HEADER_SIZE);
128
129    // computes the base adresss for psegs array,
130    pseg = (mapping_pseg_t *) ((char *) header +
131            MAPPING_HEADER_SIZE +
132            MAPPING_CLUSTER_SIZE * header->clusters);
133
134    // computes the base adresss for vspaces array,
135    vspace = (mapping_vspace_t *) ((char *) header +
136            MAPPING_HEADER_SIZE +
137            MAPPING_CLUSTER_SIZE * header->clusters +
138            MAPPING_PSEG_SIZE * header->psegs);
139
140    // computes the base adresss for vsegs array,
141    vseg = (mapping_vseg_t *) ((char *) header +
142            MAPPING_HEADER_SIZE +
143            MAPPING_CLUSTER_SIZE * header->clusters +
144            MAPPING_PSEG_SIZE * header->psegs +
145            MAPPING_VSPACE_SIZE * header->vspaces);
146
147    // computes the base adresss for vobjs array,
148    vobj = (mapping_vobj_t *) ((char *) header +
149            MAPPING_HEADER_SIZE +
150            MAPPING_CLUSTER_SIZE * header->clusters +
151            MAPPING_PSEG_SIZE * header->psegs +
152            MAPPING_VSPACE_SIZE * header->vspaces +
153            MAPPING_VSEG_SIZE * header->vsegs);
154
155    // computes the base address for tasks array
156    task = (mapping_task_t *) ((char *) header +
157            MAPPING_HEADER_SIZE +
158            MAPPING_CLUSTER_SIZE * header->clusters +
159            MAPPING_PSEG_SIZE * header->psegs +
160            MAPPING_VSPACE_SIZE * header->vspaces +
161            MAPPING_VOBJ_SIZE * header->vobjs +
162            MAPPING_VSEG_SIZE * header->vsegs);
163
164    // computes the base address for procs array
165    proc = (mapping_proc_t *) ((char *) header +
166            MAPPING_HEADER_SIZE +
167            MAPPING_CLUSTER_SIZE * header->clusters +
168            MAPPING_PSEG_SIZE * header->psegs +
169            MAPPING_VSPACE_SIZE * header->vspaces +
170            MAPPING_VOBJ_SIZE * header->vobjs +
171            MAPPING_VSEG_SIZE * header->vsegs +
172            MAPPING_TASK_SIZE * header->tasks);
173
174    // computes the base address for irqs array
175    irq = (mapping_irq_t *) ((char *) header +
176            MAPPING_HEADER_SIZE +
177            MAPPING_CLUSTER_SIZE * header->clusters +
178            MAPPING_PSEG_SIZE * header->psegs +
179            MAPPING_VSPACE_SIZE * header->vspaces +
180            MAPPING_VOBJ_SIZE * header->vobjs +
181            MAPPING_VSEG_SIZE * header->vsegs +
182            MAPPING_TASK_SIZE * header->tasks +
183            MAPPING_PROC_SIZE * header->procs);
184
185    // computes the base address for coprocs array
186    coproc = (mapping_coproc_t *) ((char *) header +
187            MAPPING_HEADER_SIZE +
188            MAPPING_CLUSTER_SIZE * header->clusters +
189            MAPPING_PSEG_SIZE * header->psegs +
190            MAPPING_VSPACE_SIZE * header->vspaces +
191            MAPPING_VOBJ_SIZE * header->vobjs +
192            MAPPING_VSEG_SIZE * header->vsegs +
193            MAPPING_TASK_SIZE * header->tasks +
194            MAPPING_PROC_SIZE * header->procs +
195            MAPPING_IRQ_SIZE * header->irqs);
196
197    // computes the base address for cp_ports array
198    cp_port = (mapping_cp_port_t *) ((char *) header +
199            MAPPING_HEADER_SIZE +
200            MAPPING_CLUSTER_SIZE * header->clusters +
201            MAPPING_PSEG_SIZE * header->psegs +
202            MAPPING_VSPACE_SIZE * header->vspaces +
203            MAPPING_VOBJ_SIZE * header->vobjs +
204            MAPPING_VSEG_SIZE * header->vsegs +
205            MAPPING_TASK_SIZE * header->tasks +
206            MAPPING_PROC_SIZE * header->procs +
207            MAPPING_IRQ_SIZE * header->irqs +
208            MAPPING_COPROC_SIZE * header->coprocs);
209
210    // computes the base address for periphs array
211    periph = (mapping_periph_t *) ((char *) header +
212            MAPPING_HEADER_SIZE +
213            MAPPING_CLUSTER_SIZE * header->clusters +
214            MAPPING_PSEG_SIZE * header->psegs +
215            MAPPING_VSPACE_SIZE * header->vspaces +
216            MAPPING_VOBJ_SIZE * header->vobjs +
217            MAPPING_VSEG_SIZE * header->vsegs +
218            MAPPING_TASK_SIZE * header->tasks +
219            MAPPING_PROC_SIZE * header->procs +
220            MAPPING_IRQ_SIZE * header->irqs +
221            MAPPING_COPROC_SIZE * header->coprocs +
222            MAPPING_CP_PORT_SIZE * header->cp_ports);
223
224    ///////////////////////// header /////////////////////////////////////////////
225
226    fprintf(fpout, "<?xml version = \"1.0\"?>\n\n");
227
228    fprintf(fpout, "<mapping_info signature = \"0x%x\" ", header->signature);
229    fprintf(fpout, " name = \"%s\" ", header->name);
230    fprintf(fpout, " cluster_x = \"%d\" ", header->cluster_x);
231    fprintf(fpout, " cluster_y = \"%d\" ", header->cluster_y);
232    fprintf(fpout, " vspaces = \"%d\" >\n\n", header->vspaces);
233
234    ///////////////////// clusters ///////////////////////////////////////////////
235
236    fprintf( fpout, "    <clusterset>\n");
237    for (cluster_id = 0; cluster_id < header->clusters; cluster_id++) {
238        fprintf(fpout, "        <cluster index  = \"%d\" >\n", cluster_id);
239        for (pseg_id = cluster[cluster_id].pseg_offset;
240                pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs;
241                pseg_id++) {
242            fprintf(fpout, "            <pseg name = \"%s\" ", pseg[pseg_id].name);
243            fprintf(fpout, " type = \"%s\" ", pseg_type[pseg[pseg_id].type]);
244            fprintf(fpout, " base = \"0x%llx\" ", pseg[pseg_id].base);
245            fprintf(fpout, " length = \"0x%llx\" />\n",   pseg[pseg_id].length);
246        }
247
248        ///////////////////// processors /////////////////////////////////////////////
249
250        unsigned int proc_index = 0;
251        for (proc_id = cluster[cluster_id].proc_offset;
252                proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs;
253                proc_id++) {
254            fprintf(fpout, "            <proc index = \"%d\" >\n", proc_index);
255            for (irq_id = proc[proc_id].irq_offset; 
256                    irq_id < proc[proc_id].irq_offset + proc[proc_id].irqs;
257                    irq_id++) {
258                fprintf(fpout, "                <irq type = \"%s\" ", irq_type[irq[irq_id].type]);
259                fprintf(fpout, " icuid = \"0x%x\" ", irq[irq_id].icuid);
260                fprintf(fpout, " isr = \"%s\" ", isr_type[irq[irq_id].isr]);
261                fprintf(fpout, " channel = \"0x%x\" />\n", irq[irq_id].channel);
262            }
263            fprintf(fpout, "            </proc>\n" );
264        }
265
266
267        ///////////////////// coprocessors ///////////////////////////////////////////
268
269        for (coproc_id = cluster[cluster_id].coproc_offset;
270                coproc_id < cluster[cluster_id].coproc_offset + cluster[cluster_id].coprocs;
271                coproc_id++) {
272            fprintf(fpout, "            <coproc name = \"%s\" ", coproc[coproc_id].name);
273            fprintf(fpout, " psegname = \"%s\" >\n", pseg[coproc[coproc_id].psegid].name);
274            for (port_id = coproc[coproc_id].port_offset;
275                    port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports;
276                    port_id++) {
277                unsigned int vobj_id = cp_port[port_id].mwmr_vobjid + vspace[cp_port[port_id].vspaceid].vobj_offset; 
278                fprintf(fpout, "             <port direction = \"%s\" ",  port_direction[cp_port[port_id].direction]);
279                fprintf(fpout, " vspacename = \"%s\" ", vspace[cp_port[port_id].vspaceid].name);
280                fprintf(fpout, " vobjname = \"%s\" />\n",  vobj[vobj_id].name);
281            }
282            fprintf(fpout, "            </coproc>\n" );
283        }
284
285        ///////////////////// periphs  ///////////////////////////////////////////////
286
287        for (periph_id = cluster[cluster_id].periph_offset;
288                periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs;
289                periph_id++) {
290            fprintf(fpout, "            <periph type = \"%s\" ", periph_type[periph[periph_id].type]);
291            fprintf(fpout, " psegname = \"%s\" ", pseg[periph[periph_id].psegid].name);
292            fprintf(fpout, " channels = \"%d\" />\n",  periph[periph_id].channels);
293        }
294        fprintf(fpout, "        </cluster>\n" );
295    }
296    fprintf(fpout, "    </clusterset>\n\n" );
297
298    /////////////////// globals /////////////////////////////////////////////////
299
300    fprintf(fpout, "    <globalset>\n" );
301    for (vseg_id = 0; vseg_id < header->globals; vseg_id++) {
302        unsigned int pseg_id = vseg[vseg_id].psegid; 
303
304        fprintf(fpout, "        <vseg name = \"%s\" ", vseg[vseg_id].name);
305        fprintf(fpout, "vbase = \"0x%x\" ", vseg[vseg_id].vbase);
306        fprintf(fpout, "mode  = \"%s\" ", mode_str[vseg[vseg_id].mode]);
307        fprintf(fpout, "clusterid = \"%d\" ", pseg[pseg_id].cluster);
308        fprintf(fpout, "psegname = \"%s\" ", pseg[pseg_id].name);
309        fprintf(fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident);
310        for (vobj_id = vseg[vseg_id].vobj_offset;
311                vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs); 
312                vobj_id++) {
313            fprintf(fpout, "            <vobj name = \"%s\" ", vobj[vobj_id].name);
314            fprintf(fpout, "type = \"%s\" ", vobj_type[vobj[vobj_id].type]);
315            fprintf(fpout, "length = \"0x%x\" ", vobj[vobj_id].length);
316            fprintf(fpout, "align = \"%d\" ", vobj[vobj_id].align);
317            fprintf(fpout, "init = \"%d\" ", vobj[vobj_id].init);
318            fprintf(fpout, "binpath = \"%s\" />\n", vobj[vobj_id].binpath);
319        }
320        fprintf(fpout, "        </vseg>\n");
321    }
322    fprintf(fpout, "    </globalset>\n" );
323
324    //////////////////// vspaces ////////////////////////////////////////////////
325
326    fprintf( fpout, "\n    <vspaceset>\n\n" );
327    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) {
328        unsigned int func_id = vspace[vspace_id].vobj_offset + vspace[vspace_id].start_offset; 
329        fprintf(fpout, "        <vspace name = \"%s\" ", vspace[vspace_id].name); 
330        fprintf(fpout, " startname = \"%s\" >\n", vobj[func_id].name); 
331
332        for (vseg_id = vspace[vspace_id].vseg_offset;
333                vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs);
334                vseg_id++) {
335            unsigned int pseg_id = vseg[vseg_id].psegid; 
336
337            fprintf(fpout, "            <vseg name = \"%s\" ", vseg[vseg_id].name);
338            fprintf(fpout, "vbase = \"0x%x\" ", vseg[vseg_id].vbase);
339            fprintf(fpout, "mode  = \"%s\" ", mode_str[vseg[vseg_id].mode]);
340            fprintf(fpout, "clusterid = \"%d\" ", pseg[pseg_id].cluster);
341            fprintf(fpout, "psegname = \"%s\" ", pseg[pseg_id].name);
342            fprintf(fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident);
343
344            for (vobj_id = vseg[vseg_id].vobj_offset;
345                    vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs);
346                    vobj_id++) {
347                fprintf(fpout, "             <vobj name = \"%s\" ", vobj[vobj_id].name);
348                fprintf(fpout, "type = \"%s\" ", vobj_type[vobj[vobj_id].type]);
349                fprintf(fpout, "length = \"0x%x\" ", vobj[vobj_id].length);
350                fprintf(fpout, "align = \"%d\" ", vobj[vobj_id].align);
351                fprintf(fpout, "init = \"%d\" ", vobj[vobj_id].init);
352                fprintf(fpout, "binpath = \"%s\" />\n", vobj[vobj_id].binpath);
353            }
354            fprintf(fpout, "            </vseg>\n\n");
355        }
356        for (task_id = vspace[vspace_id].task_offset;
357                task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks);
358                task_id++) {
359            unsigned int stack_vobj_id = task[task_id].stack_vobjid + vspace[vspace_id].vobj_offset; 
360            unsigned int heap_vobj_id = task[task_id].heap_vobjid + vspace[vspace_id].vobj_offset; 
361
362            fprintf(fpout, "            <task name = \"%s\" ", task[task_id].name);
363            fprintf(fpout, "clusterid = \"%d\" ", task[task_id].clusterid);
364            fprintf(fpout, "proclocid = \"%d\" ", task[task_id].proclocid);
365            fprintf(fpout, "stackname = \"%s\" ", vobj[stack_vobj_id].name);
366            if (heap_vobj_id != -1) {
367                fprintf(fpout, "heapname = \"%s\" ", vobj[heap_vobj_id].name);
368            }
369            fprintf(fpout, "startid = \"%d\" ", task[task_id].startid);
370            fprintf(fpout, "usetty = \"%d\" ", task[task_id].use_tty);
371            fprintf(fpout, "usenic = \"%d\" ", task[task_id].use_nic);
372            fprintf(fpout, "usedma = \"%d\" ", task[task_id].use_dma);
373            fprintf(fpout, "usecma = \"%d\" ", task[task_id].use_cma);
374            fprintf(fpout, "usetim = \"%d\" ", task[task_id].use_tim);
375            fprintf(fpout, "useioc = \"%d\" />\n", task[task_id].use_ioc);
376        }
377        fprintf(fpout, "        </vspace>\n\n");
378    }
379    fprintf(fpout, "    </vspaceset>\n");
380    fprintf(fpout, "</mapping_info>\n");
381} // end buildXml()
382
383
384/////////////////////////////////////
385int main(int argc, char * argv[]) {
386    if (argc < 2) {
387        printf("Usage: bin2xml <input_file_path> <output_file_path>\n");
388        return 1;
389    }
390
391    unsigned int bin[0x10000]; // 64 K int = 256 Kbytes
392
393    int fdin = open(argv[1], O_RDONLY);
394    if (fdin < 0) {
395        perror("open");
396        exit(1);
397    }
398
399    FILE * fpout = fopen( argv[2], "w");
400    if (fpout == NULL) {
401        perror("open");
402        exit(1);
403    }
404
405    unsigned int length = read(fdin, bin, 0x40000);
406
407    if (length <= 0) {
408        perror("read");
409        exit(1);
410    }
411
412    if (bin[0] == IN_MAPPING_SIGNATURE) {
413        buildXml((mapping_header_t *) bin, fpout);
414    } 
415    else {
416        printf("[ERROR] Wrong file format\n");
417        exit(1);
418    }
419    return 0;
420} // end main()
421
422
423
424// Local Variables:
425// tab-width: 4
426// c-basic-offset: 4
427// c-file-offsets:((innamespace . 0)(inline-open . 0))
428// indent-tabs-mode: nil
429// End:
430// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
431
Note: See TracBrowser for help on using the repository browser.