From 9e336798c74bb90966a4035e280e03f96ace48c8 Mon Sep 17 00:00:00 2001 From: Alex Gonzalez Date: Tue, 5 Mar 2013 18:29:49 +0100 Subject: [PATCH] update_flash: Add kobs-ng dependency. kobs-ng is needed to be able to flash the bootloader from user space in mxs platforms. Fixes https://jira.digi.com/browse/DEL-340 Signed-off-by: Alex Gonzalez --- .../0001-dump-v1-boot-structures.patch | 264 ++++++++++++++ .../ccardimx28js/0002-rom-version.patch | 77 +++++ ...ixed-transposed-parameters-in-memset.patch | 34 ++ ...tion-of-written-data-only-for-v1-ROM.patch | 323 +++++++++++++++++ ...-parse-MX-arch-to-select-rom-version.patch | 102 ++++++ .../cpx2/0001-dump-v1-boot-structures.patch | 268 ++++++++++++++ .../kobs-ng/cpx2/0002-rom-version.patch | 81 +++++ ...ixed-transposed-parameters-in-memset.patch | 38 ++ ...tion-of-written-data-only-for-v1-ROM.patch | 327 ++++++++++++++++++ .../recipes-bsp/kobs-ng/kobs-ng_10.12.01.bb | 29 ++ .../recipes-digi/update-flash/update-flash.bb | 1 + 11 files changed, 1544 insertions(+) create mode 100644 meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0001-dump-v1-boot-structures.patch create mode 100644 meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0002-rom-version.patch create mode 100644 meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0003-ncb-fixed-transposed-parameters-in-memset.patch create mode 100644 meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0004-added-verification-of-written-data-only-for-v1-ROM.patch create mode 100644 meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0005-version-parse-MX-arch-to-select-rom-version.patch create mode 100644 meta-digi-arm/recipes-bsp/kobs-ng/cpx2/0001-dump-v1-boot-structures.patch create mode 100644 meta-digi-arm/recipes-bsp/kobs-ng/cpx2/0002-rom-version.patch create mode 100644 meta-digi-arm/recipes-bsp/kobs-ng/cpx2/0003-ncb-fixed-transposed-parameters-in-memset.patch create mode 100644 meta-digi-arm/recipes-bsp/kobs-ng/cpx2/0004-added-verification-of-written-data-only-for-v1-ROM.patch create mode 100644 meta-digi-arm/recipes-bsp/kobs-ng/kobs-ng_10.12.01.bb diff --git a/meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0001-dump-v1-boot-structures.patch b/meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0001-dump-v1-boot-structures.patch new file mode 100644 index 000000000..49b54cfbe --- /dev/null +++ b/meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0001-dump-v1-boot-structures.patch @@ -0,0 +1,264 @@ +From: Javier Viguera +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 +--- + 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); diff --git a/meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0002-rom-version.patch b/meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0002-rom-version.patch new file mode 100644 index 000000000..b75d9e554 --- /dev/null +++ b/meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0002-rom-version.patch @@ -0,0 +1,77 @@ +From: Javier Viguera +Date: Fri, 1 Apr 2011 14:53:24 +0200 +Subject: [PATCH] rom version + +Add ROM version for the CPX2 + +Signed-off-by: Javier Viguera +--- + src/main.c | 42 ++++++++++++++++++++++-------------------- + 1 file 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; +- } +- + } + + //---------------------------------------------------------------------- diff --git a/meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0003-ncb-fixed-transposed-parameters-in-memset.patch b/meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0003-ncb-fixed-transposed-parameters-in-memset.patch new file mode 100644 index 000000000..9b2bfb0b2 --- /dev/null +++ b/meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0003-ncb-fixed-transposed-parameters-in-memset.patch @@ -0,0 +1,34 @@ +From: Hector Palacios +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 +--- + src/ncb.c | 4 ++-- + 1 file 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. diff --git a/meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0004-added-verification-of-written-data-only-for-v1-ROM.patch b/meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0004-added-verification-of-written-data-only-for-v1-ROM.patch new file mode 100644 index 000000000..7ffaad1f1 --- /dev/null +++ b/meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0004-added-verification-of-written-data-only-for-v1-ROM.patch @@ -0,0 +1,323 @@ +From: Hector Palacios +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 +--- + 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] .. 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] . 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 diff --git a/meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0005-version-parse-MX-arch-to-select-rom-version.patch b/meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0005-version-parse-MX-arch-to-select-rom-version.patch new file mode 100644 index 000000000..2dd0567ab --- /dev/null +++ b/meta-digi-arm/recipes-bsp/kobs-ng/ccardimx28js/0005-version-parse-MX-arch-to-select-rom-version.patch @@ -0,0 +1,102 @@ +From b25a7a52f45a4961763543fc67b8ad30cfb02deb Mon Sep 17 00:00:00 2001 +From: Hector Palacios +Date: Mon, 21 May 2012 11:02:43 +0200 +Subject: [PATCH 5/5] version: parse MX arch to select rom version + +Parse the 'Hardware' line of /cpu/proc in search for the +string 'MX' and then parse the two numbers after it, which +will contain the architecture number (23,28,53) that +determine the rom version to use. + +Notice this patch is only applicable to platforms that contain +the string 'MX25, MX28, MX53' on their platform names. +E.g. + ConnectCard Wi-i.MX28 -> OK + ConnectPort CPX2 -> NOT OK + +Signed-off-by: Hector Palacios +--- + src/main.c | 50 +++++++++++++++++++++++--------------------------- + 1 files changed, 23 insertions(+), 27 deletions(-) + +diff --git a/src/main.c b/src/main.c +index bd0bac0..c8d4e7f 100644 +--- a/src/main.c ++++ b/src/main.c +@@ -807,11 +807,10 @@ void discover_boot_rom_version(void) + FILE *cpuinfo; + char line_buffer[100]; + 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"; ++ char *rev; + + //---------------------------------------------------------------------- + // Attempt to open /proc/cpuinfo. +@@ -834,38 +833,35 @@ void discover_boot_rom_version(void) + // Attempt to get the current line. + //-------------------------------------------------------------- + +- if (!fgets(line_buffer, sizeof(line_buffer), cpuinfo)) { ++ if (!fgets(line_buffer, sizeof(line_buffer), cpuinfo)) + break; +- } + + //-------------------------------------------------------------- + // Check if the current line contains the information we need. + //-------------------------------------------------------------- +- if (strncmp(line_buffer, banner_hw, strlen(banner_hw))) { +- continue; +- } +- +- 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; ++ if (!strncmp(line_buffer, banner_hw, strlen(banner_hw))) { ++ rev = strstr(line_buffer, "MX"); ++ if (rev) { ++ char tmp[3] = {}; ++ ++ rev += 2; ++ memcpy(tmp, rev, 2); ++ if (!strncmp(tmp, v0_rom_tag, strlen(v0_rom_tag))) { ++ rom_version = ROM_Version_0; ++ break; ++ } ++ else ++ if (!strncmp(tmp, v1_rom_tag, strlen(v1_rom_tag))) { ++ rom_version = ROM_Version_1; ++ break; ++ } ++ else ++ if (!strncmp(tmp, v2_rom_tag, strlen(v2_rom_tag))) { ++ rom_version = ROM_Version_2; ++ break; ++ } + } + } +- +- if ( !strncmp(line_buffer, banner_digi_x2, strlen(banner_digi_x2)) ) { +- // The CPX2 has a ROM version 1 +- rom_version = ROM_Version_1; +- } + } + + //---------------------------------------------------------------------- +-- +1.7.1 + diff --git a/meta-digi-arm/recipes-bsp/kobs-ng/cpx2/0001-dump-v1-boot-structures.patch b/meta-digi-arm/recipes-bsp/kobs-ng/cpx2/0001-dump-v1-boot-structures.patch new file mode 100644 index 000000000..d9a018c81 --- /dev/null +++ b/meta-digi-arm/recipes-bsp/kobs-ng/cpx2/0001-dump-v1-boot-structures.patch @@ -0,0 +1,268 @@ +From 4c73ce48d22cba69d775c7efe5bb20fdf38a5c7d Mon Sep 17 00:00:00 2001 +From: Javier Viguera +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 +--- + 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 + diff --git a/meta-digi-arm/recipes-bsp/kobs-ng/cpx2/0002-rom-version.patch b/meta-digi-arm/recipes-bsp/kobs-ng/cpx2/0002-rom-version.patch new file mode 100644 index 000000000..0d1b0f094 --- /dev/null +++ b/meta-digi-arm/recipes-bsp/kobs-ng/cpx2/0002-rom-version.patch @@ -0,0 +1,81 @@ +From c0a2cc4852f59810ce2fd330ecf5c2a38f232935 Mon Sep 17 00:00:00 2001 +From: Javier Viguera +Date: Fri, 1 Apr 2011 14:53:24 +0200 +Subject: [PATCH] rom version + +Add ROM version for the CPX2 + +Signed-off-by: Javier Viguera +--- + 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 + diff --git a/meta-digi-arm/recipes-bsp/kobs-ng/cpx2/0003-ncb-fixed-transposed-parameters-in-memset.patch b/meta-digi-arm/recipes-bsp/kobs-ng/cpx2/0003-ncb-fixed-transposed-parameters-in-memset.patch new file mode 100644 index 000000000..4068002c0 --- /dev/null +++ b/meta-digi-arm/recipes-bsp/kobs-ng/cpx2/0003-ncb-fixed-transposed-parameters-in-memset.patch @@ -0,0 +1,38 @@ +From 577e707a60b5fb22ef1af626b4947ceb574405ff Mon Sep 17 00:00:00 2001 +From: Hector Palacios +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 +--- + 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 + diff --git a/meta-digi-arm/recipes-bsp/kobs-ng/cpx2/0004-added-verification-of-written-data-only-for-v1-ROM.patch b/meta-digi-arm/recipes-bsp/kobs-ng/cpx2/0004-added-verification-of-written-data-only-for-v1-ROM.patch new file mode 100644 index 000000000..a8c4318c0 --- /dev/null +++ b/meta-digi-arm/recipes-bsp/kobs-ng/cpx2/0004-added-verification-of-written-data-only-for-v1-ROM.patch @@ -0,0 +1,327 @@ +From 730703eef88d4ed1d09d011ebaf0ba5b5976ad7f Mon Sep 17 00:00:00 2001 +From: Hector Palacios +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 +--- + 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] .. 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] . 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 + diff --git a/meta-digi-arm/recipes-bsp/kobs-ng/kobs-ng_10.12.01.bb b/meta-digi-arm/recipes-bsp/kobs-ng/kobs-ng_10.12.01.bb new file mode 100644 index 000000000..28113408a --- /dev/null +++ b/meta-digi-arm/recipes-bsp/kobs-ng/kobs-ng_10.12.01.bb @@ -0,0 +1,29 @@ +# Copyright 2013 Digi International. All rights reserved. + +SUMMARY = "Freescale's mxs nand update utility" +SECTION = "base" +LICENSE = "GPL-2.0" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6" + +PR = "r0" + +SRC_URI = "${DIGI_MIRROR}/${PN}-${PV}.tar.gz \ + file://0001-dump-v1-boot-structures.patch \ + file://0002-rom-version.patch \ + file://0003-ncb-fixed-transposed-parameters-in-memset.patch \ + file://0004-added-verification-of-written-data-only-for-v1-ROM.patch \ + " + +SRC_URI_append_ccardimx28js += "file://0005-version-parse-MX-arch-to-select-rom-version.patch" + +SRC_URI[md5sum] = "9fce401b6c90e851f0335b9ca3a649a9" +SRC_URI[sha256sum] = "ef25f5c9033500c236b1894436bddc4e20b90bc17585fbcdf9fe3bbbd9f15781" + +inherit autotools + +#FILES_${PN} += "" + +COMPATIBLE_MACHINE = "(ccardimx28js|cpx2)" + +BBCLASSEXTEND = "native" + diff --git a/meta-digi-del/recipes-digi/update-flash/update-flash.bb b/meta-digi-del/recipes-digi/update-flash/update-flash.bb index 45bbe5efb..8a16af937 100644 --- a/meta-digi-del/recipes-digi/update-flash/update-flash.bb +++ b/meta-digi-del/recipes-digi/update-flash/update-flash.bb @@ -6,6 +6,7 @@ LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0;md5=801f80980d171dd6425 PR = "r0" DEPENDS += "libdigi" +RDEPENDS += "kobs-ng" SRC_URI = "file://update_flash.c \ file://jffs2-user.h \