The aim of the LIBMEM loader library is to be an add on to the LIBMEM library that simplifies the writing of loader applications.

To write a loader application all you need to do is register the LIBMEM drivers you require and then call the appropriate loader start function for the communication mechanism you wish to use.

For example, the following code is an example of a LIBMEM loader, it registers one LIBMEM FLASH driver, if the driver is successfully registered it starts up the loader by calling libmem_rpc_loader_start. Finally it tells the host that the loader has finished by calling libmem_rpc_loader_exit.

static unsigned char buffer[256];

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;

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

      // Run the loader 
      libmem_rpc_loader_start(buffer, buffer + sizeof(buffer) - 1);
  libmem_rpc_loader_exit(res, NULL);

  return 0;

Essentially, a LIBMEM loader is just a standard RAM-based application that registers the LIBMEM drivers required by the loader and then calls the appropriate loader start function for the communication mechanism being used.

A significant difference between LIBMEM loader applications and regular applications is that once the loader start function is called it is no longer possible to debug the application using the debugger. Therefore if you need to debug your loader application using the debugger you can do it by simply adding calls to the functions you wish to debug in place of the loader start call.