# compstatic.TWL

## Description

This command is for TWL ROMs. See `compstatic` for details on NITRO ROMs.

The `compstatic.TWL` tool compresses a ROM image for an application's static region or extended static region and overlays or extended overlays. In most cases, ROM capacity can be conserved through compression. However, because ROM images must be expanded in memory, the time required for loading is greater in most cases compared to using uncompressed images.

Due to limitations of the launcher, a TWL application cannot be created if its ROM image has either a static region or extended static region that exceeds 2.5 MB. However, it is possible to create an application with a static region or extended static region that exceeds 2.5 MB by using `compstatic.TWL`.

The `compstatic.TWL` tool also has a feature for embedding the ROM image digest values of various overlays into the static region's ROM image. This feature helps to prevent tampering with the overlay and extended overlay.

When using TWL-SDK's `make` environment, compression of the ARM9 static region, extended static region, overlay, and extended overlay is enabled when some value is defined in the environmental variable `TWL_COMPRESS`. The feature to embed overlay digest values is enabled automatically regardless of the environmental variable.

## Using the Tool

### Start Command

    % compstatic.TWL -a [-d] [-9] [-SHSIZE] [-c] [-C] [-F|-eSUFFIX] [-lFILE] STATICMODULE OVERLAYDEFS [OVERLAYTABLE] LTDSTATICMODULE LTDOVERLAYDEFS [LTDOVERLAYTABLE]

or

    % compstatic.TWL -a [-d] [-9] [-SHSIZE] [-c] [-C] [-F|-eSUFFIX] [-lFILE] -f RESPONSE_FILE

The `-a` option embeds in the static region the digest value of the overlay or extended overlay specified in `OVERLAYDEFS/LTDOVERLAYDEFS`. This digest value is used to confirm the validity of the overlay module at load time. Memory for embedding digest values must be allocated ahead of time. However, as long as the default LCF template file is used, a link script for automatically allocating the required memory is generated by the `makelcf.TWL` tool.

The `-d` option is for outputting `compstatic.TWL` debugging messages. Normally there is no need to specify this.

The `-9` option is for compressing the static region files specified in `STATICMODULE` as ARM9 code. The decompression process has been integrated with `crt0.[HYB|LTD].TWL.o` in TWL-SDK, so no further work is required on the part of the application programmer.

The `-S` option is for compressing the extended static region files specified in `LTDSTATICMODULE`. If these files include a header portion to leave uncompressed, specify the size of this portion in `HSIZE`; however, usually 0 is specified here to compress everything within the region. The decompression process has been integrated with `crt0.[HYB|LTD].TWL.o` in TWL-SDK, so no further work is required on the part of the application programmer.

The `-c` option is for compressing the various overlay files specified in `OVERLAYDEFS`. The decompression process is integrated with TWL-SDK's FS library, so the application programmer does not need to add any additional operation.

The `-C` option is for compressing the various extended overlay files specified in `LTDOVERLAYDEFS`. The decompression process is integrated with TWL-SDK's FS library, so the application programmer does not need to add any additional operation.

The `-e` and `-F` options control the post-compression filenames. If these options are not specified, compression results are output to files of the original filename but with the extension `_LZ` appended. To change this `_LZ` extension, use the `-e` option and specify a new extension in `SUFFIX`. Specify the `-F` option to overwrite the original files with the processed files.

Specify the `-I` option together with the `-c` or `-C` option. You can pass the list file described later as a parameter to specify overlay modules to exclude from compression.

The `-f` option allows you to specify the files to process with a file containing their filenames, as opposed to using command line arguments to specify their filenames. The file in which filenames are recorded is specified by `RESPONSE_FILE`. `RESPONSE_FILE` contains the actual filenames in `STATICMODULE/OVERLAYDEFS/OVERLAYTABLE/LTDSTATICMODULE/LTDOVERLAYDEFS/LTDOVERLAYTABLE`. Each filename is terminated with `\0` and stored in order. Files designated in this way are considered to be designated with a relative path from the directory where `RESPONSE_FILE` is located.

It is currently not possible to compress the ARM7's static region because the ARM7 component does not support automatic decompression.

## Compression Specification List Format

All overlay modules are compressed when the `-c` or `-C` option is specified. A specific file can be excluded from compression by using the format described below.

This is written as follows, with the overlay module and compression specifier separated by a comma on a single line.

    main_overlay_1.TWL.FLX.sbin, E
    main_overlay_2.TWL.FLX.sbin, E
    main_overlay_3.TWL.FLX.sbin, S

For the overlay module filename, enter the filename actually output to `$(BINDIR)` before the file is compressed. You can also specify an extended overlay file.

The compression specifier has the following meanings.

`Compression Specifier` | Description
--- | ---
`S` | `SMART`: It applies compression according to the `-c` or `-C` option. This is the default behavior.
`E` | `EXCLUSION`: It excludes the file from compression.

When the TWL-SDK make environment is used, define both the `COMPSTATIC_SPEC_FILE` and `TWL_COMPRESS` environment variables.

    TWL_COMPRESS         = TRUE
    COMPSTATIC_SPEC_FILE = FilePath

Beginning with TWL-SDK 5.4, a compression specification list file is automatically generated based on parameter information in the LSF file. (See makelcf.TWL)
If `COMPSTATIC_SPEC_FILE` is not specified, the automatically generated file is used.

## Location

`$TwlSDK/tools/bin/compstatic.TWL.exe`

## See Also

`makerom.TWL`
`makelcf.TWL`

## Revision History

2009/05/14 Added a description of the `-l` option. In conjunction with that, added a section entitled "Compression Specification List Format"
2008/11/07 Added the fact that overlays can also be compressed.
2008/10/28 Made additional revisions to the description of the `-a` option.
2008/09/12 Added details.
2008/07/09 Preliminary version.

CONFIDENTIAL