pvvx / ATC_MiThermometer

Custom firmware for the Xiaomi Thermometers and Telink Flasher
https://github.com/pvvx/pvvx.github.io/tree/master/ATC_MiThermometer
Other
2.93k stars 205 forks source link

'hci_rx_fifo', 'hci_tx_fifo', 'puts' undefined symbols #348

Closed Ircama closed 1 year ago

Ircama commented 1 year ago

I performed the following commands to compile the firmware using Ubuntu or WSL:

git clone https://github.com/pvvx/ATC_MiThermometer.git
cd ATC_MiThermometer
sudo apt-get update
sudo apt install make
make

The output includes three undefined symbols.

In fact, when running python3 ./src/TlsrMemInfo.py -t ./SDK/tools/linux/tc32/bin/tc32-elf-nm ./out/ATC_T hermometer.elf I get:

TLSR825x MemInfo version 12.11.20
Warning: Undefined symbol 'hci_rx_fifo'!
Warning: Undefined symbol 'hci_tx_fifo'!
Warning: Undefined symbol 'puts'!
===================================================================
 Section|          Description| Start (hex)|   End (hex)|Used space
-------------------------------------------------------------------
 ramcode|   Resident Code SRAM|           0|        59D0|   22992
    text|           Code Flash|        7200|       13780|   50560
  rodata| Read Only Data Flash|       13780|       13D68|    1512
  rtdata|       Retention SRAM|      8459D0|      8471F0|    6176
      nc|   Wasteful Area SRAM|      8471F0|      847200|      16
   ictag|     Cache Table SRAM|      847200|      847300|     256
  icdata|      Cache Data SRAM|      847300|      847B00|    2048
    data|       Init Data SRAM|      847B00|      847B0C|      12
     bss|        BSS Data SRAM|      847B10|      847D51|     577
 irq_stk|        BSS Data SRAM|      847B10|      847C90|     384
   stack|       CPU Stack SRAM|      847D51|      850000|   33455
   flash|       Bin Size Flash|           0|       13D74|   81268
-------------------------------------------------------------------
Start Load SRAM : 29168 (ICtag: 0x7200)
Total Used SRAM : 32081 from 65536
Total Free SRAM : 16 + stack[33455] = 33471

When performing the nm on ATC_Thermometer.elf I get the same three undefined symbols:

./SDK/tools/linux/tc32/bin/tc32-elf-nm ./out/ATC_Thermometer.elf | grep '         U'

Output:

         U hci_rx_fifo
         U hci_tx_fifo
         U puts

The first two look external references required by liblt_8258.a and liblt_8258_rtos.a, while puts might be needed by print.

Why does this happen?

Should we ignore these warnings?

Ircama commented 1 year ago

I think that the puts undefined symbol is because of how u_printf() is implemented.

In fact, editing UART_PRINT_DEBUG_ENABLE to 1 removes the warning because a UART debug function becomes enabled.

./SDK/tools/linux/tc32/bin/tc32-elf-nm -u ./out/ATC_Thermometer.elf
         U hci_rx_fifo
         U hci_tx_fifo

I don't think that enabling this is appropriate (maybe useless) and anyway u_printf() might not be used at all, so the puts undefined symbol could be possibly ignored (or u_printf() can be modified not to call puts() if UART_PRINT_DEBUG_ENABLE is disabled).

pvvx commented 1 year ago

Output:

U hci_rx_fifo
U hci_tx_fifo
U puts

Because they are so declared in blob libraries, but are not used in the current program. To fix it, you need to rebuild liblt_8258.a, but the manufacturer does not provide the source codes of the BLE stack. This is how it is accepted in modern society, without any obvious restrictions. Like a fashion movement :)

Ircama commented 1 year ago

Because they are so declared in blob libraries, but are not used in the current program.

Thanks, good to know they are unused and that the warnings can be ignored.

The Telink SIG Mesh SDK Developer Handbook mentions that "hci_tx_fifo and hci_rx_fifo are fifos to define and transmit data by peripherals, e.g., gateway nodes and gateway firmware USB communication".

There is an example of the definition of hci_rx_fifo and hci_tx_fifo in the Ai-Thinker-Open/Telink_825X_SDK repository.

The warnings disappear if we put that code in app.c, or alternatively if we just put

my_fifo_t hci_rx_fifo;
my_fifo_t hci_tx_fifo;

But this is at the cost of slightly increasing the size of the executable and slightly reducing the free RAM.

pvvx commented 1 year ago

The program that outputs these "warnings" was written by me, purely to increase information. In reality, with a normal build, you will never see these "warnings". Moreover, it is not necessary to designate the type of these variables. The linker is looking for just a name. You can point to an empty space, to an address to nowhere. If this variable was used, the linker could not create the project = returned an error. There are hundreds of "Undefined symbols" in many projects. This suggests that they are incorrectly described in the library.

Enter in boot.link:

    PROVIDE(hci_rx_fifo = .);
    PROVIDE(hci_tx_fifo = .);

Want to get more "Warnings" - add an option to the makefile for 'GCC_FLAGS' -pedantic :)