diff --git a/src/apps/bootman/MakeArray.cpp b/src/apps/bootman/MakeArray.cpp new file mode 100644 index 0000000000..139e30a7e3 --- /dev/null +++ b/src/apps/bootman/MakeArray.cpp @@ -0,0 +1,48 @@ +#include +#include +#include + +int main(int argc, char* argv[]) +{ + const char* application = argv[0]; + if (argc != 3) { + fprintf(stderr, "Usage:\n%s ", application); + return 1; + } + const char* variableName = argv[1]; + const char* fileName = argv[2]; + + int fd = open(fileName, 0); + if (fd < 0) { + fprintf(stderr, "%s: Error opening file '%s'!\n", application, fileName); + return 1; + } + + const int kSize = 1024; + unsigned char buffer[kSize]; + int size = read(fd, buffer, kSize); + const int COLUMNS = 16; + int column = COLUMNS - 1; + bool first = true; + printf("// THIS FILE WAS GENERATED WITH\n"); + printf("// %s %s %s\n\n", application, variableName, fileName); + printf("static const uint8 %s[] = {", variableName); + while (size > 0) { + for (int i = 0; i < size; i ++) { + if (first) + first = false; + else + printf(", "); + column ++; + if (column == COLUMNS) { + printf("\n\t"); + column = 0; + } + printf("0x%2.2x", (int)buffer[i]); + } + size = read(fd, buffer, kSize); + } + printf("\n};\n"); + + close(fd); +} \ No newline at end of file