Checked in lua io and os libraries port on the trunk, changeset 517. See the
lua documentation for details of how to use these libraries, but be sure to read below for important differences, limitations and warnings.
WARNING:
These features are experimental and untested on most cameras. They might corrupt your memory card, causing all data to be lost. Even if they work correctly on your camera, incorrect use may cause data loss or filesystem corruption..
Note this is only a risk if you try to use these features from lua. Just having them in your build doesn't pose a risk.
These are compile time optional. If you don't want to build them, see root makefile.inc. Together, they add about 4kb to the memiso useage.
Test script:
llibtst.lua added to /script in svn, and also attached to this post.
If the libraries have not already been tested on your camera and firmware version, you should run the script before attempting to use them.
This script tests the various io and os functions, generating A/llibtst.log and reporting pass or fail in the console. If not all tests are run, or there are failures, it may leave other files or directories in the root.
Failures could crash your camera, or potentially corrupt your SD card. Be sure you don't have anything wouldn't mind losing before you run it.
The pass/fail in the console only provides a general indication. The logfile should be examined to be sure everything is working. Please post the log if your camera/firmware has not been tested already. An example log from my camera is attached.
The log is formatted such that most lines end with OK or ERR followed by possible return values, and then PASS, FAIL, or NA
PASS or FAIL indicate whether the test recieved the result it expected. OK and ERR indicate whether the function being tested reported success or failure, which may represent a PASS or FAIL depending on circumstances.
NA means the script doesn't count the result of that particular call as a pass or fail, because the results are variable or not meaningful.
The script also serves as an example of how to use the libraries.
Differences from
standard lua iolib:
Missing features:
- popen: CHDK has no other processes, no pipes. Someone can revisit this when ELF is done
- standard file handles: stdin/stdout/stderr all start out closed, as do io.input() and io.output().
- tmpfile isn't implemented yet, but may be added later.
Other differences:
- Error detection and reporting is more limited:
vxworks reports errno, but no text description
dryos has no errno (that I was able to find), and simply reports "error"
- file:read("*n") will behave slightly differently because it doesn't use scanf. Shouldn't matter for sanely structured files, but corner cases will be different.
Added:
- a new file method file:_getfptr() which returns the actual FILE * associated with the file object. This is strictly for development/debugging, but combined with peek makes verifying FILE structure hack much simpler.
Differences from
standard lua oslib:
Missing features:
- os.clock: not implemented. Note this relates to CPU time used by a process, not time of day (which is handled by os.time and os.date)
- os.execute: no processes, revisit for ELF
- os.exit: not meaningful for CHDK
- os.getenv: environment variables exist in vxworks, but usefulness is doubtful
- os.setlocale: functions may exist, but it's unlikely the rest of the firmware uses them
- os.tmpname: TODO, not implemented yet
Added features:
- os.mkdir("name"): not standard, but useful
Other differences:
- Similar error reporting limitations to io
- os.date doesn't distinguish between local and GMT. It's possible support could be added for some cameras
- os.difftime just returns t1 - t2
Still to do:
- Add methods to list directories and stat files.
General notes from vxworks testing:
os.remove works on files and empty directories. Attempting to remove a non-empty directory fails gracefully.
os.rename works on files and empty directories.
Attempting to rename a non-empty directory may result in filesystem corruption!.
os.rename only works within a given directory. You can not use rename to move a file to another directory.
Attempting to do so may cause unpredictable results.
os.rename
may produce unpredictable results if the target name already exists.
os.mkdir will not create a directory if the name has a trailing /, but fails gracefully
io functions are very likely limited to files of less that two gigabytes, and certainly less than four.
unlike some OSes, file:seek cannot be used to extend a file
Future versions should attempt to handle some of these situations more gracefully. Dryos may behave differently.
New entry points used, all added to required sig_ref_*.txt
DeleteFile_Fut
Feof_Fut
Fflush_Fut
Fgets_Fut
MakeDirectory_Fut
RenameFile_Fut
errnoOfTaskGet - vxworks only, stubbed in wrappers.c for dryos
mktime - vworks only, version in wrappers.c does the right thing for each OS
strftime
mktime_ext - dryos only. Not called mktime because it doesn't behave quite like mktime
Although they all get good matches from finsig, these entry points are only verified on a few cameras. Running the test script should quickly verify each camera.
Added two #ifdef controlled options to stdlib.h
STDLIB_COMPAT_FILE - cause fopen et al use a FILE* instead of an int, and generally behave like C stdio. Also adds reverse engineered FILE structure and ftell
FS_USE_FUT - cause rename, mkdir and remove to use Fut.
Both of these can be defined on a per file basis at compile time, and are currently used for lua. In the future we may want to make this the default for the rest of CHDK
Unsupported cameras:
a450/100d
tx1/100g
I don't have dumps for these cameras, and so cannot support them. New entry points are stubbed to nullstub in stubs_entry_2.S
Attempting to actually use these stubs will probably result in crashes.
lua libs are #ifdef'd out for these, see each platforms makefile.inc
Miscelanious changes:
Some stubs_entry.S had entry points not in any of the sig_ref_*.txt files. These were not used in the code, and so are removed by this checkin: fprintf fputs puts
Added Remove to sig_ref_vxworks_3.txt. This causes the function to be incorrectly detected on some cameras (with a low match %) but all those cams already have it in stubs_entry_2.S
Added iosDevFind to sig_ref_vxworks_1.txt, not required for libs but existed in some old stubs_entry.S, used if CAM_CONSOLE_LOG_ENABLED is defined
Replace the empty stubs_entry.S for s5is with the one generated in my build. All entrypoints are unverified.
Fixed ROMBASEADDR for ixus65_sd630 100a. Now 0xff810000. If your dump has leading zeros, you'll need to fix it.