Skip to content

Commit df046ab

Browse files
committed
RAW data reading mode framework
Sometime the utility unable to check EEPROM/OTP contents. In particular, this could be caused, for example, by a conntents corruption or a missed template in the decompression algorithm. The utility declined any handling of data if they looked inconsistent. The readed data saving will be rejected as well in case of a failed check. But sometimes it is desireable to do just our best and at least save the extracted data as it is. E.g. for a partial audit, data consistency recovery, or simply for further utility development in a relaxed and more comfortable environment. So add a capability to save the read RAW data as-is. Without any checks and even without I/O byteswapping. This change introduces only the RAW data saving framework: new commands, new code execution paths that bypass checks, and a set of flags indicating whether a particular format handler is capable to fetch data without any preprocessing. Per-format support for the RAW data loading will be introduces by the following changes. Refs: gh-4, gh-6
1 parent e328345 commit df046ab

File tree

8 files changed

+87
-12
lines changed

8 files changed

+87
-12
lines changed

atheepmgr.c

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@ static int act_reg_write(struct atheepmgr *aem, int argc, char *argv[])
607607
#define ACT_F_DATA (1 << 0) /* Action will interact with EEPROM/OTP data */
608608
#define ACT_F_HW (1 << 1) /* Action require direct HW access */
609609
#define ACT_F_AUTONOMOUS (1 << 2) /* Action do not require input data or HW */
610+
#define ACT_F_RAW_EEP (1 << 3) /* Action needs only raw EEPROM contents */
611+
#define ACT_F_RAW_OTP (1 << 4) /* Action needs only raw OTP contents */
612+
#define ACT_F_RAW_DATA (ACT_F_RAW_EEP | ACT_F_RAW_OTP)
610613

611614
static const struct action {
612615
const char *name;
@@ -621,6 +624,18 @@ static const struct action {
621624
.name = "save",
622625
.func = act_eep_save,
623626
.flags = ACT_F_DATA,
627+
}, {
628+
.name = "saveraw",
629+
.func = act_eep_save,
630+
.flags = ACT_F_DATA | ACT_F_RAW_EEP | ACT_F_RAW_OTP,
631+
}, {
632+
.name = "saveraweep",
633+
.func = act_eep_save,
634+
.flags = ACT_F_DATA | ACT_F_RAW_EEP,
635+
}, {
636+
.name = "saverawotp",
637+
.func = act_eep_save,
638+
.flags = ACT_F_DATA | ACT_F_RAW_OTP,
624639
}, {
625640
.name = "unpack",
626641
.func = act_eep_unpack,
@@ -735,6 +750,8 @@ static void usage_eepmap_chips(const struct eepmap *eepmap)
735750
static void usage_eepmap(struct atheepmgr *aem, const struct eepmap *eepmap)
736751
{
737752
const struct eepmap_param *param;
753+
bool raw_eep = eepmap->features & EEPMAP_F_RAW_EEP;
754+
bool raw_otp = eepmap->features & EEPMAP_F_RAW_OTP;
738755
char buf[0x100];
739756
int i;
740757

@@ -745,6 +762,9 @@ static void usage_eepmap(struct atheepmgr *aem, const struct eepmap *eepmap)
745762

746763
usage_eepmap_chips(eepmap);
747764

765+
printf("%18sSupport for RAW contents saving: %s\n", "",
766+
raw_eep || raw_otp ? "EEPROM, OTP" :
767+
raw_eep ? "EEPROM" : raw_otp ? "OTP" : "none");
748768
printf("%18sSupport for unpacked data saving: %s\n", "",
749769
eepmap->unpacked_buf_sz ? "Yes" : "No");
750770
printf("%18s%s:\n", "", "Supported sections for dumping");
@@ -851,6 +871,14 @@ static void usage(struct atheepmgr *aem, char *name)
851871
" The default action behaviour is to print the contents of all\n"
852872
" supported EEPROM sections.\n"
853873
" save <file> Save fetched raw EEPROM content to the file <file>.\n"
874+
" saveraw <file> Save the raw contents of the EEPROM or OTP mem without any\n"
875+
" pre-checks to the file <file>. This option is useful when the\n"
876+
" data is corrupted or the utility is unable to verify the data\n"
877+
" due to some internal issues.\n"
878+
" saveraweep <file> Same as 'saveraw', but saves only the EEPROM contents\n"
879+
" without any other (e.g. OTP) memory types access.\n"
880+
" saverawotp <file> Same as 'saveraw', but saves only the OTP mem contents\n"
881+
" without any other (e.g. EEPROM) memory types access.\n"
854882
" unpack <file> Save unpacked EEPROM/OTP data to the file <file>. Saved data\n"
855883
" type depends on EEPROM map type, usually only calibration\n"
856884
" data are saved.\n"
@@ -868,6 +896,7 @@ static void usage(struct atheepmgr *aem, char *name)
868896
"Available actions (use -v option to see details):\n"
869897
" dump [<sects>] Read & dump parsed EEPROM content to the terminal.\n"
870898
" save <file> Save fetched raw EEPROM content to the file <file>.\n"
899+
/* NB: 'saveraw' intentionally skipped to keep usage short. */
871900
" unpack <file> Save unpacked EEPROM/OTP calibration data to the file <file>.\n"
872901
" update <param>[=<val>] Set EEPROM parameter <param> to <val>.\n"
873902
/* NB: 'templateexport' intentionally skipped to keep usage short. */
@@ -1044,6 +1073,22 @@ int main(int argc, char *argv[])
10441073
aem->eepmap = user_eepmap;
10451074
}
10461075

1076+
if (act->flags & ACT_F_RAW_DATA) {
1077+
ret = -EINVAL;
1078+
if ((act->flags & ACT_F_RAW_DATA) == ACT_F_RAW_EEP &&
1079+
!(aem->eepmap->features & EEPMAP_F_RAW_EEP))
1080+
fprintf(stderr, "EEPROM map does not support RAW EEPROM contents loading\n");
1081+
else if ((act->flags & ACT_F_RAW_DATA) == ACT_F_RAW_OTP &&
1082+
!(aem->eepmap->features & EEPMAP_F_RAW_OTP))
1083+
fprintf(stderr, "EEPROM map does not support RAW OTP contents loading\n");
1084+
else if (!(aem->eepmap->features & EEPMAP_F_RAW_DATA))
1085+
fprintf(stderr, "EEPROM map does not support any RAW data loading\n");
1086+
else
1087+
ret = 0;
1088+
if (ret)
1089+
goto con_clean;
1090+
}
1091+
10471092
if (aem->con->caps & CON_CAP_HW) {
10481093
ret = hw_init(aem);
10491094
if (ret)
@@ -1087,6 +1132,27 @@ int main(int argc, char *argv[])
10871132
}
10881133
}
10891134

1135+
if (act->flags & ACT_F_RAW_EEP &&
1136+
aem->eepmap->features & EEPMAP_F_RAW_EEP &&
1137+
aem->eep && aem->eepmap->load_eeprom) {
1138+
tries++;
1139+
if (aem->verbose > 1)
1140+
printf("Try to load RAW EEPROM data\n");
1141+
if (aem->eepmap->load_eeprom(aem, true))
1142+
goto loading_done;
1143+
}
1144+
if (act->flags & ACT_F_RAW_OTP &&
1145+
aem->eepmap->features & EEPMAP_F_RAW_OTP &&
1146+
aem->otp && aem->eepmap->load_otp) {
1147+
tries++;
1148+
if (aem->verbose > 1)
1149+
printf("Try to load RAW OTP data\n");
1150+
if (aem->eepmap->load_otp(aem, true))
1151+
goto loading_done;
1152+
}
1153+
if (act->flags & ACT_F_RAW_DATA)
1154+
goto no_data;
1155+
10901156
if (aem->con->blob && aem->eepmap->load_blob) {
10911157
tries++;
10921158
if (aem->verbose > 1)
@@ -1098,17 +1164,18 @@ int main(int argc, char *argv[])
10981164
tries++;
10991165
if (aem->verbose > 1)
11001166
printf("Try to load data from EEPROM\n");
1101-
if (aem->eepmap->load_eeprom(aem))
1167+
if (aem->eepmap->load_eeprom(aem, false))
11021168
goto loading_done;
11031169
}
11041170
if (aem->otp && aem->eepmap->load_otp) {
11051171
tries++;
11061172
if (aem->verbose > 1)
11071173
printf("Try to load data from OTP memory\n");
1108-
if (aem->eepmap->load_otp(aem))
1174+
if (aem->eepmap->load_otp(aem, false))
11091175
goto loading_done;
11101176
}
11111177

1178+
no_data:
11121179
if (tries) {
11131180
fprintf(stderr, "Unable to load data from any sources\n");
11141181
ret = -EIO;
@@ -1119,7 +1186,8 @@ int main(int argc, char *argv[])
11191186
goto con_clean;
11201187

11211188
loading_done:
1122-
if (!aem->eepmap->check_eeprom(aem)) {
1189+
if (!(act->flags & ACT_F_RAW_DATA) &&
1190+
!aem->eepmap->check_eeprom(aem)) {
11231191
fprintf(stderr, "EEPROM check failed\n");
11241192
ret = -EINVAL;
11251193
goto con_clean;

atheepmgr.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ struct connector {
190190
const struct otp_ops *otp;
191191
};
192192

193+
enum eepmap_feature {
194+
EEPMAP_F_RAW_EEP = 1 << 0, /* Support RAW EEPROM loading */
195+
EEPMAP_F_RAW_OTP = 1 << 1, /* Support RAW OTP mem loading */
196+
};
197+
#define EEPMAP_F_RAW_DATA (EEPMAP_F_RAW_EEP | EEPMAP_F_RAW_OTP)
198+
193199
enum eepmap_section_id {
194200
EEP_SECT_INIT,
195201
EEP_SECT_BASE,
@@ -214,6 +220,7 @@ struct eeptemplate {
214220
struct eepmap {
215221
const char *name;
216222
const char *desc;
223+
int features; /* Supported features */
217224
struct chip_regs {
218225
uint32_t srev;
219226
} chip_regs;
@@ -222,8 +229,8 @@ struct eepmap {
222229
size_t unpacked_buf_sz; /* Buffer size for unpacked data */
223230
const struct eeptemplate *templates; /* NULL terminated list */
224231
bool (*load_blob)(struct atheepmgr *aem);
225-
bool (*load_eeprom)(struct atheepmgr *aem);
226-
bool (*load_otp)(struct atheepmgr *aem);
232+
bool (*load_eeprom)(struct atheepmgr *aem, bool raw);
233+
bool (*load_otp)(struct atheepmgr *aem, bool raw);
227234
int (*check_eeprom)(struct atheepmgr *aem);
228235
void (*dump[EEP_SECT_MAX])(struct atheepmgr *aem);
229236
bool (*update_eeprom)(struct atheepmgr *aem, int param,

eep_5211.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ static void eep_5211_fill_ctl_data_33(struct atheepmgr *aem)
922922
}
923923
}
924924

925-
static bool eep_5211_load_eeprom(struct atheepmgr *aem)
925+
static bool eep_5211_load_eeprom(struct atheepmgr *aem, bool raw)
926926
{
927927
struct eep_5211_priv *emp = aem->eepmap_priv;
928928
struct ar5211_eeprom *eep = &emp->eep;

eep_5416.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static int eep_5416_get_rev(struct eep_5416_priv *emp)
3838
return ((emp->eep.baseEepHeader.version) & 0xFFF);
3939
}
4040

41-
static bool eep_5416_load_eeprom(struct atheepmgr *aem)
41+
static bool eep_5416_load_eeprom(struct atheepmgr *aem, bool raw)
4242
{
4343
struct eep_5416_priv *emp = aem->eepmap_priv;
4444
uint16_t *eep_data = (uint16_t *)&emp->eep;

eep_9285.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static int eep_9285_get_rev(struct eep_9285_priv *emp)
3838
return ((emp->eep.baseEepHeader.version) & 0xFFF);
3939
}
4040

41-
static bool eep_9285_load_eeprom(struct atheepmgr *aem)
41+
static bool eep_9285_load_eeprom(struct atheepmgr *aem, bool raw)
4242
{
4343
struct eep_9285_priv *emp = aem->eepmap_priv;
4444
uint16_t *eep_data = (uint16_t *)&emp->eep;

eep_9287.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static int eep_9287_get_rev(struct eep_9287_priv *emp)
3838
return (emp->eep.baseEepHeader.version) & 0xFFF;
3939
}
4040

41-
static bool eep_9287_load_eeprom(struct atheepmgr *aem)
41+
static bool eep_9287_load_eeprom(struct atheepmgr *aem, bool raw)
4242
{
4343
struct eep_9287_priv *emp = aem->eepmap_priv;
4444
uint16_t *eep_data = (uint16_t *)&emp->eep;

eep_9300.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ static bool eep_9300_load_blob(struct atheepmgr *aem)
275275
/*
276276
* Read the configuration data from the eeprom uncompress it if necessary.
277277
*/
278-
static bool eep_9300_load_eeprom(struct atheepmgr *aem)
278+
static bool eep_9300_load_eeprom(struct atheepmgr *aem, bool raw)
279279
{
280280
struct eep_9300_priv *emp = aem->eepmap_priv;
281281
uint16_t magic;
@@ -334,7 +334,7 @@ static bool eep_9300_load_eeprom(struct atheepmgr *aem)
334334
/*
335335
* Read the configuration data from the OTP memory uncompress it if necessary.
336336
*/
337-
static bool eep_9300_load_otp(struct atheepmgr *aem)
337+
static bool eep_9300_load_otp(struct atheepmgr *aem, bool raw)
338338
{
339339
struct eep_9300_priv *emp = aem->eepmap_priv;
340340
int cptr;

eep_9880.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static bool eep_9880_load_blob(struct atheepmgr *aem)
112112
return true;
113113
}
114114

115-
static bool eep_9880_load_otp(struct atheepmgr *aem)
115+
static bool eep_9880_load_otp(struct atheepmgr *aem, bool raw)
116116
{
117117
struct eep_9880_priv *emp = aem->eepmap_priv;
118118
struct qca9880_eeprom *eep;

0 commit comments

Comments
 (0)