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