Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Photon/P1] WiFi firmware blob compression #1421

Merged
merged 6 commits into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions hal/src/photon/compressed_resources.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "wiced_resource.h"
#include "platform_resource.h"
#include "miniz.h"
#include <stddef.h>
#include "debug.h"

__attribute__((weak)) resource_result_t platform_read_external_resource( const resource_hnd_t* resource, uint32_t offset, uint32_t maxsize, uint32_t* size, void* buffer ) {
static size_t in_pos = 0;
static tinfl_decompressor* inflator = NULL;
tinfl_status status = TINFL_STATUS_FAILED;
resource_result_t res = RESOURCE_FILE_READ_FAIL;

if (offset == 0) {
if (inflator == NULL) {
inflator = (tinfl_decompressor*)malloc(sizeof(tinfl_decompressor));
}
tinfl_init(inflator);
in_pos = 0;
}

if (inflator == NULL) {
*size = 0;
return res;
}

size_t avail_out = maxsize;
size_t out_pos = 0;

for(;;) {
size_t in_bytes = resource->val.comp.size - in_pos;
size_t out_bytes = avail_out;

status = tinfl_decompress(inflator, (const mz_uint8*)resource->val.comp.data + in_pos, &in_bytes, (mz_uint8*)buffer, (mz_uint8*)buffer + out_pos, &out_bytes, (in_bytes > 0 ? TINFL_FLAG_HAS_MORE_INPUT : 0) | 0);
in_pos += in_bytes;
out_pos += out_bytes;
avail_out -= out_bytes;

if ((status <= TINFL_STATUS_DONE) || (!avail_out)) {
// Output buffer is full or decompression is done
*size = out_pos;
res = RESOURCE_SUCCESS;
if (status != TINFL_STATUS_DONE) {
return res;
} else {
goto cleanup;
}
}

if (status <= TINFL_STATUS_DONE) {
res = RESOURCE_FILE_READ_FAIL;
goto cleanup;
}
}
cleanup:
if (inflator != NULL) {
free(inflator);
inflator = NULL;
}
in_pos = 0;
return res;
}
6 changes: 6 additions & 0 deletions hal/src/photon/include/wiced_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ typedef struct
/*@shared@*/ const char* filename;
} filesystem_resource_handle_t;

typedef struct
{
const char* data;
unsigned long size;
} compressed_resource_handle_t;

typedef enum
{
Expand All @@ -114,6 +119,7 @@ typedef struct
filesystem_resource_handle_t fs;
memory_resource_handle_t mem;
void* external_storage_context;
compressed_resource_handle_t comp;
} val;
} resource_hnd_t;

Expand Down
Binary file modified hal/src/photon/lib/FreeRTOS/STM32F2xx.a
Binary file not shown.
Binary file modified hal/src/photon/lib/FreeRTOS/WWD_for_SDIO_FreeRTOS.a
Binary file not shown.
Binary file modified hal/src/photon/lib/resources.a
Binary file not shown.
Loading