diff options
author | Dave Hylands <dhylands@gmail.com> | 2014-01-08 01:00:22 -0800 |
---|---|---|
committer | Dave Hylands <dhylands@gmail.com> | 2014-01-11 16:16:20 -0800 |
commit | d80ee8bbfd52fd44f623aabbef4544f9572aca9e (patch) | |
tree | 6af7aed612e1e335b47f5e36c5c792c9bb537dda /teensy/memzip.c | |
parent | c698d266d1f13fe82a5ac291f7c6642da3dc0bdc (diff) | |
download | micropython-d80ee8bbfd52fd44f623aabbef4544f9572aca9e.tar.gz micropython-d80ee8bbfd52fd44f623aabbef4544f9572aca9e.zip |
Added memzip filesystem support for teensy
You can now append a zipfile (containining uncomressed python sources)
to the micropython.hex file.
Use MEMZIP_DIR=directory when you call make, or set that in your
environment to include a different tree of source files.
Added sample /boot.py, /src/main.py, /test.py and /src/test.py files.
Added run command so that you can execute scripts from REPL (until import is implemented).
Added build directory to .gitignore
Diffstat (limited to 'teensy/memzip.c')
-rw-r--r-- | teensy/memzip.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/teensy/memzip.c b/teensy/memzip.c new file mode 100644 index 0000000000..ec6c26980c --- /dev/null +++ b/teensy/memzip.c @@ -0,0 +1,37 @@ +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include "memzip.h" + +extern uint8_t _staticfs[]; + +MEMZIP_RESULT memzip_locate(const char *filename, void **data, size_t *len) +{ + const MEMZIP_FILE_HDR *file_hdr = (const MEMZIP_FILE_HDR *)_staticfs; + uint8_t *mem_data; + + /* Zip file filenames don't have a leading /, so we strip it off */ + + if (*filename == '/') { + filename++; + } + while (file_hdr->signature == MEMZIP_FILE_HEADER_SIGNATURE) { + const char *file_hdr_filename = (const char *)&file_hdr[1]; + mem_data = (uint8_t *)file_hdr_filename; + mem_data += file_hdr->filename_len; + mem_data += file_hdr->extra_len; + if (!strncmp(file_hdr_filename, filename, file_hdr->filename_len)) { + /* We found a match */ + if (file_hdr->compression_method != 0) { + return MZ_FILE_COMPRESSED; + } + + *data = mem_data; + *len = file_hdr->uncompressed_size; + return MZ_OK; + } + mem_data += file_hdr->uncompressed_size; + file_hdr = (const MEMZIP_FILE_HDR *)mem_data; + } + return MZ_NO_FILE; +} |