-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for embedding images in unix executables. See deploy/packagin…
…g/README.unix for instructions.
- Loading branch information
1 parent
cc08215
commit be70093
Showing
4 changed files
with
195 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
The Unix VMs can be packaged to embed the image file in the executable. In this | ||
configuration a VM executable will only accept the image it includes and cannot | ||
be used to load other images. An embedded image is added to a VM executable using | ||
the genUnixImageResource.c program in this directory, hacking a VM build makefile, | ||
and then building the VM. | ||
|
||
First compile genUnixImageResource.c, e.g. | ||
|
||
cc -o genUnixImageResource -O3 genUnixImageResource.c | ||
|
||
then use it and the C compiler to generate an image.o file, e.g. | ||
|
||
./genUnixImageResource myimagefile.image | gcc -c -o image.o -pipe -x c - | ||
|
||
Note that in the above we use the -pipe option to avoid creating temporary files | ||
as these are huge. The output of genUnixImageResource is five times larger than | ||
the image file, and the assembler file generated may be even larger. Even using | ||
pipes creating an image.o file from a 48Mb image file on a Raspberry Pi 4 takes | ||
nearly 9 minutes. | ||
|
||
Copy/link the image.o file to a VM build directory, e.g. into | ||
building/linux64ARMv8/squeak.cog.spur/build. Edit the line that defines SQLIBS | ||
to either include image.o or a variable you can define on the make line: | ||
|
||
SQLIBS = vm/vm$a $(EIO) ... | ||
|
||
Then remove any existing squeak executable and make: | ||
|
||
$ rm -f ./squeak; make EIO=image.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Take as input an image file. Produce as output a C file defining | ||
// a byte array called embeddedImage which contains the contents of | ||
// the image file, and a string called embeddedImageName containing | ||
// the base name of the image. | ||
|
||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#define NITEMS (80/5) | ||
int | ||
main(int argc, char *argv[]) | ||
{ | ||
FILE *ifh, *ofh; | ||
unsigned char data[NITEMS]; | ||
char *basename, *dot; | ||
size_t n; | ||
|
||
if (argc == 2 || argc == 3) { | ||
if (!(ifh = fopen(argv[1], "rb"))) { | ||
perror("fopen"); | ||
return 1; | ||
} | ||
if (argc == 3) { | ||
if (!(ofh = fopen(argv[2], "w"))) { | ||
perror("fopen"); | ||
return 2; | ||
} | ||
} | ||
else | ||
ofh = stdout; | ||
} | ||
else { | ||
printf("usage: %s file.image [output file]\n", argv[0]); | ||
exit(2); | ||
} | ||
if ((basename = strrchr(argv[1],'/'))) | ||
basename = basename + 1; | ||
else | ||
basename = argv[1]; | ||
if (!(dot = strrchr(basename,'.'))) | ||
dot = basename + strlen(basename) - 1; | ||
fprintf(ofh, | ||
"char embeddedImageName[] = \"%.*s\";\n", | ||
dot - basename, basename); | ||
fseek(ifh,0,SEEK_END); | ||
fprintf(ofh,"unsigned long embeddedImageSize = %ld;\n",ftell(ifh)); | ||
fseek(ifh,0,SEEK_SET); | ||
fprintf(ofh, "unsigned char embeddedImage[] = {\n"); | ||
while ((n = fread(data,sizeof(unsigned char),NITEMS,ifh)) > 0) { | ||
unsigned char lastchar = feof(ifh) ? '\n' : ','; | ||
for (int i = 0; i < n; i++) | ||
fprintf(ofh,"0x%02x%c", data[i], i < (n - 1) ? ',' : (feof(ifh) ? '\n' : ',')); | ||
if (!feof(ifh)) | ||
fprintf(ofh,"\n"); | ||
} | ||
fprintf(ofh,"};\n"); | ||
(void)fclose(ifh); | ||
(void)fclose(ofh); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters