void libmem_rpc_loader_exit(int result,
                            const char *error);

result — A LIBMEM status result.

error — Pointer to optional error string or NULL if not required.

This function provides a way of signalling to the host that the loader program has completed and also allows the loader to return an exit code and optional error string. Note that this function should only be used in conjunction with libmem_rpc_loader_start() and that any code located after the call to libmem_rpc_loader_exit() has been made will not be executed.

The error parameter can be used to describe an error not covered by the LIBMEM status results. To use it, set result to LIBMEM_STATUS_ERROR and error to the error string to be displayed.

The following example demonstrates how to return user defined error messages from the loader and how code can be executed after the loader server has terminated prior to the loader program exiting:

static unsigned char buffer[256];

int initialise()
  ... initialisation code ...

int deinitialise()
  ... deinitialisation code ...

int main(void)
  uint8_t *flash1_start = (uint8_t *)0x10000000;
  const int flash1_max_geometry_regions = 4;
  libmem_driver_handle_t flash1_handle;
  libmem_geometry_t flash1_geometry[flash1_max_geometry_regions];
  libmem_flash_info_t flash1_info;
  int res;
  const char *error = 0;

  if (initialise())
      // Register FLASH driver.
      res = libmem_register_cfi_driver(&flash1_handle, 

      if (res == LIBMEM_STATUS_SUCCESS)
          // Run the loader 
          libmem_rpc_loader_start(buffer, buffer + sizeof(buffer) - 1);
     error = "cannot initialise loader";

 if (!deinitialise() && res == LIBMEM_STATUS_SUCCESS)
     error = "cannot deinitialise loader";

  libmem_rpc_loader_exit(res, NULL);

  return 0;