Skip to content

Commit

Permalink
Add command to set binary image header layout
Browse files Browse the repository at this point in the history
  • Loading branch information
igrr committed Jul 19, 2016
1 parent 24d8d7f commit 6d8a8bf
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
11 changes: 11 additions & 0 deletions argparse/argparse_binimagecmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ int argparse_binimagecmd(int num_args, char **arg_ptr)
return 0;
}
return 2;

case 'l':
if (num_args < 1)
{
return 0;
}
if (binimage_set_header_layout(arg_ptr[0]) == 0)
{
return 0;
}
return 2;

default:
return 0;
Expand Down
40 changes: 39 additions & 1 deletion binimage/esptool_binimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@
#include "infohelper.h"
#include "esptool_binimage.h"

typedef enum { HL_ESP8266, HL_ESP32BOOT, HL_ESP32 } binimage_header_layout_t;

static bin_image b_image = {
.magic = 0xe9,
.num_segments = 0,
.flash_mode = FLASH_MODE_QIO,
.flash_size_freq = FLASH_SIZE_512K | FLASH_FREQ_40
};

unsigned int total_size = 0;
static unsigned int total_size = 0;
static binimage_header_layout_t header_layout = HL_ESP8266;


int binimage_add_segment(uint32_t address, uint32_t size, unsigned char *data)
{
Expand Down Expand Up @@ -139,6 +143,22 @@ int binimage_write(uint32_t padsize, bool close)
}

total_size = 8;

if (header_layout == HL_ESP32BOOT)
{
LOGDEBUG("adding extra header for ESP32 boot image");
uint8_t extra_header[16];
// TODO: replace this dummy 16 byte array with the actual flash_extN_config_hdr structures
memset(extra_header, 0, sizeof(extra_header));
if(fwrite(extra_header, 1, sizeof(extra_header), b_image.image_file) != sizeof(extra_header))
{
LOGERR("cant write extra header to binimage file, aborting");
fclose(b_image.image_file);
b_image.image_file = 0;
return 0;
}
total_size += sizeof(extra_header);
}

for(cnt = 0; cnt < b_image.num_segments; cnt++)
{
Expand Down Expand Up @@ -377,3 +397,21 @@ const char* binimage_flash_freq_to_str(unsigned char freq)
}
}

int binimage_set_header_layout(const char* layout)
{
LOGDEBUG("setting header layout to %s", layout);
if (strcasecmp(layout, "esp32boot") == 0) {
header_layout = HL_ESP32BOOT;
return 1;
}
else if (strcasecmp(layout, "esp8266") == 0) {
header_layout = HL_ESP8266;
return 1;
}
else if (strcasecmp(layout, "esp32")) {
header_layout = HL_ESP32;
}
LOGERR("invalid image header layout: %s", layout);
return 0;
}

2 changes: 1 addition & 1 deletion binimage/esptool_binimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ int binimage_add_segment(uint32_t address, uint32_t size, unsigned char *data);
int binimage_set_flash_mode(const char* mode);
int binimage_set_flash_size(const char* size);
int binimage_set_flash_freq(const char* freq);

int binimage_set_header_layout(const char* layout);

#endif

0 comments on commit 6d8a8bf

Please sign in to comment.