meta-digi-arm: Review kobs-ng recipe.
Do not duplicate patches in platform specific folder, use a common folder instead. Signed-off-by: Alex Gonzalez <alex.gonzalez@digi.com>
This commit is contained in:
parent
23f2ccfc65
commit
f04579d9d9
|
|
@ -1,268 +0,0 @@
|
|||
From 4c73ce48d22cba69d775c7efe5bb20fdf38a5c7d Mon Sep 17 00:00:00 2001
|
||||
From: Javier Viguera <javier.viguera@digi.com>
|
||||
Date: Fri, 1 Apr 2011 14:45:52 +0200
|
||||
Subject: [PATCH] dump v1 boot structures
|
||||
|
||||
The kobs-ng that we received from Freescale did not support reading the
|
||||
boot structures on the mx28. It could write them, but the function that
|
||||
reads them was never updated to handle the updated structures used by
|
||||
the mx28. This change adds basic support for reading these structures,
|
||||
enough so that the dump command works. I would not recommend using
|
||||
any of the other functions, such as extract or update though.
|
||||
|
||||
Signed-off-by: Javier Viguera <javier.viguera@digi.com>
|
||||
---
|
||||
src/main.c | 6 ++-
|
||||
src/mtd.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
|
||||
src/mtd.h | 1 +
|
||||
3 files changed, 174 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/src/main.c b/src/main.c
|
||||
index 0b83828..c21dece 100644
|
||||
--- a/src/main.c
|
||||
+++ b/src/main.c
|
||||
@@ -146,7 +146,11 @@ int dump_main(int argc, char **argv)
|
||||
if (flags & F_VERBOSE)
|
||||
mtd_dump(md);
|
||||
|
||||
- r = mtd_load_all_boot_structures(md);
|
||||
+ if (rom_version == ROM_Version_1) {
|
||||
+ r = mtd_load_v1_boot_structures(md);
|
||||
+ } else {
|
||||
+ r = mtd_load_all_boot_structures(md);
|
||||
+ }
|
||||
if (r != 0) {
|
||||
fprintf(stderr, "Unable to load boot structures\n");
|
||||
exit(5);
|
||||
diff --git a/src/mtd.c b/src/mtd.c
|
||||
index b827a80..bcbb8d3 100644
|
||||
--- a/src/mtd.c
|
||||
+++ b/src/mtd.c
|
||||
@@ -65,6 +65,11 @@ const struct mtd_config default_mtd_config = {
|
||||
.boot_stream_2_address = 0,
|
||||
};
|
||||
|
||||
+
|
||||
+static int mtd_read_bcb(struct mtd_data *md, char *bcb_name,
|
||||
+ loff_t ofs1, loff_t ofs2, loff_t ofs_mchip,
|
||||
+ loff_t end, size_t size, int ecc);
|
||||
+
|
||||
static inline int multichip(struct mtd_data *md)
|
||||
{
|
||||
return md->flags & F_MULTICHIP;
|
||||
@@ -932,6 +937,32 @@ void *mtd_load_boot_structure(struct mtd_data *md, int chip, loff_t *ofsp, loff_
|
||||
return md->buf;
|
||||
}
|
||||
|
||||
+// This function is a hack by Digi, written because the original code from
|
||||
+// Freescale did not support reading the v1 boot structures at all. Do not
|
||||
+// use the results from this function for anything other than browsing the
|
||||
+// boot structures.
|
||||
+int mtd_load_v1_boot_structures(struct mtd_data *md)
|
||||
+{
|
||||
+ int err = 0;
|
||||
+
|
||||
+ err = mtd_read_bcb(md, "FCB", 0, 0, 0, 1, mtd_writesize(md) + mtd_oobsize(md), false);
|
||||
+
|
||||
+ memcpy(&md->fcb, md->buf, sizeof(md->fcb));
|
||||
+ //----------------------------------------------------------------------
|
||||
+ // read the DBBT search area.
|
||||
+ //----------------------------------------------------------------------
|
||||
+
|
||||
+ err |= mtd_read_bcb(md, "DBBT", 1, 1, 1, 1, mtd_writesize(md), true);
|
||||
+
|
||||
+ memcpy(&md->dbbt28, md->buf, sizeof(md->dbbt28));
|
||||
+
|
||||
+ if ((err != 0) || (md->dbbt28.m_u32FingerPrint != DBBT_FINGERPRINT2)) {
|
||||
+ err = -1;
|
||||
+ }
|
||||
+
|
||||
+ return err;
|
||||
+}
|
||||
+
|
||||
/* single chip version */
|
||||
int mtd_load_all_boot_structures(struct mtd_data *md)
|
||||
{
|
||||
@@ -1754,7 +1785,7 @@ int v1_rom_mtd_init(struct mtd_data *md, FILE *fp)
|
||||
|
||||
}
|
||||
|
||||
-v2_rom_mtd_init(struct mtd_data *md, FILE *fp)
|
||||
+int v2_rom_mtd_init(struct mtd_data *md, FILE *fp)
|
||||
{
|
||||
unsigned int stride_size_in_bytes;
|
||||
unsigned int search_area_size_in_bytes;
|
||||
@@ -1774,7 +1805,7 @@ v2_rom_mtd_init(struct mtd_data *md, FILE *fp)
|
||||
// Compute the geometry of a search area.
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
- stride_size_in_bytes = mtd_erasesize;
|
||||
+ stride_size_in_bytes = mtd_erasesize(md);
|
||||
search_area_size_in_bytes = 4 * stride_size_in_bytes;
|
||||
search_area_size_in_pages = search_area_size_in_bytes / mtd_writesize(md);
|
||||
|
||||
@@ -2053,6 +2084,140 @@ int mtd_commit_bcb(struct mtd_data *md, char *bcb_name,
|
||||
return err;
|
||||
}
|
||||
|
||||
+
|
||||
+//------------------------------------------------------------------------------
|
||||
+// This function is a hack written by Digi because the original code from
|
||||
+// Freescale did not supporting reading the bootlet structures at all.
|
||||
+//
|
||||
+// This function reads the search areas for a given BCB. It will read the first
|
||||
+// search area and use it if the read succeeds. If the read fails, then it will
|
||||
+// try again with the second search area.
|
||||
+//
|
||||
+// md A pointer to the current struct mtd_data.
|
||||
+// bcb_name A pointer to a human-readable string that indicates what kind of
|
||||
+// BCB we're reading. This string will only be used in log messages.
|
||||
+// ofs1 If there is one chips, the index of the search area to read
|
||||
+// ofs2
|
||||
+// ofs_mchip If there are multiple chips, the index of the search area to read
|
||||
+// on both chips.
|
||||
+// end The number of consecutive search areas to be read.
|
||||
+// size The size of the BCB data to be read.
|
||||
+// ecc Indicates whether or not to use hardware ECC.
|
||||
+//------------------------------------------------------------------------------
|
||||
+int mtd_read_bcb(struct mtd_data *md, char *bcb_name,
|
||||
+ loff_t ofs1, loff_t ofs2, loff_t ofs_mchip,
|
||||
+ loff_t end, size_t size, int ecc)
|
||||
+{
|
||||
+ int chip;
|
||||
+ loff_t end_index, search_area_indices[2], o;
|
||||
+ int r;
|
||||
+ int i;
|
||||
+ int j;
|
||||
+ unsigned stride_size_in_bytes;
|
||||
+ unsigned search_area_size_in_strides;
|
||||
+ unsigned search_area_size_in_bytes;
|
||||
+
|
||||
+ //----------------------------------------------------------------------
|
||||
+ // Compute some important facts about geometry.
|
||||
+ //----------------------------------------------------------------------
|
||||
+ if (rom_version == ROM_Version_2) {
|
||||
+
|
||||
+ stride_size_in_bytes = mtd_erasesize(md);
|
||||
+ search_area_size_in_strides = 4;
|
||||
+ search_area_size_in_bytes = search_area_size_in_strides * stride_size_in_bytes;
|
||||
+
|
||||
+ } else {
|
||||
+ stride_size_in_bytes = PAGES_PER_STRIDE * mtd_writesize(md);
|
||||
+ search_area_size_in_strides = 1 << md->cfg.search_exponent;
|
||||
+ search_area_size_in_bytes = search_area_size_in_strides * stride_size_in_bytes;
|
||||
+ }
|
||||
+
|
||||
+ //----------------------------------------------------------------------
|
||||
+ // Check whether there are multiple chips and set up the two search area
|
||||
+ // indices accordingly.
|
||||
+ //----------------------------------------------------------------------
|
||||
+
|
||||
+ if (multichip(md))
|
||||
+ search_area_indices[0] = search_area_indices[1] = ofs_mchip;
|
||||
+ else {
|
||||
+ search_area_indices[0] = ofs1;
|
||||
+ search_area_indices[1] = ofs2;
|
||||
+ }
|
||||
+
|
||||
+ //----------------------------------------------------------------------
|
||||
+ // Loop over search areas for this BCB.
|
||||
+ //----------------------------------------------------------------------
|
||||
+
|
||||
+ for (i = 0; i < 2; i++) {
|
||||
+
|
||||
+ //--------------------------------------------------------------
|
||||
+ // Compute the search area index that marks the end of the
|
||||
+ // writing on this chip.
|
||||
+ //--------------------------------------------------------------
|
||||
+
|
||||
+ end_index = search_area_indices[i] + end;
|
||||
+
|
||||
+ //--------------------------------------------------------------
|
||||
+ // Figure out which chip we're writing.
|
||||
+ //--------------------------------------------------------------
|
||||
+
|
||||
+ chip = multichip(md) ? i : 0;
|
||||
+
|
||||
+ //--------------------------------------------------------------
|
||||
+ // Loop over consecutive search areas to write.
|
||||
+ //--------------------------------------------------------------
|
||||
+
|
||||
+ for (; search_area_indices[i] < end_index; search_area_indices[i]++) {
|
||||
+
|
||||
+ //------------------------------------------------------
|
||||
+ // Compute the byte offset of the beginning of this
|
||||
+ // search area.
|
||||
+ //------------------------------------------------------
|
||||
+
|
||||
+ o = search_area_indices[i] * search_area_size_in_bytes;
|
||||
+
|
||||
+ //------------------------------------------------------
|
||||
+ // Loop over strides in this search area.
|
||||
+ //------------------------------------------------------
|
||||
+
|
||||
+ for (j = 0; j < search_area_size_in_strides; j++, o += stride_size_in_bytes) {
|
||||
+
|
||||
+ //----------------------------------------------
|
||||
+ // If we're crossing into a new block, erase it
|
||||
+ // first.
|
||||
+ //----------------------------------------------
|
||||
+
|
||||
+ //----------------------------------------------
|
||||
+ // Write the page.
|
||||
+ //----------------------------------------------
|
||||
+
|
||||
+ if (md->flags & F_VERBOSE)
|
||||
+ printf("mtd: Reading %s%d @%d:0x%llx(%x)\n",
|
||||
+ bcb_name, j, chip, o, size);
|
||||
+
|
||||
+/*int mtd_commit_bcb(struct mtd_data *md, char *bcb_name,
|
||||
+ loff_t ofs1, loff_t ofs2, loff_t ofs_mchip,
|
||||
+ loff_t end, size_t size, int ecc) */
|
||||
+/* mtd_commit_bcb(md, "FCB", 0, 0, 0, 1, size, false); */
|
||||
+ r = mtd_read_page(md, chip, o, ecc);
|
||||
+ if (r != size) {
|
||||
+ fprintf(stderr, "\n%s r = 0x%8.8X, size = 0x%8.8X\n", __func__, r, size);
|
||||
+ fprintf(stderr, "mtd: Failed to read %s @%d: 0x%llx (%d)\n",
|
||||
+ bcb_name, chip, o, r);
|
||||
+ } else {
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ }
|
||||
+
|
||||
+ }
|
||||
+
|
||||
+ }
|
||||
+
|
||||
+ return !(r == size);
|
||||
+}
|
||||
+
|
||||
+
|
||||
int v0_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags)
|
||||
{
|
||||
int startpage, start, size;
|
||||
@@ -2367,7 +2532,7 @@ int v1_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags)
|
||||
|
||||
}
|
||||
|
||||
-v2_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags)
|
||||
+int v2_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags)
|
||||
{
|
||||
int startpage, start, size;
|
||||
unsigned int search_area_size_in_bytes, stride_size_in_bytes;
|
||||
diff --git a/src/mtd.h b/src/mtd.h
|
||||
index b5c866e..cff09af 100644
|
||||
--- a/src/mtd.h
|
||||
+++ b/src/mtd.h
|
||||
@@ -254,6 +254,7 @@ void *mtd_load_boot_structure(struct mtd_data *md, int chip, loff_t *ofsp, loff_
|
||||
uint32_t magic1, uint32_t magic2, uint32_t magic3, int use_ecc,
|
||||
int magic_offset);
|
||||
int mtd_load_all_boot_structures(struct mtd_data *md);
|
||||
+int mtd_load_v1_boot_structures(struct mtd_data *md);
|
||||
int mtd_dump_structure(struct mtd_data *md);
|
||||
|
||||
int v0_rom_mtd_init(struct mtd_data *md, FILE *fp);
|
||||
--
|
||||
1.7.4.2
|
||||
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
From c0a2cc4852f59810ce2fd330ecf5c2a38f232935 Mon Sep 17 00:00:00 2001
|
||||
From: Javier Viguera <javier.viguera@digi.com>
|
||||
Date: Fri, 1 Apr 2011 14:53:24 +0200
|
||||
Subject: [PATCH] rom version
|
||||
|
||||
Add ROM version for the CPX2
|
||||
|
||||
Signed-off-by: Javier Viguera <javier.viguera@digi.com>
|
||||
---
|
||||
src/main.c | 42 ++++++++++++++++++++++--------------------
|
||||
1 files changed, 22 insertions(+), 20 deletions(-)
|
||||
|
||||
diff --git a/src/main.c b/src/main.c
|
||||
index c21dece..eb9504d 100644
|
||||
--- a/src/main.c
|
||||
+++ b/src/main.c
|
||||
@@ -795,7 +795,9 @@ void discover_boot_rom_version(void)
|
||||
{
|
||||
FILE *cpuinfo;
|
||||
char line_buffer[100];
|
||||
- static char *banner = "Hardware\t: Freescale MX";
|
||||
+ static char *banner_hw = "Hardware\t:";
|
||||
+ static char *banner = "Hardware\t: Freescale MX";
|
||||
+ static char *banner_digi_x2 = "Hardware\t: Digi ConnectPort X2";
|
||||
static char *v0_rom_tag = "23";
|
||||
static char *v1_rom_tag = "28";
|
||||
static char *v2_rom_tag = "53";
|
||||
@@ -828,31 +830,31 @@ void discover_boot_rom_version(void)
|
||||
//--------------------------------------------------------------
|
||||
// Check if the current line contains the information we need.
|
||||
//--------------------------------------------------------------
|
||||
-
|
||||
- if (strncmp(line_buffer, banner, strlen(banner))) {
|
||||
+ if (strncmp(line_buffer, banner_hw, strlen(banner_hw))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
- //--------------------------------------------------------------
|
||||
- // If control arrives here, we found what we're looking for.
|
||||
- // Extract the information we need.
|
||||
- //--------------------------------------------------------------
|
||||
-
|
||||
- if (!strncmp(line_buffer + strlen(banner), v0_rom_tag, strlen(v0_rom_tag))) {
|
||||
- rom_version = ROM_Version_0;
|
||||
- break;
|
||||
+ if ( !strncmp(line_buffer, banner, strlen(banner)) ) {
|
||||
+ if (!strncmp(line_buffer + strlen(banner), v0_rom_tag, strlen(v0_rom_tag))) {
|
||||
+ rom_version = ROM_Version_0;
|
||||
+ break;
|
||||
+ }
|
||||
+ else
|
||||
+ if (!strncmp(line_buffer + strlen(banner), v1_rom_tag, strlen(v1_rom_tag))) {
|
||||
+ rom_version = ROM_Version_1;
|
||||
+ break;
|
||||
+ }
|
||||
+ else
|
||||
+ if (!strncmp(line_buffer + strlen(banner), v2_rom_tag, strlen(v2_rom_tag))) {
|
||||
+ rom_version = ROM_Version_2;
|
||||
+ break;
|
||||
+ }
|
||||
}
|
||||
- else
|
||||
- if (!strncmp(line_buffer + strlen(banner), v1_rom_tag, strlen(v1_rom_tag))) {
|
||||
+
|
||||
+ if ( !strncmp(line_buffer, banner_digi_x2, strlen(banner_digi_x2)) ) {
|
||||
+ // The CPX2 has a ROM version 1
|
||||
rom_version = ROM_Version_1;
|
||||
- break;
|
||||
}
|
||||
- else
|
||||
- if (!strncmp(line_buffer + strlen(banner), v2_rom_tag, strlen(v2_rom_tag))) {
|
||||
- rom_version = ROM_Version_2;
|
||||
- break;
|
||||
- }
|
||||
-
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
--
|
||||
1.7.4.2
|
||||
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
From 577e707a60b5fb22ef1af626b4947ceb574405ff Mon Sep 17 00:00:00 2001
|
||||
From: Hector Palacios <hector.palacios@digi.com>
|
||||
Date: Tue, 19 Apr 2011 11:55:31 +0200
|
||||
Subject: [PATCH] ncb: fixed transposed parameters in memset
|
||||
|
||||
Doesn't seem to be critical, but we'd better have the buffer with zeros
|
||||
than with data.
|
||||
|
||||
Signed-off-by: Hector Palacios <hector.palacios@digi.com>
|
||||
---
|
||||
src/ncb.c | 4 ++--
|
||||
1 files changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/src/ncb.c b/src/ncb.c
|
||||
index 927ca01..6e6f21d 100644
|
||||
--- a/src/ncb.c
|
||||
+++ b/src/ncb.c
|
||||
@@ -332,7 +332,7 @@ int ncb_encrypt(BootBlockStruct_t *ncb, void *target, size_t size, int version)
|
||||
assert(version == 0 || version == 1 || version == 3);
|
||||
assert(size >= sizeof(BootBlockStruct_t));
|
||||
|
||||
- memset(target, size, 0);
|
||||
+ memset(target, 0, size);
|
||||
|
||||
switch (version)
|
||||
{
|
||||
@@ -377,7 +377,7 @@ int fcb_encrypt(V1_ROM_BootBlockStruct_t *fcb, void *target, size_t size, int ve
|
||||
// Clear out the target.
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
- memset(target, size, 0);
|
||||
+ memset(target, 0, size);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Compute the checksum.
|
||||
--
|
||||
1.7.1
|
||||
|
||||
|
|
@ -1,327 +0,0 @@
|
|||
From 730703eef88d4ed1d09d011ebaf0ba5b5976ad7f Mon Sep 17 00:00:00 2001
|
||||
From: Hector Palacios <hector.palacios@digi.com>
|
||||
Date: Tue, 19 Apr 2011 13:45:53 +0200
|
||||
Subject: [PATCH] added verification of written data (only for v1 ROM)
|
||||
|
||||
Added new option to verify data committed to flash right after writing.
|
||||
After each BCB or bootstream page write, the data is read back from flash
|
||||
and verified against the written buffer in RAM.
|
||||
If the verification fails the program exits.
|
||||
|
||||
Only added for v1_rom_mtd_commit_structures() -> MX28 arch.
|
||||
|
||||
Signed-off-by: Hector Palacios <hector.palacios@digi.com>
|
||||
---
|
||||
src/main.c | 25 ++++++++++++++++------
|
||||
src/mtd.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++----------
|
||||
src/mtd.h | 6 ++--
|
||||
3 files changed, 75 insertions(+), 21 deletions(-)
|
||||
|
||||
diff --git a/src/main.c b/src/main.c
|
||||
index eb9504d..bd0bac0 100644
|
||||
--- a/src/main.c
|
||||
+++ b/src/main.c
|
||||
@@ -76,10 +76,12 @@ void usage(void)
|
||||
" -v .................................... Verbose mode\n"
|
||||
" -n .................................... Dry run (don't commit to flash)\n"
|
||||
" -w .................................... Commit to flash\n"
|
||||
+ " -c .................................... Check committed data in flash\n"
|
||||
"\n"
|
||||
" update [-v] [KEY] [KOBS] [-0|1] <file> .. Update a single bootstream\n"
|
||||
" -v .................................... Verbose mode\n"
|
||||
" -0|1 .................................. Update specified bootstream #\n"
|
||||
+ " -c .................................... Check committed data in flash\n"
|
||||
"\n"
|
||||
" extract [-v] [KEY] [KOBS] [-0|1] <file> . Extract a bootstream from flash\n"
|
||||
" -v .................................... Verbose mode\n"
|
||||
@@ -378,7 +380,7 @@ int extract_main(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int perform_bootstream_update(struct mtd_data *md, FILE *infp, int image_mask)
|
||||
+static int perform_bootstream_update(struct mtd_data *md, FILE *infp, int image_mask, int check)
|
||||
{
|
||||
int i, r;
|
||||
unsigned int size, start, avail, end, update;
|
||||
@@ -423,7 +425,7 @@ static int perform_bootstream_update(struct mtd_data *md, FILE *infp, int image_
|
||||
update |= UPDATE_BS(i);
|
||||
}
|
||||
|
||||
- r = v0_rom_mtd_commit_structures(md, infp, UPDATE_LDLB | update);
|
||||
+ r = v0_rom_mtd_commit_structures(md, infp, UPDATE_LDLB | update, check);
|
||||
if (r < 0) {
|
||||
fprintf(stderr, "FAILED to commit structures\n");
|
||||
return -1;
|
||||
@@ -445,6 +447,7 @@ int update_main(int argc, char **argv)
|
||||
char ascii[20 * 2 + 1];
|
||||
int device_key;
|
||||
uint8_t *keyp;
|
||||
+ int check;
|
||||
|
||||
memset(key, 0, sizeof(key));
|
||||
device_key = 0;
|
||||
@@ -461,6 +464,7 @@ int update_main(int argc, char **argv)
|
||||
image_mask = 0; /* no image */
|
||||
flags = 0;
|
||||
j = 0;
|
||||
+ check = 0;
|
||||
for (i = 1; i < argc; i++) {
|
||||
|
||||
if (argv[i][0] != '-') {
|
||||
@@ -488,6 +492,9 @@ int update_main(int argc, char **argv)
|
||||
exit(5);
|
||||
}
|
||||
break;
|
||||
+ case 'c':
|
||||
+ check = 1;
|
||||
+ break;
|
||||
case 'v':
|
||||
flags |= F_VERBOSE;
|
||||
break;
|
||||
@@ -533,7 +540,7 @@ int update_main(int argc, char **argv)
|
||||
if (flags & F_VERBOSE)
|
||||
mtd_dump(md);
|
||||
|
||||
- r = perform_bootstream_update(md, infp, image_mask);
|
||||
+ r = perform_bootstream_update(md, infp, image_mask, check);
|
||||
if (r != 0) {
|
||||
fprintf(stderr, "Unable to perform bootstream update\n");
|
||||
usage();
|
||||
@@ -555,7 +562,7 @@ int init_main(int argc, char **argv)
|
||||
char *badlist = NULL;
|
||||
FILE *infp;
|
||||
loff_t ofs;
|
||||
- int dryrun;
|
||||
+ int dryrun, check;
|
||||
struct mtd_config cfg;
|
||||
uint8_t key[16];
|
||||
char ascii[20 * 2 + 1];
|
||||
@@ -577,6 +584,7 @@ int init_main(int argc, char **argv)
|
||||
image = 0; /* first image */
|
||||
flags = 0;
|
||||
dryrun = 0;
|
||||
+ check = 0;
|
||||
j = 0;
|
||||
for (i = 1; i < argc; i++) {
|
||||
|
||||
@@ -598,6 +606,9 @@ int init_main(int argc, char **argv)
|
||||
case 'w':
|
||||
dryrun = 0;
|
||||
break;
|
||||
+ case 'c':
|
||||
+ check = 1;
|
||||
+ break;
|
||||
case 'n':
|
||||
dryrun = 1;
|
||||
break;
|
||||
@@ -692,13 +703,13 @@ int init_main(int argc, char **argv)
|
||||
if (!dryrun) {
|
||||
switch (rom_version) {
|
||||
case ROM_Version_0:
|
||||
- r = v0_rom_mtd_commit_structures(md, infp, UPDATE_ALL);
|
||||
+ r = v0_rom_mtd_commit_structures(md, infp, UPDATE_ALL, check);
|
||||
break;
|
||||
case ROM_Version_1:
|
||||
- r = v1_rom_mtd_commit_structures(md, infp, UPDATE_ALL);
|
||||
+ r = v1_rom_mtd_commit_structures(md, infp, UPDATE_ALL, check);
|
||||
break;
|
||||
case ROM_Version_2:
|
||||
- r = v2_rom_mtd_commit_structures(md, infp, UPDATE_ALL);
|
||||
+ r = v2_rom_mtd_commit_structures(md, infp, UPDATE_ALL, check);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unknown ROM version: %d\n", rom_version);
|
||||
diff --git a/src/mtd.c b/src/mtd.c
|
||||
index bcbb8d3..4dbb878 100644
|
||||
--- a/src/mtd.c
|
||||
+++ b/src/mtd.c
|
||||
@@ -1967,7 +1967,7 @@ int v2_rom_mtd_init(struct mtd_data *md, FILE *fp)
|
||||
|
||||
int mtd_commit_bcb(struct mtd_data *md, char *bcb_name,
|
||||
loff_t ofs1, loff_t ofs2, loff_t ofs_mchip,
|
||||
- loff_t end, size_t size, int ecc)
|
||||
+ loff_t end, size_t size, int ecc, int verify)
|
||||
{
|
||||
int chip;
|
||||
loff_t end_index, search_area_indices[2], o;
|
||||
@@ -1977,6 +1977,13 @@ int mtd_commit_bcb(struct mtd_data *md, char *bcb_name,
|
||||
unsigned stride_size_in_bytes;
|
||||
unsigned search_area_size_in_strides;
|
||||
unsigned search_area_size_in_bytes;
|
||||
+ char *readbuf = NULL;
|
||||
+
|
||||
+ if (verify) {
|
||||
+ readbuf = malloc(mtd_writesize(md));
|
||||
+ if (NULL == readbuf)
|
||||
+ return -1;
|
||||
+ }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Compute some important facts about geometry.
|
||||
@@ -2072,6 +2079,21 @@ int mtd_commit_bcb(struct mtd_data *md, char *bcb_name,
|
||||
err ++;
|
||||
}
|
||||
|
||||
+ if (verify) {
|
||||
+ //------------------------------------------------------
|
||||
+ // Verify the written data
|
||||
+ //------------------------------------------------------
|
||||
+ r = pread(md->part[chip].fd, readbuf, mtd_writesize(md), o);
|
||||
+ if (r != mtd_writesize(md)) {
|
||||
+ fprintf(stderr, "mtd: Failed to read @0x%llx (%d)\n", o, r);
|
||||
+ return -1;
|
||||
+ }
|
||||
+ if (memcmp(md->buf, readbuf, mtd_writesize(md))) {
|
||||
+ fprintf(stderr, "mtd: Verification error @0x%llx\n", o);
|
||||
+ return -1;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2218,7 +2240,7 @@ int mtd_read_bcb(struct mtd_data *md, char *bcb_name,
|
||||
}
|
||||
|
||||
|
||||
-int v0_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags)
|
||||
+int v0_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags, int verify)
|
||||
{
|
||||
int startpage, start, size;
|
||||
unsigned int search_area_sz, stride;
|
||||
@@ -2317,7 +2339,7 @@ int v0_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags)
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
- mtd_commit_bcb(md, "NCB", 0, 1, 0, 1, size, false);
|
||||
+ mtd_commit_bcb(md, "NCB", 0, 1, 0, 1, size, false, verify);
|
||||
}
|
||||
|
||||
if (flags & UPDATE_LDLB) {
|
||||
@@ -2326,7 +2348,7 @@ int v0_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags)
|
||||
memset(md->buf, 0, mtd_writesize(md));
|
||||
memcpy(md->buf, md->curr_ldlb, sizeof(*md->curr_ldlb));
|
||||
|
||||
- mtd_commit_bcb(md, "LDLB", 2, 3, 1, 1, mtd_writesize(md), true);
|
||||
+ mtd_commit_bcb(md, "LDLB", 2, 3, 1, 1, mtd_writesize(md), true, verify);
|
||||
}
|
||||
|
||||
if (flags & UPDATE_DBBT) {
|
||||
@@ -2335,7 +2357,7 @@ int v0_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags)
|
||||
memset(md->buf, 0, mtd_writesize(md));
|
||||
memcpy(md->buf, md->curr_dbbt, sizeof(*md->curr_dbbt));
|
||||
|
||||
- mtd_commit_bcb(md, "DBBT", 4, 5, 2, 1, mtd_writesize(md), true);
|
||||
+ mtd_commit_bcb(md, "DBBT", 4, 5, 2, 1, mtd_writesize(md), true, verify);
|
||||
for (i = 0; i < 2; i++) {
|
||||
for (j = 0; j < 2; j++) {
|
||||
if (md->flags & F_MULTICHIP) {
|
||||
@@ -2369,14 +2391,20 @@ int v0_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-int v1_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags)
|
||||
+int v1_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags, int verify)
|
||||
{
|
||||
int startpage, start, size;
|
||||
unsigned int search_area_size_in_bytes, stride_size_in_bytes;
|
||||
int i, r, chunk;
|
||||
loff_t ofs, end;
|
||||
int chip = 0;
|
||||
+ char *readbuf = NULL;
|
||||
|
||||
+ if (verify) {
|
||||
+ readbuf = malloc(mtd_writesize(md));
|
||||
+ if (NULL == readbuf)
|
||||
+ return -1;
|
||||
+ }
|
||||
//----------------------------------------------------------------------
|
||||
// Compute some important facts about geometry.
|
||||
//----------------------------------------------------------------------
|
||||
@@ -2403,7 +2431,7 @@ int v1_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags)
|
||||
// Write the FCB search area.
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
- mtd_commit_bcb(md, "FCB", 0, 0, 0, 1, size, false);
|
||||
+ mtd_commit_bcb(md, "FCB", 0, 0, 0, 1, size, false, verify);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Write the DBBT search area.
|
||||
@@ -2412,7 +2440,7 @@ int v1_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags)
|
||||
memset(md->buf, 0, mtd_writesize(md));
|
||||
memcpy(md->buf, &(md->dbbt28), sizeof(md->dbbt28));
|
||||
|
||||
- mtd_commit_bcb(md, "DBBT", 1, 1, 1, 1, mtd_writesize(md), true);
|
||||
+ mtd_commit_bcb(md, "DBBT", 1, 1, 1, 1, mtd_writesize(md), true, verify);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Loop over the two boot streams.
|
||||
@@ -2512,6 +2540,21 @@ int v1_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags)
|
||||
if (r != mtd_writesize(md)) {
|
||||
fprintf(stderr, "mtd: Failed to write BS @0x%llx (%d)\n", ofs, r);
|
||||
}
|
||||
+
|
||||
+ if (verify) {
|
||||
+ //------------------------------------------------------
|
||||
+ // Verify the written data
|
||||
+ //------------------------------------------------------
|
||||
+ r = pread(md->part[chip].fd, readbuf, mtd_writesize(md), ofs);
|
||||
+ if (r != mtd_writesize(md)) {
|
||||
+ fprintf(stderr, "mtd: Failed to read BS @0x%llx (%d)\n", ofs, r);
|
||||
+ return -1;
|
||||
+ }
|
||||
+ if (memcmp(md->buf, readbuf, mtd_writesize(md))) {
|
||||
+ fprintf(stderr, "mtd: Verification error @0x%llx\n", ofs);
|
||||
+ return -1;
|
||||
+ }
|
||||
+ }
|
||||
ofs += mtd_writesize(md);
|
||||
size -= chunk;
|
||||
|
||||
@@ -2532,7 +2575,7 @@ int v1_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags)
|
||||
|
||||
}
|
||||
|
||||
-int v2_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags)
|
||||
+int v2_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags, int verify)
|
||||
{
|
||||
int startpage, start, size;
|
||||
unsigned int search_area_size_in_bytes, stride_size_in_bytes;
|
||||
@@ -2569,7 +2612,7 @@ int v2_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags)
|
||||
memset(md->buf, 0, mtd_writesize(md));
|
||||
memcpy(md->buf, &(md->fcb), sizeof(md->fcb));
|
||||
|
||||
- mtd_commit_bcb(md, "FCB", 0, 0, 0, 1, mtd_writesize(md), true);
|
||||
+ mtd_commit_bcb(md, "FCB", 0, 0, 0, 1, mtd_writesize(md), true, verify);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Write the DBBT search area.
|
||||
@@ -2578,7 +2621,7 @@ int v2_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags)
|
||||
memset(md->buf, 0, mtd_writesize(md));
|
||||
memcpy(md->buf, &(md->dbbt28), sizeof(md->dbbt28));
|
||||
|
||||
- mtd_commit_bcb(md, "DBBT", 1, 1, 1, 1, mtd_writesize(md), true);
|
||||
+ mtd_commit_bcb(md, "DBBT", 1, 1, 1, 1, mtd_writesize(md), true, verify);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Write the DBBT table area.
|
||||
diff --git a/src/mtd.h b/src/mtd.h
|
||||
index cff09af..429078f 100644
|
||||
--- a/src/mtd.h
|
||||
+++ b/src/mtd.h
|
||||
@@ -269,9 +269,9 @@ int mtd_markbad(struct mtd_data *md, int chip, loff_t ofs);
|
||||
#define UPDATE_BS1 0x10
|
||||
#define UPDATE_BS(x) (0x08 << ((x) & 1))
|
||||
#define UPDATE_ALL (UPDATE_NCB | UPDATE_LDLB | UPDATE_DBBT | UPDATE_BS0 | UPDATE_BS1)
|
||||
-int v0_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags);
|
||||
-int v1_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags);
|
||||
-int v2_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags);
|
||||
+int v0_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags, int verify);
|
||||
+int v1_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags, int verify);
|
||||
+int v2_rom_mtd_commit_structures(struct mtd_data *md, FILE *fp, int flags, int verify);
|
||||
int mtd_set_ecc_mode(struct mtd_data *md, int ecc);
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
--
|
||||
1.7.1
|
||||
|
||||
Loading…
Reference in New Issue