Skip to content

Commit

Permalink
FEATURE: leave out cell/short-range/gnss as required. (#754)
Browse files Browse the repository at this point in the history
It is now possible for an application to leave out one or more of cell, short-range or GNSS from a build.  This is done through the common ubxlib.mk and ubxlib.cmake files: simply change the make/CMake variable UBXLIB_FEATURES that you supply to that file from "cell short_range gnss" to "cell", or "short_range", or "gnss", or "cell gnss", or "cell short_range", whatever, and only the portions you specify will be included, saving flash and static RAM.

If you have your own build system then make sure to bring in all of the "stub" files that this commit introduces, then you may remove .c files from whichever area, cell/short_range/gnss/ble/wifi, is unused and the ubxlib code should still compile/run but now with reduced footprint.

Note about ESP-IDF linker: there is a bug/feature of the Espressif linker (discussed here: https://www.esp32.com/viewtopic.php?f=13&t=8418&p=35899), which is that if a .c file turns out to have no external linkage because all of the functions in that file happen to have WEAK counterparts, then the linker will entirely ignore the .c file and use the WEAK versions instead, which is not what you want at all.  The workaround is to introduce a dummy function into such a .c file, one that has no WEAK counterpart, and make sure it is called from somewhere.  You will see uXxxPrivateLink() (e.g. uGnssPosPrivateLink()) dummy functions spread throughout the files that contain functions that have WEAK stub versions, that function being called from the init function (e.g. uGnssInit()) so that there is definitely something in those .c files to keep the linker engaged.
  • Loading branch information
RobMeades committed Jan 5, 2023
1 parent 9f98476 commit bf8cd21
Show file tree
Hide file tree
Showing 79 changed files with 2,946 additions and 299 deletions.
15 changes: 15 additions & 0 deletions ble/src/u_ble_extmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
#include "u_ble.h"
#include "u_ble_private.h"

// The headers below are necessary to work around an Espressif linker problem, see uBleInit()
#include "u_network.h"
#include "u_network_config_ble.h"
#include "u_network_private_ble.h"

/* ----------------------------------------------------------------
* COMPILE-TIME MACROS
* -------------------------------------------------------------- */
Expand All @@ -67,6 +72,16 @@
// Initialise the ble driver.
int32_t uBleInit(void)
{
// Workaround for Espressif linker missing out files that
// only contain functions which also have weak alternatives
// (see https://www.esp32.com/viewtopic.php?f=13&t=8418&p=35899)
// Basically any file that might end up containing only functions
// that also have WEAK linked counterparts will be lost, so we need
// to add a dummy function in those files and call it from somewhere
// that will always be present in the build, which for BLE we
// choose to be here
uNetworkPrivateBleLink();

uBleSpsPrivateInit();
return uShortRangeInit();
}
Expand Down
12 changes: 12 additions & 0 deletions cell/api/u_cell_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ typedef void (uCellHttpCallback_t) (uDeviceHandle_t cellHandle,
const char *pFileNameResponse,
void *pCallbackParam);

/* ----------------------------------------------------------------
* FUNCTIONS: WORKAROUND FOR LINKER ISSUE
* -------------------------------------------------------------- */

/** Workaround for Espressif linker missing out files that
* only contain functions which also have weak alternatives
* (see https://www.esp32.com/viewtopic.php?f=13&t=8418&p=35899).
*
* You can ignore this function.
*/
void uCellHttpPrivateLink(void);

/* ----------------------------------------------------------------
* FUNCTIONS
* -------------------------------------------------------------- */
Expand Down
12 changes: 12 additions & 0 deletions cell/api/u_cell_loc.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ extern "C" {
* TYPES
* -------------------------------------------------------------- */

/* ----------------------------------------------------------------
* FUNCTIONS: WORKAROUND FOR LINKER ISSUE
* -------------------------------------------------------------- */

/** Workaround for Espressif linker missing out files that
* only contain functions which also have weak alternatives
* (see https://www.esp32.com/viewtopic.php?f=13&t=8418&p=35899).
*
* You can ignore this function.
*/
void uCellLocPrivateLink(void);

/* ----------------------------------------------------------------
* FUNCTIONS: MISC
* -------------------------------------------------------------- */
Expand Down
11 changes: 11 additions & 0 deletions cell/api/u_cell_mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ typedef struct {
// *INDENT-ON*
} uCellMqttSnTopicName_t;

/* ----------------------------------------------------------------
* FUNCTIONS: WORKAROUND FOR LINKER ISSUE
* -------------------------------------------------------------- */

/** Workaround for Espressif linker missing out files that
* only contain functions which also have weak alternatives
* (see https://www.esp32.com/viewtopic.php?f=13&t=8418&p=35899).
*
* You can ignore this function.
*/
void uCellMqttPrivateLink(void);

/* ----------------------------------------------------------------
* FUNCTIONS: MQTT AND MQTT-SN
Expand Down
12 changes: 12 additions & 0 deletions cell/api/u_cell_sec.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ extern "C" {
* TYPES
* -------------------------------------------------------------- */

/* ----------------------------------------------------------------
* FUNCTIONS: WORKAROUND FOR LINKER ISSUE
* -------------------------------------------------------------- */

/** Workaround for Espressif linker missing out files that
* only contain functions which also have weak alternatives
* (see https://www.esp32.com/viewtopic.php?f=13&t=8418&p=35899).
*
* You can ignore this function.
*/
void uCellSecPrivateLink(void);

/* ----------------------------------------------------------------
* FUNCTIONS: INFORMATION
* -------------------------------------------------------------- */
Expand Down
12 changes: 12 additions & 0 deletions cell/api/u_cell_sec_tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ typedef struct {
at the end to improve structure packing. */
} uCellSecTlsContext_t;

/* ----------------------------------------------------------------
* FUNCTIONS: WORKAROUND FOR LINKER ISSUE
* -------------------------------------------------------------- */

/** Workaround for Espressif linker missing out files that
* only contain functions which also have weak alternatives
* (see https://www.esp32.com/viewtopic.php?f=13&t=8418&p=35899).
*
* You can ignore this function.
*/
void uCellSecTlsPrivateLink(void);

/* ----------------------------------------------------------------
* FUNCTIONS: ADD/REMOVE A TLS SECURITY CONTEXT
* -------------------------------------------------------------- */
Expand Down
12 changes: 12 additions & 0 deletions cell/api/u_cell_sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ extern "C" {
* TYPES
* -------------------------------------------------------------- */

/* ----------------------------------------------------------------
* FUNCTIONS: WORKAROUND FOR LINKER ISSUE
* -------------------------------------------------------------- */

/** Workaround for Espressif linker missing out files that
* only contain functions which also have weak alternatives
* (see https://www.esp32.com/viewtopic.php?f=13&t=8418&p=35899).
*
* You can ignore this function.
*/
void uCellSockPrivateLink(void);

/* ----------------------------------------------------------------
* FUNCTIONS: INIT/DEINIT
* -------------------------------------------------------------- */
Expand Down
31 changes: 31 additions & 0 deletions cell/src/u_cell.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@
#include "u_cell_net.h" // important here
#include "u_cell_private.h" // don't change it

// The headers below necessary to work around an Espressif linker problem, see uCellInit()
#include "u_device_private_cell.h"
#include "u_network.h"
#include "u_network_config_cell.h"
#include "u_network_private_cell.h"
#include "u_sock.h"
#include "u_cell_sock.h" // For uCellSockPrivateLink()
#include "u_cell_sec.h" // For uCellSecPrivateLink()
#include "u_cell_sec_tls.h" // For uCellSecTlsPrivateLink()
#include "u_cell_mqtt.h" // For uCellMqttPrivateLink()
#include "u_cell_http.h" // For uCellHttpPrivateLink()
#include "u_cell_loc.h" // For uCellLocPrivateLink()

/* ----------------------------------------------------------------
* COMPILE-TIME MACROS
* -------------------------------------------------------------- */
Expand Down Expand Up @@ -145,6 +158,24 @@ int32_t uCellInit()
{
int32_t errorCode = (int32_t) U_ERROR_COMMON_SUCCESS;

// Workaround for Espressif linker missing out files that
// only contain functions which also have weak alternatives
// (see https://www.esp32.com/viewtopic.php?f=13&t=8418&p=35899).
// Basically any file that might end up containing only functions
// that also have WEAK linked counterparts will be lost, so we need
// to add a dummy function in those files and call it from somewhere
// that will always be present in the build, which for cellular we
// choose to be here
uDevicePrivateCellLink();
uNetworkPrivateCellLink();
uCellSockPrivateLink();
uCellSecPrivateLink();
uCellSecTlsPrivateLink();
uCellMqttPrivateLink();
uCellHttpPrivateLink();
uCellLocPrivateLink();


if (gUCellPrivateMutex == NULL) {
// Create the mutex that protects the linked list
errorCode = uPortMutexCreate(&gUCellPrivateMutex);
Expand Down
9 changes: 9 additions & 0 deletions cell/src/u_cell_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,15 @@ static void UUHTTPCR_urc(uAtClientHandle_t atHandle, void *pParameter)

}

/* ----------------------------------------------------------------
* PUBLIC FUNCTIONS: WORKAROUND FOR LINKER ISSUE
* -------------------------------------------------------------- */

void uCellHttpPrivateLink()
{
//dummy
}

/* ----------------------------------------------------------------
* PUBLIC FUNCTIONS
* -------------------------------------------------------------- */
Expand Down
9 changes: 9 additions & 0 deletions cell/src/u_cell_loc.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,15 @@ static int32_t beginLocationFix(const uCellPrivateInstance_t *pInstance)
return errorCode;
}

/* ----------------------------------------------------------------
* PUBLIC FUNCTIONS: WORKAROUND FOR LINKER ISSUE
* -------------------------------------------------------------- */

void uCellLocPrivateLink()
{
//dummy
}

/* ----------------------------------------------------------------
* PUBLIC FUNCTIONS: MISC
* -------------------------------------------------------------- */
Expand Down
9 changes: 9 additions & 0 deletions cell/src/u_cell_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,15 @@ static int32_t readMessage(const uCellPrivateInstance_t *pInstance,
return errorCode;
}

/* ----------------------------------------------------------------
* PUBLIC FUNCTIONS: WORKAROUND FOR LINKER ISSUE
* -------------------------------------------------------------- */

void uCellMqttPrivateLink()
{
//dummy
}

/* ----------------------------------------------------------------
* PUBLIC FUNCTIONS: MQTT AND MQTT-SN
* -------------------------------------------------------------- */
Expand Down
9 changes: 9 additions & 0 deletions cell/src/u_cell_sec.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,15 @@ static size_t encryptC2cConfirmationTag(const char *pC2cConfirmationTagHex,
return length;
}

/* ----------------------------------------------------------------
* PUBLIC FUNCTIONS: WORKAROUND FOR LINKER ISSUE
* -------------------------------------------------------------- */

void uCellSecPrivateLink()
{
//dummy
}

/* ----------------------------------------------------------------
* PUBLIC FUNCTIONS: INFORMATION
* -------------------------------------------------------------- */
Expand Down
9 changes: 9 additions & 0 deletions cell/src/u_cell_sec_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,15 @@ static int32_t setGeneratePsk(const uCellSecTlsContext_t *pContext,
return errorCode;
}

/* ----------------------------------------------------------------
* PUBLIC FUNCTIONS: WORKAROUND FOR LINKER ISSUE
* -------------------------------------------------------------- */

void uCellSecTlsPrivateLink()
{
//dummy
}

/* ----------------------------------------------------------------
* PUBLIC FUNCTIONS: ADD/REMOVE A TLS SECURITY CONTEXT
* -------------------------------------------------------------- */
Expand Down
9 changes: 9 additions & 0 deletions cell/src/u_cell_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,15 @@ static int32_t doUsoctl(uDeviceHandle_t cellHandle, int32_t sockHandle,
return negErrnoLocallOrValue;
}

/* ----------------------------------------------------------------
* PUBLIC FUNCTIONS: WORKAROUND FOR LINKER ISSUE
* -------------------------------------------------------------- */

void uCellSockPrivateLink()
{
//dummy
}

/* ----------------------------------------------------------------
* PUBLIC FUNCTIONS: INIT/DEINIT
* -------------------------------------------------------------- */
Expand Down
95 changes: 95 additions & 0 deletions common/at_client/src/u_at_client_stub_short_range.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright 2019-2022 u-blox
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/** @file
* @brief Stubs to allow the AT client to compile without short-range.
*/

#ifdef U_CFG_OVERRIDE
# include "u_cfg_override.h" // For a customer's configuration override
#endif

#include "stddef.h" // NULL, size_t etc.
#include "stdint.h" // int32_t etc.
#include "stdbool.h"

#include "u_compiler.h" // U_WEAK
#include "u_error_common.h"
#include "u_short_range_pbuf.h"
#include "u_short_range_module_type.h"
#include "u_short_range.h"
#include "u_short_range_edm_stream.h"

/* ----------------------------------------------------------------
* PUBLIC FUNCTIONS
* -------------------------------------------------------------- */

//lint -esym(593, pParam) Suppress pParam not being freed here
U_WEAK int32_t uShortRangeEdmStreamAtCallbackSet(int32_t handle,
uEdmAtEventCallback_t pFunction,
void *pParam)
{
(void) handle;
(void) pFunction;
(void) pParam;
return (int32_t) U_ERROR_COMMON_NOT_SUPPORTED;
}

U_WEAK void uShortRangeEdmStreamAtCallbackRemove(int32_t handle)
{
(void) handle;
}

U_WEAK void uShortRangeEdmStreamIpEventCallbackRemove(int32_t handle)
{
(void) handle;
}

U_WEAK int32_t uShortRangeEdmStreamAtRead(int32_t handle, void *pBuffer,
size_t sizeBytes)
{
(void) handle;
(void) pBuffer;
(void) sizeBytes;
return (int32_t) U_ERROR_COMMON_NOT_SUPPORTED;
}

U_WEAK int32_t uShortRangeEdmStreamAtEventSend(int32_t handle, uint32_t eventBitMap)
{
(void) handle;
(void) eventBitMap;
return (int32_t) U_ERROR_COMMON_NOT_SUPPORTED;
}

U_WEAK bool uShortRangeEdmStreamAtEventIsCallback(int32_t handle)
{
(void) handle;
return false;
}

U_WEAK int32_t uShortRangeEdmStreamAtEventStackMinFree(int32_t handle)
{
(void) handle;
return (int32_t) U_ERROR_COMMON_NOT_SUPPORTED;
}

U_WEAK int32_t uShortRangeEdmStreamAtGetReceiveSize(int32_t handle)
{
(void) handle;
return (int32_t) U_ERROR_COMMON_NOT_SUPPORTED;
}

// End of file

0 comments on commit bf8cd21

Please sign in to comment.