| 1 | /* |
| 2 | * Copyright 2010-2017 Intel Corporation. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License, version 2, |
| 6 | * as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * General Public License for more details. |
| 12 | * |
| 13 | * Disclaimer: The codes contained in these modules may be specific to |
| 14 | * the Intel Software Development Platform codenamed Knights Ferry, |
| 15 | * and the Intel product codenamed Knights Corner, and are not backward |
| 16 | * compatible with other Intel products. Additionally, Intel will NOT |
| 17 | * support the codes or instruction set in future products. |
| 18 | * |
| 19 | * Intel offers no warranty of any kind regarding the code. This code is |
| 20 | * licensed on an "AS IS" basis and Intel is not obligated to provide |
| 21 | * any support, assistance, installation, training, or other services |
| 22 | * of any kind. Intel is also not obligated to provide any updates, |
| 23 | * enhancements or extensions. Intel specifically disclaims any warranty |
| 24 | * of merchantability, non-infringement, fitness for any particular |
| 25 | * purpose, and any other warranty. |
| 26 | * |
| 27 | * Further, Intel disclaims all liability of any kind, including but |
| 28 | * not limited to liability for infringement of any proprietary rights, |
| 29 | * relating to the use of the code, even if Intel is notified of the |
| 30 | * possibility of such liability. Except as expressly stated in an Intel |
| 31 | * license agreement provided with this code and agreed upon with Intel, |
| 32 | * no license, express or implied, by estoppel or otherwise, to any |
| 33 | * intellectual property rights is granted herein. |
| 34 | */ |
| 35 | |
| 36 | #include <stdio.h> |
| 37 | #include <stdlib.h> |
| 38 | #include <stdint.h> |
| 39 | #include <unistd.h> |
| 40 | #include <fcntl.h> |
| 41 | #include <sys/ioctl.h> |
| 42 | #include "../include/scif.h" |
| 43 | |
| 44 | // Use 2MB for KNF and 4MB for KNC. |
| 45 | #define MICTC_XML_BUFFER_SIZE (2 * 1024 * 1024) |
| 46 | |
| 47 | // Memory transfer window. 1GB |
| 48 | #define MICTC_MEM_BUFFER_SIZE (1 * 1024UL * 1024UL * 1024UL) |
| 49 | |
| 50 | FILE *ip; |
| 51 | FILE *op; |
| 52 | |
| 53 | |
| 54 | int main(void) |
| 55 | { |
| 56 | long srcPhysAddr = 0; |
| 57 | uint32_t page_buf[4096/4]; |
| 58 | long i = 0; |
| 59 | int size; |
| 60 | char dest[64]; |
| 61 | |
| 62 | if ((ip = fopen("mem.dat", "r")) == NULL) { |
| 63 | fprintf(stderr, "Cannot open file mem.dat.\n"); |
| 64 | } |
| 65 | |
| 66 | if ((op = fopen("memfmt.txt", "w")) == NULL) { |
| 67 | fprintf(stderr, "Cannot open file memfmt.txt.\n"); |
| 68 | } |
| 69 | |
| 70 | while (! feof(ip)) { |
| 71 | fread(page_buf, sizeof(page_buf), 1, ip); // check for error |
| 72 | |
| 73 | size = sprintf(dest, "origin %lx\n", srcPhysAddr); |
| 74 | fwrite(dest, size, 1, op); |
| 75 | |
| 76 | for (i = 0; i < 4096/4; i++) { |
| 77 | size = sprintf(dest, "%x\n", page_buf[i]); |
| 78 | fwrite(dest, size, 1, op); |
| 79 | } |
| 80 | |
| 81 | srcPhysAddr += 4096; |
| 82 | } |
| 83 | fclose(ip); |
| 84 | fclose(op); |
| 85 | } |