TMS320F280049: Why is this cast necessary?

Part Number: TMS320F280049

Tool/software:

Given this "simple" snipped of code:

if ( meta_data_size_announced != (uint16_t)(MIN_META_DATA_SIZE + name_size_from_meta_data() + custom_meta_data_size_from_meta_data() ) )
{
    return reset_state();
}

Why is the cast (to uint16_t one the right hand side of the != operator) above necessary? I have the value of 31 on the left and on the right side of the != operator and would expect that the expression yields false, even without that cast.

MIN_META_DATA_SIZE is defined as:

#define MIN_META_DATA_SIZE ( \
     1 /* Firmware Name Size */ \
  +  1 /* Firmware Major Version */ \
  +  1 /* Firmware Minor Version */ \
  +  2 /* Firmware Type */ \
  +  2 /* Hardware Type */ \
  +  8 /* Device ID */ \
  +  8 /* Flags / Reserved */ \
  +  4 /* Custom Meta Data Size */ )

`name_size_from_meta_data()` and `custom_meta_data_size_from_meta_data()` are declared as follows:

static size_t name_size_from_meta_data(void);
static uint32_t custom_meta_data_size_from_meta_data(void);

`meta_data_size_announced` is a static variable of type uint16_t. `name_size_from_meta_data` returns 4 in the given case and `custom_meta_data_size_from_meta_data()` returns 0.

Beside adding the cast above, I found a few other methods to get the desired result:

- Disable optimization (instead of --opt_level=4)

- Removing the call to `custom_meta_data_size_from_meta_data()`

- Using a different compiler like clang

I see this effect, with the 20.2.2 and 22.6.0 Version of the TI compiler.

Thanks in advance and best regards,

Torsten

  • Hi Torsten,

    In general, casting is typically used in a case like this to ensure that the comparison is carried out correctly (essentially, making sure you are comparing apples to apples). In this case, since the "meta_data_size_announced" is defined as type uint16_t, the other side of the comparison should be cast to match this. 

    What you are casting is comprised of "MIN_META_DATA_SIZE", the type size_t returned from "name_size_from_meta_data()", and the type uint32_t returned from "custom_meta_data_size_from_meta_data()". When these values are used together, they may be subject to integer promotion rules (meaning, you would not get a unint16_t out).

    Different compilers/optimizations handle these cases differently, but casting explicitly ensures that you are using both uint16_t values to avoid any question and maintain consistency. 

    Best Regards,

    Allison

  • Hi Allison,

    but under what rules, would a compiler be allowed to compare 31 and 31 as being different? Usually, the compiler should apply implicit conversions to find an implementation of operator != that can be used. So what implicit conversion could convert a 31 to something that is not equal to 31?

  • I suspect the compiler has done something wrong.  Cases like this often turn on some small detail that is easily overlooked.  That being the case, for the source file which contains the problem comparison, please follow the directions in the article How to Submit a Compiler Test Case.

    Thanks and regards,

    -George

  • Hi George,

    thanks for looking into this. Please find attached the preprocessor output of the source file, that contains the line of code in question. The line 2285 works as expected, if the currently commented out cast to uint16_t is not commented out, or if optimization is not applied. The source file is translated as follows:

    /Applications/ti/ti-cgt-c2000_22.6.0.LTS/bin/cl2000 --compile_only --c_file=/Users/todi/bootloader/c2000/bootloader/meta_data.c -DAPPLICATION_BEGIN_ADDR=0x00082000 -DAPPLICATION_FLASH_SIZE=0x1dff8 -DAPP_STARTUP_DELAY=2000 -DBOOTLOADER_KEY_ADDR=0x08000A -DCAN_BAUDRATE=1000000 -DCAN_BAUDRATE_1000000=1 -DCAN_MESSAGE_ID=256 -DCAN_MESSAGE_ID_SIZE=3 -DCPU1=1 -DCROSSCOMPILING=1 -DCRYPTO_IV_LENGTH=96 -DCRYPTO_KEY_LENGTH=128 -DCRYPTO_SUPPORT=1 -DCRYPTO_SUPPORT_CLIENT_LIB=1 -DDEVICE_NAME=f28004x -DEXTERNAL_OSCILLATOR_FREQUENCY=20000000 -DHAS_DRIVER_LIB -DMAX_APPLICATION_FLASH_SIZE=0x1DFF8 -DPROJECT_VERSION_MAJOR=1 -DPROJECT_VERSION_MINOR=7 -DTARGET_MC_FAMILY_F28004X=1 -DTORROX_BOOTLOADER_NAME=c2000 -DVALUE_OF_UNUSED_FLASH_MEMORY_BYTE=0xff -D_FLASH --include_path=/Users/todi/bootloader/c2000/drivers --include_path=/Users/todi/bootloader/library --include_path=/Applications/ti/c2000/C2000Ware_5_02_00_00/device_support/f28004x/common/include --include_path=/Applications/ti/c2000/C2000Ware_5_02_00_00/device_support/f28004x/headers/include --include_path=/Applications/ti/c2000/C2000Ware_5_02_00_00/driverlib/f28004x/driverlib --include_path=/Users/todi/bootloader/c2000/client_lib --include_path=/Applications/ti/ti-cgt-c2000_22.6.0.LTS/include --silicon_version=28 --large_memory_model --unified_memory --cla_support=cla1 --float_support=fpu32 --fp_mode=relaxed --tmu_support=tmu0 --vcu_support=vcu2 --display_error_number --symdebug:dwarf --c99 --gen_func_subsections --gen_data_subsections=on --opt_level=4 -DNASSERT --preproc_with_comment --preproc_with_compile --output_file=CMakeFiles/bootloader.out.dir/meta_data.c.obj

    Thanks and best regards,

    Torsten

    meta_data.pp.txt

    meta_data.c.obj.txt
    �x�vfj���!�+3�.text� .data�@.bss��k��i:.cinit?T �x@.ebss��� @A��P��P��P�V�Q��P
    �  @ � *y @B#� 6y @U�2!z @ubN"R{ @�# @�>#| @�cx#�| @�C>$z} A�&�$�} @6%:~ @P-%^~ @=�x%�~0t0('�%��X*�x,��&.icode��,A2TI+Assembler
    �������g/Users/todi/bootloader/c2000/bootloader/meta_data.c/Users/todi/bootloader/c2000/build/bootloaderTI TMS320C2000 G3 C/C++ Codegen Unix v22.6.0.LTS Copyright (c) 1996-2018 Texas Instruments Incorporatedgcm_init_16_gcm_init_16V	3Ogcm_add_auth_data_block_gcm_add_auth_data_blockV	�xgcm_set_iv_gcm_set_ivV	�gcm_flip_gcm_flipV	�gcm_decrypt_block_gcm_decrypt_blockV	��expected_typea_expected_typeremaining_data_remaining_datadata_flushed�_data_flushedmeta_data_size_meta_data_sizemeta_data_total_size_meta_data_total_sizemeta_data_size_announced_meta_data_size_announcedall_metadata_uploaded�_all_metadata_uploadedUgcm_check_tag�_gcm_check_tagV	�calculated_crcc_calculated_crc
    block_header_size�_block_header_sizeblock_header_currentc_block_header_currentblock_header_addressc_block_header_addressblock_header_remaining_sizec_block_header_remaining_sizeblock_header_current_lastc_block_header_current_lastblock_header_address_lastc_block_header_address_last(checksum32_uint_fast8c_checksum32_uint_fast8�c$P$T2$1d_$P$T2$1initialization_vector�_initialization_vectorauth_tag�_auth_tagmeta_data�_meta_datacrypto_contexti_crypto_contextblock_headers�_block_headersvoidboolsigned charunsigned charwchar_tshortunsigned shortintunsigned int	__uint16_th	__uint_fast8_tx	uint_fast8_t���
     �����
    ��
    ��
    ��� �
    	uint16_tx ) .longunsigned long	__uint32_tA	uint32_tR�c
     c��c�	size_tA��long longunsigned long longfloatdoublelong doubleunsigned char_block_header_meta_datastart_address#c_start_addresssize#c_size_V	gcm_contextVcounter#�_countercounter_0#�_counter_0crypt# �_crypth#0r_hbuf#8�_bufyw#Hr_ywcount_aad#Pc_count_aadcount_ctr#Rc_count_ctrused_crypt#Ta_used_crypt iPALQAHRPLSPHdSPeXTfTgST0hST1iPCjRPClFPmDPnSXMoPM� OVM�!PAGE0�"AMODE�NEALLOW�#INTM�$IFR�%IER�&V�LPSEUDOH�MVOLTAR0UXAR0VAR1WXAR1XAR2YXAR2ZAR3[XAR3\AR4]XAR4^AR5_XAR5`AR6aXAR6bAR7cXAR7�+R0H�/R1H�3R2H�7R3H�;R4H�?R5H�CR6H�GR7H�JRB�(STFkFPUHAZ�OSTF_HWDIV�PVCRC�QVSTATUS�private_key3_private_key/Users/todi/bootloader/c2000/bootloader/meta_data.cA/Users/todi/bootloader/c2000/bootloader/meta_data.cD~Wreset_state#�_reset_state/Users/todi/bootloader/c2000/bootloader/meta_data.cG
    /Users/todi/bootloader/c2000/bootloader/meta_data.c^|_gcm_init_16"
    read_uint32_tc_read_uint32_t/Users/todi/bootloader/c2000/bootloader/meta_data.cf/Users/todi/bootloader/c2000/bootloader/meta_data.cm~\pos_pos\pos_pos$first_firmware_block_first_firmware_block/Users/todi/bootloader/c2000/bootloader/meta_data.cz
    /Users/todi/bootloader/c2000/bootloader/meta_data.c�~Pblock_start�_block_start_read_uint32_t_read_uint32_t_read_uint32_t�meta_data_firmware_version_meta_data_firmware_version/Users/todi/bootloader/c2000/bootloader/meta_data.c�
    /Users/todi/bootloader/c2000/bootloader/meta_data.c�~block_address_size_meta_data-_block_address_size_meta_data/Users/todi/bootloader/c2000/bootloader/meta_data.c�/Users/todi/bootloader/c2000/bootloader/meta_data.c�vPindex�_index�|$P$T0_$P$T0�x$P$T1_$P$T1bindex�_index_read_uint32_t_read_uint32_t,handle_meta_data_message��_handle_meta_data_message/Users/todi/bootloader/c2000/bootloader/meta_data.c�/Users/todi/bootloader/c2000/bootloader/meta_data.c�xPmessage_size�_message_size\buffer�_bufferVmessage_size�_message_sizeXbuffer�_buffer^i�_i`i�_i^i�_i^i�_ibmeta_data_size�_meta_data_size^meta_data_total_size�_meta_data_total_size_reset_state_gcm_add_auth_data_blocky_checksum32_uint_fast8���handle_load_meta_datab�_handle_load_meta_data/Users/todi/bootloader/c2000/bootloader/meta_data.c�/Users/todi/bootloader/c2000/bootloader/meta_data.cHvPmessage_size�_message_size\buffer_buffer^type�_type�treason�_reason`message_size�_message_sizeZbuffer_bufferVtype�_typeXreason�_reason_reset_state_reset_stateM_checksum32_uint_fast8Va
    �handle_flush_meta_datac�_handle_flush_meta_data/Users/todi/bootloader/c2000/bootloader/meta_data.cQ/Users/todi/bootloader/c2000/bootloader/meta_data.c�|Pmessage_size�_message_size\buffer_buffer^crc�_crc�ztype�_type�xreason�_reasonRmessage_size�_message_size\buffer_buffer^crc�_crcbtype�_type`reason�_reasonPexpected_crcc_expected_crc_read_uint32_t?_reset_stateI_first_firmware_blockL_gcm_flipS_gcm_set_ivZb
    rcheck_uploaded_firmware_range_against_meta_data&�_check_uploaded_firmware_range_against_meta_data/Users/todi/bootloader/c2000/bootloader/meta_data.c�/Users/todi/bootloader/c2000/bootloader/meta_data.c�~Paddressc_address�|length�_length`address�_addressblength�_length_reset_state_first_firmware_block"%
    �decrypt_firmware_blockC�_decrypt_firmware_block/Users/todi/bootloader/c2000/bootloader/meta_data.c�/Users/todi/bootloader/c2000/bootloader/meta_data.c�j\packed_buffer#_packed_buffer^buffer_length_in_bytes_buffer_length_in_bytesPblock_addressc_block_address�hblock_alignmentc_block_alignment�pbuffer�_bufferXpacked_buffer#_packed_bufferVbuffer_length_in_bytes_buffer_length_in_bytesRblock_address�_block_addressbblock_alignment�_block_alignment_gcm_decrypt_block,B
    jcheck_security_tag�_check_security_tag/Users/todi/bootloader/c2000/bootloader/meta_data.c�/Users/todi/bootloader/c2000/bootloader/meta_data.c�~_gcm_check_tag��������������������
    �����������
    �V�����v1�����H�
    (��+�V++++��
    :����@v��������v���Ť���V�~`��g@v��vo�IaR'aRaRT`��Ra�����թ��
    ����݄�����`Bo��@a
    �զV���݄�����`2o��0a���]�	a��g�f�	a�ŦV�Xǒ
    ��ަ�
    ����`o��a�����թ��
    ����݄�����`v�	aRa�����@vv��B��@vv���t����������������L�������V�A`��ǒ���V���`@v����v�S1`R/f
    �V��*`��V�����V��aSaSaS`Rao��`Ra����Sf�
    oR
    h�oR`�V��Ra@v��o�++B@vv�����������)V�į��(�%Z���ʪ��'�+���;VZ���ʪ��voVv
    a�����@vX��`�@v���@v��Z�H�Fū�V�A`�V�v�ǖ���7`)V�̯��(�%Z���ʪ˧�;V�V�Z���ʪ��ũ`�V��'aRaRaRa&o��]���Tf�@v�����r��a@vo@v�Vo�@vo�@�@vv��V��������YZ�����X��a�4o)�V�@�V���)a�\����ܤ\	��Œ��Ė����̖�ww�\�ܤ]�@v�\�ܤ\���V��ʅ�����١���`�������v�D�`�a�R	`�`�fX�`@vVAV��`V@v��@�@v��v)��
    C��i��v3�V����@v�H��@v�\F��
    o�\�ܤ\�v��$�\�ܩ���a��$��$����	
    ;?CG�C�F#�A~�a�A,��A~�A}�A|�}A~�B�A4b�A~�A}�A|�A{Y|A}�B~�A�A�V�]c�A~�a�A,C�A~�A}�Au}}A~�A�A&�T
    CO�G-�A{kA,J1
    /Users/todi/bootloader/c2000/bootloader/meta_data.c�
    �A|>>A?u>Nnop@q??G{>A|>>A?u>N��
    	�
    �
    	pq	
    q�}�	�
    
    ~�%t���
    p>p�ԣ	��pq?@�}o��o�
    	@�	��	.
    
    �~>
    @~>y�
    �~>
    @~>p�`>�D
    )A>z>
    yv>y
    
    �~>
    @~>2	�}>p@�
    }>�~>qrpr	p�?qrq	(v�	qq>r@u>�p	��|>?A~>@�
    ?�
    p
    @
    ~t�?�
    �}>A~>qA�qyo�rrq		�~	���~>P>	�>
    	�ppz>�q>)~>�
    �
    	�II
    I�@I
    28
    I�@3I%�@	I
    !/$>&I
    .?I�@�@�@�@�@�@�@�@
    .?I�@�@�@�@�@�@�@�@
    .?I�@�@�@�@�@�@�@�@
    .I�@�@�@�@�@�@�@�@
    .�@�@�@�@�@�@�@�@
    .<?I�@.<?�@4
    ?I�@4
    I�@;��I��
    ���@���@t#C&�bc-Z!<icode>
    ��X�+�*�-�3�5/Users/todi/bootloader/c2000/bootloader/meta_data.c/N;	/Applications/ti/ti-cgt-c2000_22.6.0.LTS/bin/ac2000 -@/var/tmp/TIfHwH8jt0d \\\.]	e$e,e0^BBB.C	e$#e-ei#e	
    524298DHHH.Ie:
    e
    e
    -1.Je:!e!e!0.Ke:ee0.Le:*e*e*1.Ne:!e!e!0.Oe:!e!e!0.Pe:!e!e!0.Re:ee0.Se:ee0.Te:ee0.Ue:ee0.Ve:e e0.We:e!e0.Ye:*e*"e*0.[eFe@e$%e8e e$eH#eAe-.]e$*e.e*0^aaa.be{eY
    e!e0.ce$e/e
    e(e(e>ejehe
    0edg#_pos  f4f4#_pos  f4f4.ge:ee.he$
    e0e
    e
    e
    e@ehe
    eeejehe
    0ee
    0e@ehe
    eeejehe
    1ee
    8e@ehe
    eeejehe
    2ee
    16e@ehe
    eeejehe
    3ee
    24mp#_block_start  o/#_offset  oEoE#_block_start  o/#_offset  oEoE.pe9e:eee:ee.qe$e1eFeBe0eie(e(e?ejehe
    eeer{{{^C)/Users/todi/bootloader/c2000/bootloader/meta_data.c:12400for.|ere*.~
    eee
    16*.|
    emeL
    e
    eQ
    eeeQ
    eFeCe1e8ee0eHeDe,e.�emeQ
    eee.�	e:eeFeCe1e8ee4.�	e:eeFeCe1e8ee8*.�eve2����.�eee
    16.�eHeEe2.�eve2���#_size_pos  ��.�e:ee25.�e{eP
    e!e27.�e$e,eFeBe0eie(e(e>ejehee��	��.�e{eP
    e!e27.�e$e/	ee@!e
    e(e(e>ejehe
    1ee
    8e@!e
    e(e(e>ejehe
    2ee
    0��
    #_index  �D�D#_index  �D#_$P$T0@3 �D�D.�e:ee��.�emeW
    ee<
    ee
    16e�#_$P$T1@3 �#_block_start  ��.�e:ee
    ee
    16.�	e$3e4
    e;3e:eDe3e3eFeBe0eie(e(e?ejehe
    ee
    4ee;3e:eDe3e3eFeBe0eie(e(e?ejehe
    ee
    8ee3�*�.�eb3e3eF&.�e$3e4
    e3��# _meta_data_size  �.#&_meta_data_total_size  �E�E# _meta_data_size  �.#&_meta_data_total_size  �E#_name_size  ��.�e9e:eee:ee.�emeP
    ee
    0e.�	e$*e5e*1*.�e:eeheH!eGe/.�e$*e5eh*eQ
    e
    eY
    eeeW
    ee
    27e
    0��#_message_size  �&#_buffer ( �B�B#_message_size  �&#_buffer ( �B�B.�e9e:eee:(e(e(.�emeQ
    eh
    e*"e
    0e.�	e$*e6e*0*.�emeY
    eeh
    e!e.�	e$*e6eH*eHe.*��.�ere��*�#_i  ��.�e:ee0^G)/Users/todi/bootloader/c2000/bootloader/meta_data.c:199200202for.�emeQ
    eee*.�
    e:e
    e(e(e=ejehe
    eh
    ee12e!eee
    e(e(ejehee.�0eee.�emeL
    eQ
    eee*�.�	ere*	�#_i  ��.�e:ee0^G)/Users/todi/bootloader/c2000/bootloader/meta_data.c:206207217for.�emeQ
    eee*
    .�
    emeQ
    eh
    eF*eIe5e8ele!ele!e
    0e.�e{eW
    eh
    e!e
    27.�e:e
    e(e(e>ejehe!ee
    e(e(ejehee.�e!e!e!*.�
    e!e!e!.�0eee.�emeL
    eQ
    eee
    *�.�	ere*
    �#_i  ��.�e:ee0^G)/Users/todi/bootloader/c2000/bootloader/meta_data.c:222223225for.�emeQ
    eee*.�
    e:e
    e(e(e?ejehe
    e
    eeh
    e!eee
    e(e(ejehee.�0eee.�emeL
    eQ
    eee*�.�	ere*�#_i  ��.�e:ee0^G)/Users/todi/bootloader/c2000/bootloader/meta_data.c:229230232for.�emeQ
    eee*.�
    e:e
    e(e(e#ejehe
    eh
    ee16e!eee
    e(e(ejehee.�0eee.�emeL
    eQ
    eee*�.�	ere�.�ere*.�e(
    e
    e8e8e8e/
    e
    0ee/
    e
    1e	e/
    e
    2e
    e/
    e
    3e**�.�eme
    eQ
    e
    e
    0eQ
    e
    e
    3e.�	eFeJe&'e8e8e e$eie(e(ejehe
    0ee*.�e:eeFeKe(e8e8eie(ee.�e	!e!e.�e$*e6e*1��
    #_message_size  �##_buffer  �E#_type ( �[#_reason ( �o�o#_message_size  �##_buffer  �E#_type ( �[#_reason ( �o�o.�e9e9e9e:eee:eee:(e(e(e:(e(e(.�e:e
    e(e1.�emeQ
    ee
    3e.�	e$*e7
    eH*eHe.*.�e:e
    e(e
    eeejehe
    0e.�e:e
    e(e2.�emeP
    e
    e(e0e.�	eH*eHe.*.�eme
    eQ
    e
    e(ehe
    e
    e
    1eY
    e
    e(e3e.�	e$*e7
    eH*eHe.*.�e
    e
    e
    .�e:e
    e(e4.�emeQ
    e!e0e.�	e$*e7
    eH*eHe.*.�e:!e!ee
    eeejehe
    1ee@e
    eeejehe
    2ee
    8.�e:e
    e(e3.�ere*.�	emeQ
    e!e12e	.�
    e$*e7
    eH*eHe.*	.�	ere*
    .�	emeW
    e!e27e.�
    e$*e7
    eH*eHe.*.�	e:!e!e!.�	ere*.�	eme
    e
    eQ
    e>e!e16e0eP
    e!e0eY
    e<e!e16e16e
    .�
    e$*e7
    eH*eHe.*
    .�	e:eehe!.�	ere*.�	emeQ
    e!e16e.�
    e$*e7
    eH*eHe.*.�	ere*.�	ere.�ere*.�e(
    e
    e8e8e8e8e/
    e
    0ee/
    e
    1e
    e/
    e
    2ee/
    e
    3ee.e**.�e:e
    e(e5.�emeL
    eQ
    eh
    e*e
    0e.�	e$*e7
    eH*eHe.*.�e:e
    e(e0.�e:*e*e*0.�e:eeFeKe(e8e8eeejehe
    0ee3e0.�e$*e7
    e*1��#_message_size  �$#_buffer  �F#_crc 8 �X#_type ( �k#_reason ( ��#_message_size  �$#_buffer  �F#_crc 8 �X#_type ( �k#_reason ( �#_expected_crc  ��.�e9e9e9e9e:eee:eee:8e8e8e:(e(e(e:(e(	e(.�e:e
    e(	e1.�emeQ
    ee
    5e.�	e$*e9eH*eHe.*.�e:e
    e(	e2.�e:e
    e(ehe
    .�emeQ
    ehe
    e
    eeejehe
    0ee.�	e$*e9eH*eHe.*.�e:e
    e
    e
    e
    eh
    e
    eeejehe
    1ee@ehe
    eeejehe
    2ee
    8e@ehe
    eeejehe
    3ee
    16e@ehe
    eeejehe
    4ee
    24.�e:e
    e8e.�e:e
    e(	e3.�emeQ
    e
    ee.�	e$*e9eH*eHe.*.�e:e
    e(	e4.�ere*.�	eFeLe%)e8e e$eie(e=.�	ere*.�	eme
    eW
    e!ee27eH!eGe/eQ
    eh
    e!e
    eh
    ee27eH!eGe/eHeDe,e	.�
    e$*e9eH*eHe.*	.�	ere*
    .�	eFeMe'*e e$.�	ere*.�	eHeEe2.�	e:*e*"e*1.�	ere*.�	ere.�ere*.�e(
    e
    e8e8e8e8e/
    e
    0ee/
    e
    1ee/
    e
    2e
    e/
    e
    3ee.e**.�e:*e*e*1.�e$*e9e*1��#_address  �@#_length  �P�P#_address  �@#_length  �P�P.�e9e:eee:ee.�eme
    eP
    ee!eP
    ee e.�	e$*e:e*1*.�emeL
    eQ
    eh
    e*"e
    0e.�	e$*e:eH*eHe.*.�emeQ
    eee.�	e$*e:eH*eHe.*.�eme
    eY
    eeeP
    ee
    0e.�	e$*e:eH*eHe.*.�eee.�e	ee.�e:e e.�e:e!e.�emeP
    ee
    0e.�	eHeEe2*.�e$*e:e*1��#_packed_buffer ; �(#(_buffer_length_in_bytes!�@#_block_address  �a#!_block_alignment  �y�y#_packed_buffer ; �(#(_buffer_length_in_bytes!�@#_block_address  �a#!_block_alignment  �y�y.�e9e9e9e:;e;e;e:!e!e!e:eee:ee.�emeQ
    e>e!e16e0e.�	e$*e<e*0*.�e;e;ejehe<
    e>
    eee
    2e��^G)/Users/todi/bootloader/c2000/bootloader/meta_data.c:432433448for.�emeQ
    e!e0e*�#_buffer����	#_i
    ��.�e:
    e
    	e
    0^G)/Users/todi/bootloader/c2000/bootloader/meta_data.c:436437440for.�emeQ
    e
    	e
    8e*.�
    e:e
    e(e(eejehe
    e
    2e
    	eee
    !e;e;ejehe
    	ee255.�
    e:e
    e(e(eejehe
    e
    e
    2e
    	e
    1eeBee
    !e;e;ejehe
    	ee65280e
    8.�8e
    e
    	e
    .�emeL
    eQ
    e
    	e
    8e*�.�	eFeNe)+e8e8e e$e(ee16�	#_i
    ��.�e:
    e
    
    e
    0^G)/Users/todi/bootloader/c2000/bootloader/meta_data.c:444445447for.�emeQ
    e
    
    e
    8e*.�
    e:!e
    !e;e;ejehe
    
    eee
    e(e(eejehe
    e
    2e
    
    ee@e
    e(e(eejehe
    e
    e
    2e
    
    e
    1ee
    8.�8e
    e
    
    e
    .�emeL
    eQ
    e
    
    e
    8e*��.�%e;;e	!e!e16e;e;ejehe
    8e.�%emeL
    eQ
    e!e0e*�.�e$*e<e*1����.�e$*e.eF*eOe+,e8e e$e(e#��ie
    -1epie!0epie*1epie0epie!0epie!0epie!0epie0epie0epie0epie0epi e0epi!e0epi"e*0epi&e0e0ep�o�--abi=coffabi--cla_background_task=off--cla_signed_compare_workaround=off--enum_type=unpacked--fp_reassoc=on--mem_model:code=flat--mem_model:data=large--object_format=coff--sat_reassoc=off--size_speed_goal=low_risk_size--silicon_version=28--unified_memory--cla_support=cla1--float_support=fpu32--fp_mode=relaxed--tmu_support=tmu0--vcu_support=vcu2--symdebug:dwarf--gen_func_subsections=on--gen_data_subsections=on--opt_level=4--symdebug:dwarf_version=3--silicon_errata_fpu1_workaround=off--hll_source=on�t%3_block_header_meta_data@ :t_gcm_context�
     
    t
    	  t___uint32_t
      Ct_uint32_t  Ft3�t3_start_address;t3_size <t3�tt___uint16_tAt___uint_fast8_t{t_uint_fast8_t9t
    �t
    � t
    t�t_countert_counter_0�t_crypt�
    t_h�t_buf�t_yw�	t_count_aad�
    t_count_ctr�
    t	_used_crypt
    �
    	t�t1t1t$t   t!_uint16_tAt"!t#"  t$�t$ t$#t$�t@$  t%tt  t%�t% t%t%�tL%  t&t_size_t
      	@t&�t& t&t&t&�tJ&  t't'�t' t'�tM'  t)t(  t)�t) t)(t)t)�tN)  t2t2�t2�tE2  t
    =�t
    >�t?�� t/!t/�t/�tG/  t;!  t-#t-�t-�tA-  t  tt�tttt�tK  t,t,�t,�tD,  t0t0�t0t0�tB0  t1t1�t1t1t1�tC1  t8  t*t+*t+�t+ t+(t+�tO+  t.*t.�t.�tH.  t5*t5�t5t5t5�tI5  t6*t6�t6t6(t6�t7*t7�t7t7t7(t7(t7�t9*t9�t9t9t98t9(t9(t9�t:*t:�t:t:t:�t<*t<�t<;t<!t<t<t<�t43t4�t4t4�tF3@ �~3/Users/todi/bootloader/c2000/bootloader/dual_cpu.h~4/Users/todi/bootloader/c2000/bootloader/meta_data.c~+/Users/todi/bootloader/c2000/drivers/gcm.h~%/Users/todi/bootloader/library/crc.h~4/Users/todi/bootloader/c2000/bootloader/meta_data.h~B/Applications/ti/ti-cgt-c2000_22.6.0.LTS/include/machine/_types.h~?/Applications/ti/ti-cgt-c2000_22.6.0.LTS/include/sys/_stdint.h~>/Applications/ti/ti-cgt-c2000_22.6.0.LTS/include/sys/stdint.h~:/Applications/ti/ti-cgt-c2000_22.6.0.LTS/include/stddef.h�#%_local_firmware_bank ,�[^1C#_private_key -�A^1C#_reset_state.�G
    ^1C#*_name_size_from_meta_data/�`^1C#_read_uint32_t 0�f^1C#'_u32_from_block_header 1�o^1C#&_first_firmware_block2�
    z
    ^1C#&_next_firmware_block2�
    �
    ^1C#7_custom_meta_data_size_from_meta_data ,�
    �^1C#-_meta_data_firmware_version/��
    ^1C#/_block_address_size_meta_data@4��^1C#+_not_name_nor_custom_data5��
    ^1C#+_handle_meta_data_message6��^1C#(_handle_load_meta_data7�)�^1C#)_handle_flush_meta_data9�6�^1C#B_check_uploaded_firmware_range_against_meta_data:�C�^1C#)_decrypt_firmware_block<�H�^1C#%_check_security_tag.�U�^1C#_expected_type
    �U"#'_initialization_vector�=## _remaining_data!�V$#_data_flushed*�V%# _calculated_crc  �V&
    # _meta_data_size!�V(#&_meta_data_total_size!�V)#*_meta_data_size_announced!�V*#_meta_data�>+##_block_header_size  �V-#_block_headers� ?.#&_block_header_current  �V0#&_block_header_address  �V1#-_block_header_remaining_size  �V2#+_block_header_current_last  �W5#+_block_header_address_last  �W6#'_all_metadata_uploaded*�W8#_auth_tag�<# _crypto_context�
     >#_gcm_init_16$^1C#_$P$T2$1@F �W�#(_gcm_add_auth_data_block&^1C#&_checksum32_uint_fast8 
    ^1C#_gcm_set_iv%^1C#_gcm_flip'^1C#"_gcm_decrypt_block)^1C#_gcm_check_tag+^1C�Pv@r�t�ttt@tEtJtPtntstyt�t�t�t�t�t�LP�(P�L�t�LP�*P�Lt&LP&&P)L:tLLPL*POLbtvLPv6PyL�t�LP�>P�L�t�LP�8P�Lt#t7tKtPtULPU+PXLlt�LP�0P�L�t�LP�6P�L�t�LP�6P�LtLPDPL?t`LP`@PcL�t�LP�@P�L�t�t�ttt#t(NP(P+N7tDPPD8PGPat|RP|PR�t�TP� P�T�t�VP�+P�V�t�XP�(P�X�t�t�t�t�t�t�t�t�t�t�t�t�t�t�t�tttttt%t*t/t5t_tntstyt�t�t�t�t�t�t�t�tt7tTt`tetjt�t�t�t�t�t�t	t&	tE	tX	tZP�PtZZ!t�Z�^P��P�t�^�^�tK^Q^WdPW�PXtjdndrt�t	
    t
    d
    fP
    P
    t3
    f7
    f�
    t�
    ffff$\P$�P%tD\H\Mt�\�pP�=P�tppt�t�t�t�t�ppp`PPt<`@`Et�t�tt4tEtQt]tit�t�t�`�```bP�Pt9b=bBt�t�tt t<tXtlt�t�b�b�b�b�hP�!P�t�h�h�t�t�t�t�t�tt$t7tHt\txt�h�h�h�h�h�h�lP�{P�t,l0l5t�t�tt*tDlJlflllrjPr4Pst�j�j�t3t`t�t�t�t�ttKtqt�j�j�nP��P������n�n�t^ndnLdLd	Ld
    LdLdLdLdLd"Ld'Ld,Ld1Ld6Ld;LdT_LaL]L]L]L]L]L]L]L]L]L]L
    ]L]L]L]V_�_LaL]L]
    L]^_L]L]!R_0L
    ]1X_@T_CL]DL]SL]UL]YL]aL]cP_pLaqL]uV_y�_|La}L]��_�La�L]�L]^_LaL]L]"L](L]+L]@L
    ]DL]JL]M^_SL]V�_YLa[L]X_L]L
    aL
    ]	L]L]d_d_L]d_L]La
    L]L](L]*L].L]7T_<L]?d_EL]I^_Lf_OL]QV_S�_VV_XP_Z�_]La`L]*V_,�_LaL]L]	L]
    L]L]^_L]L]L]L]L]!L]"f_V_R_�_L
    aL
    ]X_d_d_ N_(ZP(P,����0Z@\P@PD����H\X^PX P\����`^x`Px0P|�����`�bP�8P������b�dP�P������d�fP�P�����fhP P����h0jP00P4����8j`lP`Pd����hl|nP|P������n�pP�P������pPT^PT=PW^�ZP�P�Z�\P�P�\�jP�DP�jlP4Pl5`P5�P8`�bP�aP�bGdPGPJd]fP](P`f�hP�uP�h�nP�P�npP PpPt^PP^ZPPZ \P P \(jP(P(j0lP0P0l8`P8P8`@bP@P@bHdPHPHdPfPPPPfXhPXPXh`nP`P`nhpPhPhp��g����/��=��M��c��}���
    ����������������_$P$T2$1&	��=
    ��G��R
    ��a��$C$L1$C$L2'$C$L3.$C$L47$C$L5>$C$L6C$C$L7M$C$L8O$C$L9W$C$L10^$C$L11i$C$L12o$C$L13{$C$L14�$C$L15$C$L166$C$L17B$C$L18F$C$L19H$C$L20M$C$L21Q$C$L22\n��}��$C$L23$C$L24$C$L25$C$L267$C$L27I$C$L28L$C$L29Q$C$L30V$C$L31\$C$L32a$C$L33$C$L34$C$L35$C$L36&$C$L373$C$L38>$C$L39?$C$L40	$C$L41$C$L42$C$L43$$C$L44$C$L45&$C$L46+.text.data.bss.cinit?.ebss��	�
    ��V�
    
     B#U�ub���c�C�&6P-t0%�k:���x&���-�C�6bM��]��m&�c�������������������JTIfHwM0X5Di_expected_type_remaining_data_data_flushed_meta_data_size_meta_data_total_size_meta_data_size_announced_all_metadata_uploaded_block_header_size_block_header_current_block_header_address_block_header_remaining_size_block_header_current_last_block_header_address_last_initialization_vector_auth_tag_meta_data_block_headers_reset_state_read_uint32_t_first_firmware_block.econst:_$P$T2$1.ebss:_initialization_vector.ebss:_auth_tag.ebss:_meta_data.ebss:_crypto_context.ebss:_block_headers.text:_private_key.text:_meta_data_firmware_version.text:_reset_state.text:_handle_meta_data_message.text:_handle_load_meta_data.text:_read_uint32_t.text:_first_firmware_block.text:_handle_flush_meta_data.text:_decrypt_firmware_block.text:_check_uploaded_firmware_range_against_meta_data.text:_check_security_tag.text:_block_address_size_meta_data.debug_line.debug_info.debug_abbrev.debug_aranges_private_key_meta_data_firmware_version_block_address_size_meta_data_decrypt_firmware_block_check_security_tag_handle_meta_data_message_handle_load_meta_data_calculated_crc_crypto_context_check_uploaded_firmware_range_against_meta_data_handle_flush_meta_data_gcm_add_auth_data_block_gcm_set_iv_gcm_init_16_gcm_flip_gcm_decrypt_block_gcm_check_tag_checksum32_uint_fast8$build.attributes.debug_frame

  • Thank you for the test case.  I remain unable to explain what happened.  I used your build options, and added --src_interlist.  This causes the compiler to keep the generated assembly file, and add comments to it which make it easier to understand.  The attachment below is a small part of the assembly file, focused on where the problem occurs.  Please understand I cannot run the code.  I inspect it, starting with presumptions based on your description above.  Among those presumptions is that the function read_uint32 returns 0.  Is that presumption correct?

    Thanks and regards,

    -George

    file.asm

  • Yes, `custom_meta_data_size_from_meta_data()` simply forwards to `read_uint32()`, which returned 0 in the concrete example.

  • Unfortunately, I cannot find any problem with the code generated by the compiler.  The attachment below is similar to the one from last time.  But I added a comment block to the beginning which explains 3 presumptions.  In the assembly instructions, I added comments which always begin ;;; .  Here is an example ...

        MOVZ      AR5,*+XAR4[0]         ; [CPU_ALU] |2284| 
    	;;; AR5 = 4
    

    This means, after that instruction has completed execution, the register AR5 contains the value 4.  It ends with ...

        B         $C$L31,EQ             ; [CPU_ALU] |2284| 
    	;;; Branch taken
    

    But that is not what happens.  This conditional branch is not taken.  Control falls through to the next instruction.  Which is not expected behavior.  This means that, somewhere along the way, these instructions do not do what I describe.  Recall that I cannot execute the code.  But you can.  Please single step through these instructions, and tell me the first point where my comments are wrong.

    Thanks and regards,

    -George

    0181.file.asm

  • Hi George,

    I single stepped through the code and found out, that `read_uint32()` in the end only returns 0, when casted to uint16_t. Without that, the function returns 0x01000000. This function works perfectly find on a PC, with sizeof(uint32_t) == 4, but not on a C2000, where the same expression yields 2, if I'm right.

    static uint32_t custom_meta_data_size_from_meta_data(void)
    {
        size_t size_pos = MIN_META_DATA_SIZE - sizeof( uint32_t );
        assert( meta_data_size == MIN_META_DATA_SIZE );
    
        return read_uint32_t( &meta_data[ size_pos ] );
    }
    

    The only thing, that I'm currently do not understand, is why this worked without optimization. But most likely, I did something stupid on that end too.

    Thank you so much, for your excellent support!

    Best regards

    Torsten

  • I'm not sure what the function custom_meta_data_size_from_meta_data is intended to compute.  But here is one guess at the problem.  Consider what happens when you mix up kilometers and miles.  I suspect something similar is happening between MIN_META_DATA_SIZE and sizeof.  The sizeof operator returns the size of a type, given in terms of the number of char-wide units.  On C28x, a char is 16-bits, thus sizeof(uint32_t) is 2.  Consider changing this to work in terms of bits.  Something like ...

    (MIN_META_DATA_SIZE_IN_BITS - sizeof(uint32_t)*CHAR_BIT)/CHAR_BIT

    The macro CHAR_BIT is defined in the standard header file limits.h.  It is the number of bits in type char.  On most compilers, it is 8.  But on C28x, it is 16.

    Thanks and regards,

    -George

  • Thanks, that is good advice!