[258] | 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 | ////////////////////////////////////////////////////// |
---|
[295] | 20 | void buildXml(mapping_header_t * header, FILE * fpout) |
---|
| 21 | { |
---|
| 22 | // mnemonics defined in mapping_info.h |
---|
[511] | 23 | const char * vseg_type[] = |
---|
[258] | 24 | { |
---|
| 25 | "ELF", // binary code generated by GCC |
---|
[522] | 26 | "BLOB", // binary |
---|
[258] | 27 | "PTAB", // page table |
---|
| 28 | "PERI", // hardware component |
---|
| 29 | "MWMR", // MWMR channel |
---|
| 30 | "LOCK", // Spin-Lock |
---|
[295] | 31 | "BUFFER", // Any "no intialiasation needed" object (stacks...) |
---|
[258] | 32 | "BARRIER", // Barrier |
---|
| 33 | "CONST", // Constant |
---|
| 34 | "MEMSPACE", // Memspace |
---|
| 35 | "SCHED", // Scheduler |
---|
[472] | 36 | "HEAP", // Heap |
---|
[258] | 37 | }; |
---|
| 38 | |
---|
[295] | 39 | // mnemonics defined in mapping_info.h |
---|
[258] | 40 | const char * pseg_type[] = |
---|
| 41 | { |
---|
| 42 | "RAM", |
---|
| 43 | "PERI", |
---|
| 44 | }; |
---|
| 45 | |
---|
[295] | 46 | // mnemonics defined in mapping_info.h |
---|
[258] | 47 | const char * irq_type[] = |
---|
| 48 | { |
---|
[295] | 49 | "HWI", |
---|
| 50 | "WTI", |
---|
| 51 | "PTI", |
---|
[258] | 52 | }; |
---|
| 53 | |
---|
[522] | 54 | // These mnemonics must be consistent with values in |
---|
| 55 | // irq_handler.h / irq_handler.c / mapping.py |
---|
[258] | 56 | const char * isr_type[] = |
---|
| 57 | { |
---|
[295] | 58 | "ISR_DEFAULT", |
---|
| 59 | "ISR_TICK", |
---|
| 60 | "ISR_TTY_RX", |
---|
| 61 | "ISR_TTY_TX", |
---|
| 62 | "ISR_BDV", |
---|
[258] | 63 | "ISR_TIMER", |
---|
[295] | 64 | "ISR_WAKUP", |
---|
| 65 | "ISR_NIC_RX", |
---|
| 66 | "ISR_NIC_TX", |
---|
| 67 | "ISR_CMA", |
---|
[323] | 68 | "ISR_MMC", |
---|
| 69 | "ISR_DMA", |
---|
| 70 | "ISR_SPI", |
---|
[522] | 71 | "ISR_MWR", |
---|
[258] | 72 | }; |
---|
| 73 | |
---|
[522] | 74 | const char * mwr_subtype[] = |
---|
| 75 | { |
---|
| 76 | "GCD", |
---|
| 77 | "DCT", |
---|
| 78 | }; |
---|
| 79 | |
---|
[258] | 80 | const char * periph_type[] = |
---|
| 81 | { |
---|
| 82 | "CMA", |
---|
| 83 | "DMA", |
---|
| 84 | "FBF", |
---|
| 85 | "IOB", |
---|
| 86 | "IOC", |
---|
| 87 | "MMC", |
---|
| 88 | "MWR", |
---|
| 89 | "NIC", |
---|
| 90 | "ROM", |
---|
| 91 | "SIM", |
---|
| 92 | "TIM", |
---|
| 93 | "TTY", |
---|
| 94 | "XCU", |
---|
[295] | 95 | "PIC", |
---|
[491] | 96 | "DROM", |
---|
[258] | 97 | }; |
---|
| 98 | |
---|
[295] | 99 | const char * ioc_subtype[] = |
---|
[289] | 100 | { |
---|
| 101 | "BDV", |
---|
| 102 | "HBA", |
---|
| 103 | "SPI", |
---|
[323] | 104 | "NONE", |
---|
[289] | 105 | }; |
---|
| 106 | |
---|
[258] | 107 | const char * mode_str[] = |
---|
| 108 | { |
---|
| 109 | "____", |
---|
| 110 | "___U", |
---|
| 111 | "__W_", |
---|
| 112 | "__WU", |
---|
| 113 | "_X__", |
---|
| 114 | "_X_U", |
---|
| 115 | "_XW_", |
---|
| 116 | "_XWU", |
---|
| 117 | "C___", |
---|
| 118 | "C__U", |
---|
| 119 | "C_W_", |
---|
| 120 | "C_WU", |
---|
| 121 | "CX__", |
---|
| 122 | "CX_U", |
---|
| 123 | "CXW_", |
---|
| 124 | "CXWU", |
---|
| 125 | }; |
---|
| 126 | |
---|
| 127 | unsigned int vspace_id; |
---|
| 128 | unsigned int cluster_id; |
---|
| 129 | unsigned int pseg_id; |
---|
| 130 | unsigned int vseg_id; |
---|
| 131 | unsigned int task_id; |
---|
| 132 | unsigned int proc_id; |
---|
| 133 | unsigned int irq_id; |
---|
| 134 | unsigned int periph_id; |
---|
| 135 | |
---|
| 136 | mapping_cluster_t * cluster; |
---|
| 137 | mapping_pseg_t * pseg; |
---|
| 138 | mapping_vspace_t * vspace; |
---|
| 139 | mapping_vseg_t * vseg; |
---|
| 140 | mapping_task_t * task; |
---|
| 141 | mapping_proc_t * proc; |
---|
| 142 | mapping_irq_t * irq; |
---|
| 143 | mapping_periph_t * periph; |
---|
| 144 | |
---|
| 145 | // computes the base adresss for clusters array, |
---|
| 146 | cluster = (mapping_cluster_t *)((char *) header + |
---|
| 147 | MAPPING_HEADER_SIZE); |
---|
| 148 | |
---|
| 149 | // computes the base adresss for psegs array, |
---|
| 150 | pseg = (mapping_pseg_t *) ((char *) header + |
---|
| 151 | MAPPING_HEADER_SIZE + |
---|
[263] | 152 | MAPPING_CLUSTER_SIZE * header->x_size * header->y_size); |
---|
[258] | 153 | |
---|
| 154 | // computes the base adresss for vspaces array, |
---|
| 155 | vspace = (mapping_vspace_t *) ((char *) header + |
---|
| 156 | MAPPING_HEADER_SIZE + |
---|
[263] | 157 | MAPPING_CLUSTER_SIZE * header->x_size * header->y_size + |
---|
[258] | 158 | MAPPING_PSEG_SIZE * header->psegs); |
---|
| 159 | |
---|
| 160 | // computes the base adresss for vsegs array, |
---|
| 161 | vseg = (mapping_vseg_t *) ((char *) header + |
---|
| 162 | MAPPING_HEADER_SIZE + |
---|
[263] | 163 | MAPPING_CLUSTER_SIZE * header->x_size * header->y_size + |
---|
[258] | 164 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 165 | MAPPING_VSPACE_SIZE * header->vspaces); |
---|
| 166 | |
---|
| 167 | // computes the base address for tasks array |
---|
| 168 | task = (mapping_task_t *) ((char *) header + |
---|
| 169 | MAPPING_HEADER_SIZE + |
---|
[263] | 170 | MAPPING_CLUSTER_SIZE * header->x_size * header->y_size + |
---|
[258] | 171 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 172 | MAPPING_VSPACE_SIZE * header->vspaces + |
---|
| 173 | MAPPING_VSEG_SIZE * header->vsegs); |
---|
| 174 | |
---|
| 175 | // computes the base address for procs array |
---|
| 176 | proc = (mapping_proc_t *) ((char *) header + |
---|
| 177 | MAPPING_HEADER_SIZE + |
---|
[263] | 178 | MAPPING_CLUSTER_SIZE * header->x_size * header->y_size + |
---|
[258] | 179 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 180 | MAPPING_VSPACE_SIZE * header->vspaces + |
---|
| 181 | MAPPING_VSEG_SIZE * header->vsegs + |
---|
| 182 | MAPPING_TASK_SIZE * header->tasks); |
---|
| 183 | |
---|
| 184 | // computes the base address for irqs array |
---|
| 185 | irq = (mapping_irq_t *) ((char *) header + |
---|
| 186 | MAPPING_HEADER_SIZE + |
---|
[263] | 187 | MAPPING_CLUSTER_SIZE * header->x_size * header->y_size + |
---|
[258] | 188 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 189 | MAPPING_VSPACE_SIZE * header->vspaces + |
---|
| 190 | MAPPING_VSEG_SIZE * header->vsegs + |
---|
| 191 | MAPPING_TASK_SIZE * header->tasks + |
---|
| 192 | MAPPING_PROC_SIZE * header->procs); |
---|
| 193 | |
---|
| 194 | // computes the base address for periphs array |
---|
| 195 | periph = (mapping_periph_t *) ((char *) header + |
---|
| 196 | MAPPING_HEADER_SIZE + |
---|
[263] | 197 | MAPPING_CLUSTER_SIZE * header->x_size * header->y_size + |
---|
[258] | 198 | MAPPING_PSEG_SIZE * header->psegs + |
---|
| 199 | MAPPING_VSPACE_SIZE * header->vspaces + |
---|
| 200 | MAPPING_VSEG_SIZE * header->vsegs + |
---|
| 201 | MAPPING_TASK_SIZE * header->tasks + |
---|
| 202 | MAPPING_PROC_SIZE * header->procs + |
---|
[522] | 203 | MAPPING_IRQ_SIZE * header->irqs); |
---|
[258] | 204 | |
---|
| 205 | ///////////////////////// header ///////////////////////////////////////////// |
---|
| 206 | |
---|
| 207 | fprintf(fpout, "<?xml version = \"1.0\"?>\n\n"); |
---|
| 208 | |
---|
[287] | 209 | fprintf(fpout, "<mapping_info signature = \"0x%x\" \n" , header->signature); |
---|
| 210 | fprintf(fpout, " name = \"%s\" \n" , header->name); |
---|
| 211 | fprintf(fpout, " x_size = \"%d\" \n" , header->x_size); |
---|
| 212 | fprintf(fpout, " y_size = \"%d\" \n" , header->y_size); |
---|
| 213 | fprintf(fpout, " x_width = \"%d\" \n" , header->x_width); |
---|
| 214 | fprintf(fpout, " y_width = \"%d\" \n" , header->y_width); |
---|
[295] | 215 | fprintf(fpout, " irq_per_proc = \"%d\" \n" , header->irq_per_proc); |
---|
[306] | 216 | fprintf(fpout, " use_ram_disk = \"%d\" \n" , header->use_ram_disk); |
---|
[295] | 217 | fprintf(fpout, " x_io = \"%d\" \n" , header->x_io); |
---|
| 218 | fprintf(fpout, " y_io = \"%d\" >\n\n", header->y_io); |
---|
[258] | 219 | |
---|
| 220 | ///////////////////// clusters /////////////////////////////////////////////// |
---|
| 221 | |
---|
| 222 | fprintf( fpout, " <clusterset>\n"); |
---|
[263] | 223 | for (cluster_id = 0; cluster_id < (header->x_size * header->y_size); cluster_id++) |
---|
[258] | 224 | { |
---|
[306] | 225 | fprintf(fpout, " <cluster x=\"%d\" y=\"%d\" >\n", |
---|
[263] | 226 | cluster[cluster_id].x, cluster[cluster_id].y ); |
---|
| 227 | |
---|
| 228 | ///////////////////// psegs //////////////////////////////////////////////// |
---|
| 229 | |
---|
[258] | 230 | for (pseg_id = cluster[cluster_id].pseg_offset; |
---|
| 231 | pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs; |
---|
| 232 | pseg_id++) |
---|
| 233 | { |
---|
[306] | 234 | fprintf(fpout, " <pseg name=\"%s\"", pseg[pseg_id].name); |
---|
| 235 | fprintf(fpout, " type=\"%s\"", pseg_type[pseg[pseg_id].type]); |
---|
| 236 | fprintf(fpout, " base=\"0x%llx\"", pseg[pseg_id].base); |
---|
| 237 | fprintf(fpout, " length=\"0x%llx\" />\n", pseg[pseg_id].length); |
---|
[258] | 238 | } |
---|
| 239 | |
---|
| 240 | ///////////////////// processors ///////////////////////////////////////////// |
---|
| 241 | |
---|
| 242 | unsigned int proc_index = 0; |
---|
| 243 | for (proc_id = cluster[cluster_id].proc_offset; |
---|
| 244 | proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs; |
---|
[295] | 245 | proc_id++, proc_index++) |
---|
[258] | 246 | { |
---|
[306] | 247 | fprintf(fpout, " <proc index=\"%d\" />\n", proc_index); |
---|
[258] | 248 | } |
---|
| 249 | |
---|
| 250 | ///////////////////// periphs /////////////////////////////////////////////// |
---|
| 251 | |
---|
| 252 | for (periph_id = cluster[cluster_id].periph_offset; |
---|
| 253 | periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs; |
---|
| 254 | periph_id++) |
---|
| 255 | { |
---|
[306] | 256 | fprintf(fpout, " <periph type=\"%s\"", periph_type[periph[periph_id].type]); |
---|
[289] | 257 | |
---|
[306] | 258 | if (periph[periph_id].type == PERIPH_TYPE_IOC) |
---|
| 259 | fprintf(fpout, " subtype=\"%s\"", ioc_subtype[periph[periph_id].subtype]); |
---|
[289] | 260 | |
---|
[522] | 261 | if (periph[periph_id].type == PERIPH_TYPE_MWR) |
---|
| 262 | fprintf(fpout, " subtype=\"%s\"", mwr_subtype[periph[periph_id].subtype]); |
---|
| 263 | |
---|
[306] | 264 | fprintf(fpout, " psegname=\"%s\"", pseg[periph[periph_id].psegid].name); |
---|
[323] | 265 | fprintf(fpout, " channels=\"%d\"", periph[periph_id].channels); |
---|
[522] | 266 | fprintf(fpout, " arg0=\"%d\" >\n", periph[periph_id].arg0); |
---|
| 267 | fprintf(fpout, " arg1=\"%d\" >\n", periph[periph_id].arg1); |
---|
| 268 | fprintf(fpout, " arg2=\"%d\" >\n", periph[periph_id].arg2); |
---|
| 269 | fprintf(fpout, " arg3=\"%d\" >\n", periph[periph_id].arg3); |
---|
[323] | 270 | if ( (periph[periph_id].type == PERIPH_TYPE_PIC) || |
---|
[439] | 271 | (periph[periph_id].type == PERIPH_TYPE_XCU) ) |
---|
[295] | 272 | { |
---|
[306] | 273 | for (irq_id = periph[periph_id].irq_offset; |
---|
| 274 | irq_id < periph[periph_id].irq_offset + periph[periph_id].irqs; |
---|
| 275 | irq_id++) |
---|
| 276 | { |
---|
| 277 | fprintf(fpout, " <irq srctype=\"%s\"", irq_type[irq[irq_id].srctype]); |
---|
| 278 | fprintf(fpout, " srcid=\"%d\"", irq[irq_id].srcid); |
---|
| 279 | fprintf(fpout, " isr=\"%s\"", isr_type[irq[irq_id].isr]); |
---|
[323] | 280 | fprintf(fpout, " channel=\"%d\" />\n", irq[irq_id].channel); |
---|
[306] | 281 | } |
---|
| 282 | } |
---|
[295] | 283 | fprintf(fpout, " </periph>\n"); |
---|
[258] | 284 | } |
---|
| 285 | fprintf(fpout, " </cluster>\n" ); |
---|
| 286 | } |
---|
| 287 | fprintf(fpout, " </clusterset>\n\n" ); |
---|
| 288 | |
---|
| 289 | /////////////////// globals ///////////////////////////////////////////////// |
---|
| 290 | |
---|
| 291 | fprintf(fpout, " <globalset>\n" ); |
---|
| 292 | for (vseg_id = 0; vseg_id < header->globals; vseg_id++) |
---|
| 293 | { |
---|
[306] | 294 | unsigned int pseg_id = vseg[vseg_id].psegid; |
---|
| 295 | unsigned int cluster_id = pseg[pseg_id].clusterid; |
---|
[258] | 296 | |
---|
[306] | 297 | fprintf(fpout, " <vseg name=\"%s\"", vseg[vseg_id].name); |
---|
| 298 | fprintf(fpout, " vbase=\"0x%x\"", vseg[vseg_id].vbase); |
---|
[511] | 299 | fprintf(fpout, " length=\"0x%x\"", vseg[vseg_id].length); |
---|
| 300 | fprintf(fpout, " type=\"%s\"", vseg_type[vseg[vseg_id].type]); |
---|
[306] | 301 | fprintf(fpout, " mode=\"%s\"", mode_str[vseg[vseg_id].mode]); |
---|
[511] | 302 | fprintf(fpout, "\n "); |
---|
[306] | 303 | fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x); |
---|
| 304 | fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y); |
---|
| 305 | fprintf(fpout, " psegname=\"%s\"", pseg[pseg_id].name); |
---|
[511] | 306 | if( vseg[vseg_id].ident ) |
---|
| 307 | fprintf(fpout, " ident=\"1\""); |
---|
| 308 | if( vseg[vseg_id].local ) |
---|
| 309 | fprintf(fpout, " local=\"1\""); |
---|
| 310 | if( vseg[vseg_id].big ) |
---|
| 311 | fprintf(fpout, " big=\"1\""); |
---|
| 312 | if( vseg[vseg_id].binpath[0] != 0 ) |
---|
| 313 | fprintf(fpout, " binpath=\"%s\"", vseg[vseg_id].binpath); |
---|
[306] | 314 | fprintf(fpout, " >\n"); |
---|
[258] | 315 | } |
---|
| 316 | fprintf(fpout, " </globalset>\n" ); |
---|
| 317 | |
---|
| 318 | //////////////////// vspaces //////////////////////////////////////////////// |
---|
| 319 | |
---|
| 320 | fprintf( fpout, "\n <vspaceset>\n\n" ); |
---|
| 321 | for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) |
---|
| 322 | { |
---|
[511] | 323 | unsigned int vseg_id = vspace[vspace_id].start_vseg_id; |
---|
[258] | 324 | fprintf(fpout, " <vspace name = \"%s\" ", vspace[vspace_id].name); |
---|
[511] | 325 | fprintf(fpout, " startname = \"%s\" >\n", vseg[vseg_id].name); |
---|
[258] | 326 | |
---|
[263] | 327 | //////////////////// vsegs ////////////////////////////////////////////// |
---|
| 328 | |
---|
[258] | 329 | for (vseg_id = vspace[vspace_id].vseg_offset; |
---|
| 330 | vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); |
---|
| 331 | vseg_id++) |
---|
| 332 | { |
---|
[263] | 333 | unsigned int pseg_id = vseg[vseg_id].psegid; |
---|
| 334 | unsigned int cluster_id = pseg[pseg_id].clusterid; |
---|
[258] | 335 | |
---|
[306] | 336 | fprintf(fpout, " <vseg name=\"%s\"", vseg[vseg_id].name); |
---|
| 337 | fprintf(fpout, " vbase=\"0x%x\"", vseg[vseg_id].vbase); |
---|
[511] | 338 | fprintf(fpout, " length=\"0x%x\"", vseg[vseg_id].length); |
---|
| 339 | fprintf(fpout, " type=\"%s\"", vseg_type[vseg[vseg_id].type]); |
---|
[306] | 340 | fprintf(fpout, " mode=\"%s\"", mode_str[vseg[vseg_id].mode]); |
---|
[511] | 341 | fprintf(fpout, "\n "); |
---|
[306] | 342 | fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x); |
---|
| 343 | fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y); |
---|
| 344 | fprintf(fpout, " psegname=\"%s\"", pseg[pseg_id].name); |
---|
[511] | 345 | if( vseg[vseg_id].ident ) |
---|
| 346 | fprintf(fpout, " ident=\"1\""); |
---|
| 347 | if( vseg[vseg_id].local ) |
---|
| 348 | fprintf(fpout, " local=\"1\""); |
---|
| 349 | if( vseg[vseg_id].big ) |
---|
| 350 | fprintf(fpout, " big=\"1\""); |
---|
| 351 | if( vseg[vseg_id].binpath[0] != 0 ) |
---|
| 352 | fprintf(fpout, " binpath=\"%s\"", vseg[vseg_id].binpath); |
---|
[306] | 353 | fprintf(fpout, " >\n"); |
---|
[258] | 354 | } |
---|
[263] | 355 | |
---|
| 356 | //////////////////// tasks ////////////////////////////////////////////// |
---|
| 357 | |
---|
[258] | 358 | for (task_id = vspace[vspace_id].task_offset; |
---|
| 359 | task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks); |
---|
| 360 | task_id++) |
---|
| 361 | { |
---|
[511] | 362 | unsigned int stack_vseg_id = task[task_id].stack_vseg_id; |
---|
| 363 | unsigned int heap_vseg_id = task[task_id].heap_vseg_id; |
---|
[323] | 364 | unsigned int cluster_id = task[task_id].clusterid; |
---|
[258] | 365 | |
---|
[306] | 366 | fprintf(fpout, " <task name=\"%s\"", task[task_id].name); |
---|
| 367 | fprintf(fpout, " trdid=\"%d\"", task[task_id].trdid); |
---|
| 368 | fprintf(fpout, " x=\"%d\"", cluster[cluster_id].x); |
---|
| 369 | fprintf(fpout, " y=\"%d\"", cluster[cluster_id].y); |
---|
| 370 | fprintf(fpout, " p=\"%d\"", task[task_id].proclocid); |
---|
[511] | 371 | fprintf(fpout, "\n "); |
---|
| 372 | fprintf(fpout, " stackname=\"%s\"", vseg[stack_vseg_id].name); |
---|
| 373 | if (heap_vseg_id != -1) |
---|
| 374 | fprintf(fpout, " heapname=\"%s\"", vseg[heap_vseg_id].name); |
---|
[306] | 375 | fprintf(fpout, " startid = \"%d\"", task[task_id].startid); |
---|
| 376 | fprintf(fpout, " />\n"); |
---|
[258] | 377 | } |
---|
| 378 | fprintf(fpout, " </vspace>\n\n"); |
---|
| 379 | } |
---|
| 380 | fprintf(fpout, " </vspaceset>\n"); |
---|
| 381 | fprintf(fpout, "</mapping_info>\n"); |
---|
| 382 | } // end buildXml() |
---|
| 383 | |
---|
| 384 | |
---|
| 385 | ///////////////////////////////////// |
---|
[306] | 386 | int main(int argc, char * argv[]) |
---|
| 387 | { |
---|
| 388 | if (argc < 2) |
---|
| 389 | { |
---|
[258] | 390 | printf("Usage: bin2xml <input_file_path> <output_file_path>\n"); |
---|
| 391 | return 1; |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | unsigned int bin[0x10000]; // 64 K int = 256 Kbytes |
---|
| 395 | |
---|
| 396 | int fdin = open(argv[1], O_RDONLY); |
---|
[306] | 397 | if (fdin < 0) |
---|
| 398 | { |
---|
[258] | 399 | perror("open"); |
---|
| 400 | exit(1); |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | FILE * fpout = fopen( argv[2], "w"); |
---|
[306] | 404 | if (fpout == NULL) |
---|
| 405 | { |
---|
[258] | 406 | perror("open"); |
---|
| 407 | exit(1); |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | unsigned int length = read(fdin, bin, 0x40000); |
---|
| 411 | |
---|
[306] | 412 | if (length <= 0) |
---|
| 413 | { |
---|
[258] | 414 | perror("read"); |
---|
| 415 | exit(1); |
---|
| 416 | } |
---|
| 417 | |
---|
[306] | 418 | if (bin[0] == IN_MAPPING_SIGNATURE) |
---|
| 419 | { |
---|
[258] | 420 | buildXml((mapping_header_t *) bin, fpout); |
---|
| 421 | } |
---|
[306] | 422 | else |
---|
| 423 | { |
---|
[258] | 424 | printf("[ERROR] Wrong file format\n"); |
---|
| 425 | exit(1); |
---|
| 426 | } |
---|
| 427 | return 0; |
---|
| 428 | } // end main() |
---|
| 429 | |
---|
| 430 | |
---|
| 431 | |
---|
| 432 | // Local Variables: |
---|
| 433 | // tab-width: 4 |
---|
| 434 | // c-basic-offset: 4 |
---|
| 435 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 436 | // indent-tabs-mode: nil |
---|
| 437 | // End: |
---|
| 438 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 439 | |
---|