Skip to content

Commit 05b89e8

Browse files
committed
Revert "Merging code for reading additional file data from info block section."
This reverts commit 8afd8db, reversing changes made to c7da983. Reverting changes from pull-request #62. Issues found in frame size while flashing.
1 parent 8afd8db commit 05b89e8

File tree

5 files changed

+38
-266
lines changed

5 files changed

+38
-266
lines changed

src/libmaxtouch/config.c

+2-42
Original file line numberDiff line numberDiff line change
@@ -507,32 +507,17 @@ static int mxt_load_xcfg_file(struct libmaxtouch_ctx *ctx, const char *filename,
507507

508508
ignore_line = false;
509509

510-
/* Extract the info and checksums */
510+
/* Extract the checksum */
511511
if (!strcmp(object, "VERSION_INFO_HEADER")) {
512512
while (false == ignore_line) {
513513
if (fscanf(fp, "%s", tmp) != 1) {
514514
mxt_err(ctx, "Version info header parse error");
515515
ret = MXT_ERROR_FILE_FORMAT;
516516
goto close;
517517
}
518-
if (!strncmp(tmp, "FAMILY_ID", 9)) {
519-
sscanf(tmp, "%[^'=']=%hhu", object, &cfg->id.family);
520-
mxt_dbg(ctx, "Family ID from file: %s", tmp);
521-
} else if (!strncmp(tmp, "VARIANT", 7)) {
522-
sscanf(tmp, "%[^'=']=%hhu", object, &cfg->id.variant);
523-
mxt_dbg(ctx, "Variant from file: %s", tmp);
524-
} else if (!strncmp(tmp, "VERSION", 7)) {
525-
sscanf(tmp, "%[^'=']=%hhu", object, &cfg->id.version);
526-
mxt_dbg(ctx, "Version from file: %s", tmp);
527-
} else if (!strncmp(tmp, "BUILD", 5)) {
528-
sscanf(tmp, "%[^'=']=%hhu", object, &cfg->id.build);
529-
mxt_dbg(ctx, "Build from file: %s", tmp);
530-
} else if (!strncmp(tmp, "CHECKSUM", 8)) {
518+
if (!strncmp(tmp, "CHECKSUM", 8)) {
531519
sscanf(tmp, "%[^'=']=%x", object, &cfg->config_crc);
532520
mxt_dbg(ctx, "Config CRC from file: %s", tmp);
533-
} else if (!strncmp(tmp, "INFO_BLOCK_CHECKSUM", 19)) {
534-
sscanf(tmp, "%[^'=']=%x", object, &cfg->info_crc);
535-
mxt_dbg(ctx, "Info CRC from file: %s", tmp);
536521
ignore_line = true;
537522
}
538523
}
@@ -889,31 +874,6 @@ int mxt_save_config_file(struct mxt_device *mxt, const char *filename)
889874
return ret;
890875
}
891876

892-
//******************************************************************************
893-
/// \brief Load configuration from .xcfg or RAW file and save to new file in
894-
// .xcfg or RAW format (automatically detect formats)
895-
/// \return #mxt_rc
896-
int mxt_convert_config_file(struct libmaxtouch_ctx *ctx, const char *in_filename, const char *out_filename)
897-
{
898-
int ret;
899-
900-
char *extension = strrchr(out_filename, '.');
901-
struct mxt_config cfg = {{0}};
902-
903-
ret = mxt_get_config_from_file(ctx, in_filename, &cfg);
904-
if (ret)
905-
return ret;
906-
907-
if (extension && !strcmp(extension, ".xcfg"))
908-
ret = mxt_save_xcfg_file(ctx, out_filename, &cfg);
909-
else
910-
ret = mxt_save_raw_file(ctx, out_filename, &cfg);
911-
912-
mxt_free_config(&cfg);
913-
914-
return ret;
915-
}
916-
917877
//******************************************************************************
918878
/// \brief Zero all configuration settings
919879
/// \return #mxt_rc

src/libmaxtouch/libmaxtouch.h

-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ int mxt_calibrate_chip(struct mxt_device *mxt);
196196
int mxt_backup_config(struct mxt_device *mxt, uint8_t backup_command);
197197
int mxt_load_config_file(struct mxt_device *mxt, const char *cfg_file);
198198
int mxt_save_config_file(struct mxt_device *mxt, const char *filename);
199-
int mxt_convert_config_file(struct libmaxtouch_ctx *ctx, const char *in_filename, const char *out_filename);
200199
int mxt_zero_config(struct mxt_device *mxt);
201200
int mxt_get_msg_count(struct mxt_device *mxt, int *count);
202201
char *mxt_get_msg_string(struct mxt_device *mxt);

src/mxt-app/bootloader.c

+33-180
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,6 @@
6464
#define MXT_RESET_TIME 2
6565
#define MXT_BOOTLOADER_DELAY 50000
6666

67-
//******************************************************************************
68-
/// \brief File operation wrapper object
69-
struct file_context {
70-
FILE *fp;
71-
int (*get)(struct file_context *fpc, unsigned char *ptr);
72-
int (*put)(struct file_context *fpc, unsigned char val);
73-
};
74-
7567
//******************************************************************************
7668
/// \brief Bootloader context object
7769
struct flash_context {
@@ -80,7 +72,7 @@ struct flash_context {
8072
struct libmaxtouch_ctx *ctx;
8173
bool have_bootloader_version;
8274
bool extended_id_mode;
83-
struct file_context fpc;
75+
FILE *fp;
8476
long file_size;
8577
char curr_version[MXT_FW_VER_LEN];
8678
int i2c_adapter;
@@ -91,112 +83,6 @@ struct flash_context {
9183
bool usb_bootloader;
9284
};
9385

94-
//******************************************************************************
95-
/// \brief Read value from binary file
96-
static int fpc_get_value(struct file_context *fpc, unsigned char *ptr)
97-
{
98-
int val;
99-
100-
val = fgetc(fpc->fp);
101-
102-
if (feof(fpc->fp)) return EOF;
103-
104-
*ptr = val;
105-
106-
return 0;
107-
}
108-
109-
//******************************************************************************
110-
/// \brief Read hexadecimal value from file
111-
static int fpc_get_hex_value(struct file_context *fpc, unsigned char *ptr)
112-
{
113-
char str[] = "00\0";
114-
int val;
115-
116-
str[0] = fgetc(fpc->fp);
117-
str[1] = fgetc(fpc->fp);
118-
119-
if (feof(fpc->fp)) return EOF;
120-
121-
if (sscanf(str, "%x", &val) != 1) {
122-
return EOF;
123-
}
124-
125-
*ptr = val;
126-
127-
return 0;
128-
}
129-
130-
//******************************************************************************
131-
/// \brief Read value from binary file
132-
static int fpc_put_value(struct file_context *fpc, unsigned char val)
133-
{
134-
fputc(val, fpc->fp);
135-
136-
return ferror(fpc->fp);
137-
}
138-
139-
//******************************************************************************
140-
/// \brief Read hexadecimal value from file
141-
static int fpc_put_hex_value(struct file_context *fpc, unsigned char val)
142-
{
143-
int ret;
144-
145-
ret = fprintf(fpc->fp, "%02hhX", val);
146-
147-
if(ret != 2) {
148-
return ret;
149-
}
150-
151-
return 0;
152-
}
153-
154-
//******************************************************************************
155-
/// \brief Open file in hex format
156-
static int open_hex_file(struct file_context *fpc, const char *filename, const char* mode)
157-
{
158-
fpc->fp = fopen(filename, mode);
159-
if (!fpc->fp) {
160-
return errno;
161-
}
162-
163-
fpc->get = fpc_get_hex_value;
164-
fpc->put = fpc_put_hex_value;
165-
166-
return 0;
167-
}
168-
169-
//******************************************************************************
170-
/// \brief Open binary file
171-
static int open_bin_file(struct file_context *fpc, const char *filename, const char* mode)
172-
{
173-
fpc->fp = fopen(filename, mode);
174-
if (!fpc->fp) {
175-
return errno;
176-
}
177-
178-
fpc->get = fpc_get_value;
179-
fpc->put = fpc_put_value;
180-
181-
return 0;
182-
}
183-
184-
//******************************************************************************
185-
/// \brief Open file in format based on filename
186-
static int open_file(struct file_context *fpc, const char *filename, const char* mode)
187-
{
188-
int ret;
189-
190-
char *extension = strrchr(filename, '.');
191-
192-
if (extension && !strcmp(extension, ".enc"))
193-
ret = open_hex_file(fpc, filename, mode);
194-
else
195-
ret = open_bin_file(fpc, filename, mode);
196-
197-
return ret;
198-
}
199-
20086
//******************************************************************************
20187
/// \brief Wait for CHG line to indicate bootloader state change
20288
/// \return #mxt_rc
@@ -356,6 +242,26 @@ static int mxt_check_bootloader(struct flash_context *fw, unsigned int state)
356242
return MXT_SUCCESS;
357243
}
358244

245+
//******************************************************************************
246+
/// \brief Read hexadecimal value from file
247+
static int get_hex_value(struct flash_context *fw, unsigned char *ptr)
248+
{
249+
char str[] = "00\0";
250+
int val;
251+
int ret;
252+
253+
str[0] = fgetc(fw->fp);
254+
str[1] = fgetc(fw->fp);
255+
256+
if (feof(fw->fp)) return EOF;
257+
258+
ret = sscanf(str, "%x", &val);
259+
260+
*ptr = val;
261+
262+
return ret;
263+
}
264+
359265
//******************************************************************************
360266
/// \brief Send firmware frames to bootloader
361267
/// \return #mxt_rc
@@ -396,14 +302,14 @@ static int send_frames(struct flash_context *fw)
396302

397303
frame = 1;
398304

399-
while (!feof(fw->fpc.fp)) {
305+
while (!feof(fw->fp)) {
400306
if (frame_retry == 0) {
401-
if (fw->fpc.get(&fw->fpc, &buffer[0]) == EOF) {
307+
if (get_hex_value(fw, &buffer[0]) == EOF) {
402308
mxt_info(fw->ctx, "End of file");
403309
break;
404310
}
405311

406-
if (fw->fpc.get(&fw->fpc, &buffer[1]) == EOF) {
312+
if (get_hex_value(fw, &buffer[1]) == EOF) {
407313
mxt_err(fw->ctx, "Unexpected end of firmware file");
408314
return MXT_ERROR_FILE_FORMAT;
409315
}
@@ -421,7 +327,7 @@ static int send_frames(struct flash_context *fw)
421327
}
422328

423329
for (i = 2; i < frame_size; i++) {
424-
ret = fw->fpc.get(&fw->fpc, &buffer[i]);
330+
ret = get_hex_value(fw, &buffer[i]);
425331

426332
if (ret == EOF) {
427333
mxt_err(fw->ctx, "Unexpected end of firmware file");
@@ -459,7 +365,7 @@ static int send_frames(struct flash_context *fw)
459365
frame_retry = 0;
460366
frame++;
461367
bytes_sent += frame_size;
462-
cur_percent = (unsigned char)(0.5f + (100.0 * ftell(fw->fpc.fp)) / fw->file_size);
368+
cur_percent = (unsigned char)(0.5f + (100.0 * ftell(fw->fp)) / fw->file_size);
463369

464370
/* Display at 10% or difference is greater than 10% */
465371
if (cur_percent % 10 == 0 || (cur_percent - last_percent) > 10) {
@@ -477,7 +383,7 @@ static int send_frames(struct flash_context *fw)
477383
}
478384
}
479385

480-
fclose(fw->fpc.fp);
386+
fclose(fw->fp);
481387

482388
return MXT_SUCCESS;
483389
}
@@ -640,59 +546,6 @@ static int mxt_enter_bootloader_mode(struct flash_context *fw)
640546
return MXT_SUCCESS;
641547
}
642548

643-
//******************************************************************************
644-
/// \brief Load firmware from .enc or binary file and save to new file in
645-
// .enc or binary format (automatically detect formats)
646-
/// \return #mxt_rc
647-
int mxt_convert_firmware_file(struct libmaxtouch_ctx *ctx,
648-
const char *in_filename,
649-
const char *out_filename)
650-
{
651-
int ret;
652-
long file_size;
653-
struct file_context in_fpc;
654-
struct file_context out_fpc;
655-
unsigned char val;
656-
657-
mxt_info(ctx, "Opening input firmware file %s", in_filename);
658-
659-
ret = open_file(&in_fpc, in_filename, "r");
660-
if (ret) {
661-
mxt_err(ctx, "Error %d opening %s for input", ret, in_filename);
662-
ret = mxt_errno_to_rc(ret);
663-
goto fail_in;
664-
}
665-
666-
mxt_info(ctx, "Opening output firmware file %s", out_filename);
667-
668-
ret = open_file(&out_fpc, out_filename, "w");
669-
if (ret) {
670-
mxt_err(ctx, "Error %d opening %s for output", ret, out_filename);
671-
ret = mxt_errno_to_rc(ret);
672-
goto fail_out;
673-
}
674-
675-
while (1) {
676-
if (in_fpc.get(&in_fpc, &val) == EOF) {
677-
break;
678-
}
679-
ret = out_fpc.put(&out_fpc, val);
680-
if (ret) {
681-
mxt_err(ctx, "Error %d writing to output", ret);
682-
ret = mxt_errno_to_rc(ret);
683-
break;
684-
}
685-
}
686-
687-
fclose(out_fpc.fp);
688-
689-
fail_out:
690-
fclose(in_fpc.fp);
691-
692-
fail_in:
693-
return ret;
694-
}
695-
696549
//******************************************************************************
697550
/// \brief Flash firmware to chip
698551
int mxt_flash_firmware(struct libmaxtouch_ctx *ctx,
@@ -709,14 +562,14 @@ int mxt_flash_firmware(struct libmaxtouch_ctx *ctx,
709562

710563
mxt_info(fw.ctx, "Opening firmware file %s", filename);
711564

712-
ret = open_file(&fw.fpc, filename, "r");
713-
if (ret) {
565+
fw.fp = fopen(filename, "r");
566+
if (!fw.fp) {
714567
mxt_err(fw.ctx, "Cannot open firmware file %s!", filename);
715-
return mxt_errno_to_rc(ret);
568+
return mxt_errno_to_rc(errno);
716569
}
717-
fseek(fw.fpc.fp, 0L, SEEK_END);
718-
fw.file_size = ftell(fw.fpc.fp);
719-
rewind(fw.fpc.fp);
570+
fseek(fw.fp, 0L, SEEK_END);
571+
fw.file_size = ftell(fw.fp);
572+
rewind(fw.fp);
720573

721574
ret = mxt_bootloader_init_chip(&fw);
722575
if (ret && (ret != MXT_DEVICE_IN_BOOTLOADER))

0 commit comments

Comments
 (0)