
Write a File
115
SWRU455A – February 2017 – Revised March 2017
Copyright © 2017, Texas Instruments Incorporated
File System
NOTE:
Downgrading the trusted root-certificate catalog is not possible.
NOTE:
The service pack is a special file which already contains the signature. When writing the
service pack by the host, the sl_FsClose() function should receive a NULL certificate name
and a NULL signature.
8.4.4 Open a File for Write
Opening an existing file for write is the preferred way to update the file content (rather than to delete it and
recreate it). A file which was not closed or aborted cannot be opened for write.
Appending content to an existing file is not supported; when the file is opened for write, the storage of the
file is erased.
If the file was created with a FAILSAFE flag, the storage of the nonactive content is erased; thus, if the
device was powered off before the file closure, the file contains the last valid content.
If the file was created without a FAILSAFE flag, powering off the device before the file is closed results in
no valid copy.
The operation of opening a file for write does not involve updating the file allocation table, unlike the
create file function.
For a secure file, the default behavior is that when opening a file for write, all the tokens except the master
are regenerated. The new tokens can be retrieved by the sl_FsGetInfo function.
If the file is already open (for write or read) or does not exist, sl_FsOpen() returns an error.
The following is a partial list of errors that might be returned by the creation function:
•
SL_ERROR_FS_FILE_IS_ALREADY_OPENED: The file is already opened for read or write.
•
SL_ERROR_FS_INVALID_TOKEN_SECURITY_ALERT: For a secure file, the input token is not valid;
this triggers security alerts if the device is secured.
•
SL_ERROR_FS_FILE_NOT_EXISTS: The file does not exist.
The following parameters are required to create a file:
•
Filename: The filename is not case-sensitive.
•
File tokens: The token is the key for accessing a secure file; for nonsecure files it is set to zero. For a
secure file with no public write permission, the host should supply a token with write permission
(master token, write token, or read-write token).
•
The function returns a token on the same permission level as the input one.
•
Flags: The noncreation flags that can be set:
–
SL_FS_WRITE_MUST_COMMIT – used for the file commit feature, and can be used only if the file
was created with a FAILSAFE flag.
–
SL_FS_WRITE_BUNDLE_FILE – used for the bundle commit feature, and can be used only if the
file was created with a FAILSAFE flag.
–
SL_FS_WRITE_ENCRYPTED – used for secure content delivery.
8.4.5 Write an Opened File
The host can invoke the write command for each file opened for write. For nonsecure files, the write
command can be done to random offsets. For secure files, the write operation also encrypts the file, thus
writing secure files requires writing to sequential offsets, or writing to a 16-byte-aligned offsets buffer,
which is also 16-byte-aligned in size.
The file system sets the actual file size as the higher offset that was written; the actual file size can be
retrieved by the sl_FsGetInfo() function.