Everything

-crc


< Optimizing Linkage Editor (rlink) Options / Output Options >

[Format]

-CRc = <suboption>
       <suboption>: <address where the result is output>=<target range>
                         [/<Operation Method>][<initial value>][:<endian>]
                    <address where the result is output>: <address>
                    <target range>: { <start address>-<end address> | 
                                      <section> }[,...]
                    <Operation Method>: { CCITT | 16-CCITT-MSB | 
                                               16-CCITT-MSB-LITTLE-4 |
                                               16-CCITT-MSB-LITTLE-2 | 16-CCITT-LSB |
                                               16 | SENT-MSB | 32-ETHERNET }
                    <initial value>: <initial value>
                    <endian>: {BIG | LITTLE}[-<size>-<offset>]

[Description]

-

CRC (cyclic redundancy check) operation is done for the specified range of section data in the order from the lower to the higher addresses, and the operation result is output to the specified output address in the specified endian mode.

-

Specify one of the following as the operation method. If the specification of the operation method is omitted, operation is performed assuming that CCITT has been specified.

Table 2.16

List of Operation Methods

Operation Method

Description

CCITT

The result of CRC-16-CCITT operation is obtained with the MSB first, an initial value of 0xFFFF, and inverse of XOR performed.

The generator polynomial is x16+x12+x5+1.

16-CCITT-MSB

[V2.04.00 or later]

The result of CRC-16-CCITT operation is obtained with the MSB first.

The generator polynomial is x16+x12+x5+1.

16-CCITT-MSB-LITTLE-4

[V2.04.00 or later]

The input is handled in little endian in 4-byte units and the result of CRC-16-CCITT operation is obtained with the MSB first.

The generator polynomial is x16+x12+x5+1.

16-CCITT-MSB-LITTLE-2

[V2.04.00 or later]

The input is handled in little endian in 2-byte units and the result of CRC-16-CCITT operation is obtained with the MSB first.

The generator polynomial is x16+x12+x5+1.

16-CCITT-LSB

[V2.04.00 or later]

The result of CRC-16-CCITT operation is obtained with the LSB first.

The generator polynomial is x16+x12+x5+1.

16

The result of CRC-16 operation is obtained with the LSB first.

The generator polynomial is x16+x15+x2+1.

SENT-MSB

[V2.04.00 or later]

The input is handled in little endian in the lower 4-bit units of one byte and the result of SENT-compliant CRC operation is obtained with the MSB first and an initial value of 0x5.

The generator polynomial is x4+x3+x2+1.

32-ETHERNET

[V2.04.00 or later]

The result of CRC-32-ETHERNET operation is obtained with an initial value of 0xFFFFFFFF, inverse of XOR performed, and the bits reversed.

The generator polynomial is x32+x26+x23+x22+x16+x12+x11+x10+x8 +x7+x5+x4 +x2 +x+1.

-

The range of values that can be specified for <initial value> is from 0x0 to 0xFFFFFFFF when the operation method is 32-ETHERNET, from 0x0 to 0xF when the operation method is SENT-MSB, and from 0x0 to 0xFFFF for the other cases.

-

When <initial value> is omitted, operation is performed on the assumption that 0x5 has been specified for the operation method of SENT-MSB, 0xFFFF for CCITT, 0xFFFFFFFF for 32-ETHERNET, and 0x0 for other cases.

-

The operation result is output to the specified output address by writing at the offset location from the beginning of the area allocated by size in the byte order specified with BIG or LITTLE. 0 is output from the beginning of the allocated area until immediately before the offset location.

-

When the size and offset are omitted, the size is assumed to be 2 bytes and the offset is assumed to be 0.

-

When the space option is not specified, space=FF is assumed for CRC operation for the unused areas in the operation range. Note that 0xFF is only assumed for CRC operation for the unused areas, but the areas are not actually filled with 0xFF.

-

Operation is done from the lower to the higher addresses of the specified operation range.

-

If this option is specified more than once, the results of all the specified CRC operations will be output. [V3.05.00 or later]

[Example]

-

rlink *.obj -form=stype -start=P1,P2/1000,P3/2000
-crc=2FFE=1000-2FFD -output=out.mot=1000-2FFF

-

crc option: -crc=2FFE=1000-2FFD

-

In this example, CRC will be calculated for the range from 0x1000 to 0x2FFD and the result will be output to address 0x2FFE.

-

When the space option has not been specified, space=0xFF is assumed for calculation of free areas within the target range.

-

output option: -output=out.mot=1000-2FFF

-

Since the space option has not been specified, the free areas are not output to the out.mot file. 0xFF is used in CRC for calculation of the free areas, but will not be filled into these areas.

Notes 1.

The address where the result of CRC will be output cannot be included in the target range.

Notes 2.

The address where the result of CRC will be output must be included in the output range specified with the output option.

 

-

rlink *.obj -form=stype -start=P1/1000,P2/1800,P3/2000
-space=7F -crc=2FFE=1000-17FF,2000-27FF
-output=out.mot=1000-2FFF

-

crc option: -crc=2FFE=1000-2FFD,2000-27FF

-

In this example, CRC will be calculated for the two ranges, 0x1000 to 0x17FF and 0x2000 to 0x27FF, and the result will be output to address 0x2FFE.

-

Two or more non-contiguous address ranges can be selected as the target range for CRC.

-

space option: -space=7F

-

The value of the space option (0x7F) is used for CRC in free areas within the target range.

-

output option: -output=out.mot=1000-2FFF

-

Since the space option has been specified, the free areas are output to the out.mot file. 0x7F will be filled into the free areas.

Notes 1.

The order that CRC is calculated for the specified address ranges is not the order that the ranges have been specified. CRC proceeds from the lowest to the highest address.

Notes 2.

Even if you wish to use the crc and space options at the same time, the space option cannot be set as random or a value of 2 bytes or more. Only 1-byte values are valid.

 

-

rlink *.obj -form=stype -start=P1,P2/1000,P3/2000
-crc=1FFE=1000-1FFD,2000-2FFF
-output=flmem.mot=1000-1FFF

-

crc option: -crc=1FFE=1000-1FFD,2000-2FFF

-

In this example, CRC will be calculated for the two ranges, 0x1000 to 0x1FFD and 0x2000 to 0x2FFF, and the result will be output to address 0x1FFE.

-

When the space option has not been specified, space=0xFF is assumed for calculation of free areas within the target range.

-

output option: -output=flmem.mot=1000-1FFF

-

Since the space option has not been specified, the free areas are not output to the flmem.mot file.

-

0xFF is used in CRC for calculation of the free areas, but will not be filled into these areas.

-

rlink *.obj -form=stype -start=.SEC1,.SEC2/1000,.SEC3/2000 -output=out.mot=1000-2FFF
-crc=2FFC=1000-1FFF -crc=2FFE=2000-2FFB

-

crc option (1): -crc=2FFC=1000-1FFF

-

In this example, CRC will be calculated for the range from 0x1000 to 0x1FFF, and the result will be output to address 0x2FFC.

-

crc option (2): -crc=2FFE=2000-2FFB

-

In this example, CRC will be calculated for the range from 0x2000 to 0x2FFB, and the result will be output to address 0x2FFE.

[Remarks]

-

When multiple load module files are input, the compiler outputs a warning message and ignores this option.

-

This option is valid when the output format is form={hexadecimal | stype | bin}. For any other cases, an error is output and execution is terminated.

-

When the space option is not specified and the operation range includes an empty area that is not output, 0xFF is assumed to be stored in the unused area during CRC operation.

-

An error is output and execution is terminated if the CRC operation range includes an overlaid area.

-

The following can be specified for the size and offset when specifying the endian. For any other cases, an error is output and execution is terminated.

-

LITTLE

-

LITTLE-2-0

-

LITTLE-4-0

-

BIG

-

BIG-2-0

-

BIG-4-0

-

Sample Code: The sample code shown below is provided to check the result of CRC figured out by the crc option. The sample code program should match the result of CRC by rlink.

-

When the selected operation method is CRC-CCITT:

typedef unsigned char    uint8_t;
typedef unsigned short   uint16_t;
typedef unsigned ong    uint32_t;
 
uint16_t CRC_CCITT(uint8_t *pData, uint32_t iSize)
{
    uint32_t    ui32_i;
    uint8_t     *pui8_Data;
    uint16_t    ui16_CRC = 0xFFFFu;
 
    pui8_Data = (uint8_t *)pData;
 
    for(ui32_i = 0; ui32_i < iSize; ui32_i++)
    {
        ui16_CRC  = (uint16_t)((ui16_CRC >> 8u) |
                              ((uint16_t)((uint32_t)ui16_CRC << 8u)));
        ui16_CRC ^= pui8_Data[ui32_i];
        ui16_CRC ^= (uint16_t)((ui16_CRC & 0xFFu) >> 4u);
        ui16_CRC ^= (uint16_t)((ui16_CRC << 8u) << 4u);
        ui16_CRC ^= (uint16_t)(((ui16_CRC & 0xFFu) << 4u) << 1u);
    }
    ui16_CRC = (uint16_t)( 0x0000FFFFul & 
                              ((uint32_t)~(uint32_t)ui16_CRC) );
    return ui16_CRC;
}

-

When the selected operation method is CRC-16:

#define POLYNOMIAL 0xa001 // Generated polynomial expression CRC-16
 
typedef unsigned char    uint8_t;
typedef unsigned short   uint16_t;
typedef unsigned long    uint32_t;
 
uint16_t CRC16(uint8_t *pData, uint32_t iSize)
{
    uint16_t crcdData = (uint16_t)0;
    uint32_t data = 0;
    uint32_t i,cycLoop;
 
    for(i=0;i<iSize;i++){
        data = (uint32_t)pData[i];
        crcdData = crcdData ^ data;
        for (cycLoop = 0; cycLoop < 8; cycLoop++) {
            if (crcdData & 1) {
                crcdData = (crcdData >> 1) ^ POLYNOMIAL;
            } else {
                crcdData = crcdData >> 1;
            }
        }
    }
    return crcdData;
}