1 /*
2 * Copyright © 2023 Collabora Ltd. and Red Hat Inc.
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include <inttypes.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11 #include "mme_fermi.h"
12 #include "mme_tu104.h"
13
14
main(int argc,char ** argv)15 int main(int argc, char **argv) {
16 const char *arch_name;
17 const char *file_name;
18 FILE *file;
19 long file_size;
20 uint32_t *data;
21
22 if (argc != 3) {
23 fprintf(stderr, "Usage: nv_mme_dump file.bin "
24 "<FERMI|TURING>\n");
25 return 1;
26 }
27
28 file_name = argv[1];
29 arch_name = argv[2];
30
31 file = fopen(file_name, "r");
32
33 if (file == NULL) {
34 fprintf(stderr, "couldn't open file \"%s\"\n", file_name);
35 return 1;
36 }
37
38 fseek(file, 0L, SEEK_END);
39 file_size = ftell(file);
40 fseek(file, 0L, SEEK_SET);
41
42 if (file_size % 4 != 0) {
43 fclose(file);
44
45 fprintf(stderr, "invalid file, data isn't aligned to 4 bytes\n");
46 return 1;
47 }
48
49 data = malloc(file_size);
50
51 if (data == NULL) {
52 fclose(file);
53
54 fprintf(stderr, "memory allocation failed\n");
55 return 1;
56 }
57
58 fread(data, file_size, 1, file);
59 fclose(file);
60
61 if (!strcmp(arch_name, "FERMI")) {
62 mme_fermi_dump(stdout, data, file_size);
63 } else {
64 mme_tu104_dump(stdout, data, file_size);
65 }
66
67 free(data);
68
69 return 0;
70 }