| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
#include "acpixtract.h" |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
int |
| 64 |
AxExtractTables ( |
| 65 |
char *InputPathname, |
| 66 |
char *Signature, |
| 67 |
unsigned int MinimumInstances) |
| 68 |
{ |
| 69 |
FILE *InputFile; |
| 70 |
FILE *OutputFile = NULL; |
| 71 |
int BytesConverted; |
| 72 |
int ThisTableBytesWritten = 0; |
| 73 |
unsigned int FoundTable = 0; |
| 74 |
unsigned int Instances = 0; |
| 75 |
unsigned int ThisInstance; |
| 76 |
char ThisSignature[5]; |
| 77 |
char UpperSignature[5]; |
| 78 |
int Status = 0; |
| 79 |
unsigned int State = AX_STATE_FIND_HEADER; |
| 80 |
|
| 81 |
memset (UpperSignature, 0, sizeof(UpperSignature)); |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
InputFile = fopen (InputPathname, "r"); |
| 86 |
if (!InputFile) |
| 87 |
{ |
| 88 |
printf ("Could not open input file %s\n", InputPathname); |
| 89 |
return (-1); |
| 90 |
} |
| 91 |
|
| 92 |
if (!AxIsFileAscii (InputFile)) |
| 93 |
{ |
| 94 |
fclose (InputFile); |
| 95 |
return (-1); |
| 96 |
} |
| 97 |
|
| 98 |
if (Signature) |
| 99 |
{ |
| 100 |
memcpy (UpperSignature, Signature, ACPI_NAMESEG_SIZE); |
| 101 |
AcpiUtStrupr (UpperSignature); |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
AxNormalizeSignature (UpperSignature); |
| 106 |
Instances = AxCountTableInstances (InputPathname, UpperSignature); |
| 107 |
|
| 108 |
if (Instances < MinimumInstances || |
| 109 |
(Instances == 0 && MinimumInstances == AX_OPTIONAL_TABLES)) |
| 110 |
{ |
| 111 |
printf ("Table [%s] was not found in %s\n", |
| 112 |
UpperSignature, InputPathname); |
| 113 |
fclose (InputFile); |
| 114 |
return (0); |
| 115 |
} |
| 116 |
|
| 117 |
if (Instances == 0) |
| 118 |
{ |
| 119 |
fclose (InputFile); |
| 120 |
return (-1); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile)) |
| 127 |
{ |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
if (AX_IS_TABLE_BLOCK_HEADER && |
| 133 |
(State == AX_STATE_EXTRACT_DATA)) |
| 134 |
{ |
| 135 |
|
| 136 |
|
| 137 |
if (ThisTableBytesWritten) |
| 138 |
{ |
| 139 |
printf (AX_TABLE_INFO_FORMAT, ThisSignature, ThisTableBytesWritten, |
| 140 |
ThisTableBytesWritten, Gbl_OutputFilename); |
| 141 |
} |
| 142 |
else |
| 143 |
{ |
| 144 |
Gbl_TableCount--; |
| 145 |
} |
| 146 |
|
| 147 |
State = AX_STATE_FIND_HEADER; |
| 148 |
} |
| 149 |
|
| 150 |
switch (State) |
| 151 |
{ |
| 152 |
case AX_STATE_FIND_HEADER: |
| 153 |
|
| 154 |
if (!AxIsDataBlockHeader ()) |
| 155 |
{ |
| 156 |
continue; |
| 157 |
} |
| 158 |
|
| 159 |
ACPI_COPY_NAMESEG (ThisSignature, Gbl_LineBuffer); |
| 160 |
if (Signature) |
| 161 |
{ |
| 162 |
|
| 163 |
|
| 164 |
if (!ACPI_COMPARE_NAMESEG (ThisSignature, UpperSignature)) |
| 165 |
{ |
| 166 |
continue; |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
ThisInstance = AxGetNextInstance (InputPathname, ThisSignature); |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
if (ThisInstance > 0) |
| 179 |
{ |
| 180 |
|
| 181 |
|
| 182 |
sprintf (Gbl_OutputFilename, "%4.4s%u.dat", |
| 183 |
ThisSignature, ThisInstance); |
| 184 |
} |
| 185 |
else |
| 186 |
{ |
| 187 |
sprintf (Gbl_OutputFilename, "%4.4s.dat", |
| 188 |
ThisSignature); |
| 189 |
} |
| 190 |
|
| 191 |
AcpiUtStrlwr (Gbl_OutputFilename); |
| 192 |
OutputFile = fopen (Gbl_OutputFilename, "w+b"); |
| 193 |
if (!OutputFile) |
| 194 |
{ |
| 195 |
printf ("Could not open output file %s\n", |
| 196 |
Gbl_OutputFilename); |
| 197 |
fclose (InputFile); |
| 198 |
return (-1); |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
Gbl_TableCount++; |
| 206 |
FoundTable = 1; |
| 207 |
ThisTableBytesWritten = 0; |
| 208 |
State = AX_STATE_EXTRACT_DATA; |
| 209 |
continue; |
| 210 |
|
| 211 |
case AX_STATE_EXTRACT_DATA: |
| 212 |
|
| 213 |
if (!AxIsHexDataLine ()) |
| 214 |
{ |
| 215 |
continue; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
BytesConverted = AxConvertAndWrite (OutputFile, ThisSignature); |
| 221 |
switch (BytesConverted) |
| 222 |
{ |
| 223 |
case 0: |
| 224 |
|
| 225 |
State = AX_STATE_FIND_HEADER; |
| 226 |
continue; |
| 227 |
|
| 228 |
case -1: |
| 229 |
|
| 230 |
Status = -1; |
| 231 |
goto CleanupAndExit; |
| 232 |
|
| 233 |
default: |
| 234 |
|
| 235 |
ThisTableBytesWritten += BytesConverted; |
| 236 |
continue; |
| 237 |
} |
| 238 |
|
| 239 |
default: |
| 240 |
|
| 241 |
Status = -1; |
| 242 |
goto CleanupAndExit; |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
if (!FoundTable) |
| 247 |
{ |
| 248 |
printf ("No ACPI tables were found in %s\n", InputPathname); |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
CleanupAndExit: |
| 253 |
|
| 254 |
if (State == AX_STATE_EXTRACT_DATA) |
| 255 |
{ |
| 256 |
|
| 257 |
|
| 258 |
printf (AX_TABLE_INFO_FORMAT, ThisSignature, ThisTableBytesWritten, |
| 259 |
ThisTableBytesWritten, Gbl_OutputFilename); |
| 260 |
} |
| 261 |
|
| 262 |
if (OutputFile) |
| 263 |
{ |
| 264 |
fclose (OutputFile); |
| 265 |
} |
| 266 |
|
| 267 |
fclose (InputFile); |
| 268 |
return (Status); |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
int |
| 288 |
AxExtractToMultiAmlFile ( |
| 289 |
char *InputPathname) |
| 290 |
{ |
| 291 |
FILE *InputFile; |
| 292 |
FILE *OutputFile; |
| 293 |
int Status = 0; |
| 294 |
int TotalBytesWritten = 0; |
| 295 |
int ThisTableBytesWritten = 0; |
| 296 |
unsigned int BytesConverted; |
| 297 |
char ThisSignature[4]; |
| 298 |
unsigned int State = AX_STATE_FIND_HEADER; |
| 299 |
|
| 300 |
|
| 301 |
strcpy (Gbl_OutputFilename, AX_MULTI_TABLE_FILENAME); |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
InputFile = fopen (InputPathname, "r"); |
| 306 |
if (!InputFile) |
| 307 |
{ |
| 308 |
printf ("Could not open input file %s\n", InputPathname); |
| 309 |
return (-1); |
| 310 |
} |
| 311 |
|
| 312 |
if (!AxIsFileAscii (InputFile)) |
| 313 |
{ |
| 314 |
fclose (InputFile); |
| 315 |
return (-1); |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
OutputFile = fopen (Gbl_OutputFilename, "w+b"); |
| 321 |
if (!OutputFile) |
| 322 |
{ |
| 323 |
printf ("Could not open output file %s\n", Gbl_OutputFilename); |
| 324 |
fclose (InputFile); |
| 325 |
return (-1); |
| 326 |
} |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile)) |
| 331 |
{ |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
if (AX_IS_TABLE_BLOCK_HEADER && |
| 337 |
(State == AX_STATE_EXTRACT_DATA)) |
| 338 |
{ |
| 339 |
|
| 340 |
|
| 341 |
if (ThisTableBytesWritten) |
| 342 |
{ |
| 343 |
printf (AX_TABLE_INFO_FORMAT, ThisSignature, ThisTableBytesWritten, |
| 344 |
ThisTableBytesWritten, Gbl_OutputFilename); |
| 345 |
} |
| 346 |
else |
| 347 |
{ |
| 348 |
Gbl_TableCount--; |
| 349 |
} |
| 350 |
|
| 351 |
State = AX_STATE_FIND_HEADER; |
| 352 |
} |
| 353 |
|
| 354 |
switch (State) |
| 355 |
{ |
| 356 |
case AX_STATE_FIND_HEADER: |
| 357 |
|
| 358 |
if (!AxIsDataBlockHeader ()) |
| 359 |
{ |
| 360 |
continue; |
| 361 |
} |
| 362 |
|
| 363 |
ACPI_COPY_NAMESEG (ThisSignature, Gbl_LineBuffer); |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
if (!ACPI_COMPARE_NAMESEG (ThisSignature, ACPI_SIG_DSDT) && |
| 368 |
!ACPI_COMPARE_NAMESEG (ThisSignature, ACPI_SIG_SSDT)) |
| 369 |
{ |
| 370 |
continue; |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
Gbl_TableCount++; |
| 378 |
ThisTableBytesWritten = 0; |
| 379 |
State = AX_STATE_EXTRACT_DATA; |
| 380 |
continue; |
| 381 |
|
| 382 |
case AX_STATE_EXTRACT_DATA: |
| 383 |
|
| 384 |
if (!AxIsHexDataLine ()) |
| 385 |
{ |
| 386 |
continue; |
| 387 |
} |
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
BytesConverted = AxConvertAndWrite (OutputFile, ThisSignature); |
| 392 |
switch (BytesConverted) |
| 393 |
{ |
| 394 |
case 0: |
| 395 |
|
| 396 |
State = AX_STATE_FIND_HEADER; |
| 397 |
continue; |
| 398 |
|
| 399 |
case -1: |
| 400 |
|
| 401 |
Status = -1; |
| 402 |
goto CleanupAndExit; |
| 403 |
|
| 404 |
default: |
| 405 |
|
| 406 |
ThisTableBytesWritten += BytesConverted; |
| 407 |
TotalBytesWritten += BytesConverted; |
| 408 |
continue; |
| 409 |
} |
| 410 |
|
| 411 |
default: |
| 412 |
|
| 413 |
Status = -1; |
| 414 |
goto CleanupAndExit; |
| 415 |
} |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
CleanupAndExit: |
| 420 |
|
| 421 |
if (State == AX_STATE_EXTRACT_DATA) |
| 422 |
{ |
| 423 |
|
| 424 |
|
| 425 |
printf (AX_TABLE_INFO_FORMAT, ThisSignature, ThisTableBytesWritten, |
| 426 |
ThisTableBytesWritten, Gbl_OutputFilename); |
| 427 |
} |
| 428 |
|
| 429 |
printf ("\n%u binary ACPI tables extracted and written to %s (%u bytes)\n", |
| 430 |
Gbl_TableCount, Gbl_OutputFilename, TotalBytesWritten); |
| 431 |
|
| 432 |
fclose (InputFile); |
| 433 |
fclose (OutputFile); |
| 434 |
return (Status); |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
int |
| 452 |
AxListAllTables ( |
| 453 |
char *InputPathname) |
| 454 |
{ |
| 455 |
FILE *InputFile; |
| 456 |
unsigned char Header[48]; |
| 457 |
UINT32 ByteCount = 0; |
| 458 |
INT32 ThisLineByteCount; |
| 459 |
unsigned int State = AX_STATE_FIND_HEADER; |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
InputFile = fopen (InputPathname, "r"); |
| 465 |
if (!InputFile) |
| 466 |
{ |
| 467 |
printf ("Could not open input file %s\n", InputPathname); |
| 468 |
return (-1); |
| 469 |
} |
| 470 |
|
| 471 |
if (!AxIsFileAscii (InputFile)) |
| 472 |
{ |
| 473 |
fclose (InputFile); |
| 474 |
return (-1); |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
printf ("\n Signature Length Version Oem Oem " |
| 480 |
"Oem Compiler Compiler\n"); |
| 481 |
printf ( " Id TableId " |
| 482 |
"RevisionId Name Revision\n"); |
| 483 |
printf ( " _________ __________ ____ ________ __________ " |
| 484 |
"__________ _______ __________\n\n"); |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile)) |
| 489 |
{ |
| 490 |
|
| 491 |
|
| 492 |
if (AxIsEmptyLine (Gbl_LineBuffer)) |
| 493 |
{ |
| 494 |
continue; |
| 495 |
} |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
if (AX_IS_TABLE_BLOCK_HEADER && |
| 502 |
(State == AX_STATE_EXTRACT_DATA)) |
| 503 |
{ |
| 504 |
State = AX_STATE_FIND_HEADER; |
| 505 |
} |
| 506 |
|
| 507 |
switch (State) |
| 508 |
{ |
| 509 |
case AX_STATE_FIND_HEADER: |
| 510 |
|
| 511 |
ByteCount = 0; |
| 512 |
if (!AxIsDataBlockHeader ()) |
| 513 |
{ |
| 514 |
continue; |
| 515 |
} |
| 516 |
|
| 517 |
State = AX_STATE_EXTRACT_DATA; |
| 518 |
continue; |
| 519 |
|
| 520 |
case AX_STATE_EXTRACT_DATA: |
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
if (!AxIsHexDataLine ()) |
| 525 |
{ |
| 526 |
continue; |
| 527 |
} |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
ThisLineByteCount = AxConvertToBinary (Gbl_LineBuffer, |
| 532 |
&Header[ByteCount]); |
| 533 |
if (ThisLineByteCount == EOF) |
| 534 |
{ |
| 535 |
fclose (InputFile); |
| 536 |
return (-1); |
| 537 |
} |
| 538 |
|
| 539 |
ByteCount += ThisLineByteCount; |
| 540 |
if (ByteCount >= sizeof (ACPI_TABLE_HEADER)) |
| 541 |
{ |
| 542 |
AxDumpTableHeader (Header); |
| 543 |
State = AX_STATE_FIND_HEADER; |
| 544 |
} |
| 545 |
continue; |
| 546 |
|
| 547 |
default: |
| 548 |
break; |
| 549 |
} |
| 550 |
} |
| 551 |
|
| 552 |
printf ("\nFound %u ACPI tables in %s\n", Gbl_TableCount, InputPathname); |
| 553 |
fclose (InputFile); |
| 554 |
return (0); |
| 555 |
} |