Initial commit
Some checks failed
Build Kernel / Build all affected Kernels (push) Has been cancelled
Build all core packages / Build all core packages for selected target (push) Has been cancelled
Build and Push prebuilt tools container / Build and Push all prebuilt containers (push) Has been cancelled
Build Toolchains / Build Toolchains for each target (push) Has been cancelled
Build host tools / Build host tools for linux and macos based systems (push) Has been cancelled
Coverity scan build / Coverity x86/64 build (push) Has been cancelled

This commit is contained in:
domenico
2025-06-24 12:51:15 +02:00
commit 27c9d80f51
10493 changed files with 1885777 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
--- a/src/mtd.c
+++ b/src/mtd.c
@@ -28,6 +28,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
+#include <stddef.h>
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
--- a/src/mtd.h
+++ b/src/mtd.h
@@ -25,8 +25,11 @@
#ifndef MTD_H
#define MTD_H
+#define _GNU_SOURCE
#include <mtd/mtd-user.h>
#include <endian.h>
+#include <stdint.h>
+#include <fcntl.h>
#include "BootControlBlocks.h"
#include "rom_nand_hamming_code_ecc.h"

View File

@@ -0,0 +1,45 @@
Add --chip_0_size param to override the size of the mtd partition which is
required if the SPL does not occupy the entire partition. For Gateworks
Ventana boards the 'uboot' partition contains both the SPL and uboot.
--- a/src/main.c
+++ b/src/main.c
@@ -94,6 +94,7 @@ void usage(void)
" [KOBS] boot structures config options\n"
" --chip_0_device_path=<path> .......... Device of boot (default /dev/mtd0)\n"
" --chip_1_device_path=<path> .......... The second chip in case of multichip NAND\n"
+ " --chip_0_size=<size> ................. Override size of chip_0 device\n"
" --search_exponent=<value> ............ NCB field (default 2)\n"
" --data_setup_time=<value> ............ NCB field (default 80)\n"
" --data_hold_time=<value> ............. NCB field (default 60)\n"
--- a/src/mtd.c
+++ b/src/mtd.c
@@ -876,6 +876,11 @@ struct mtd_data *mtd_open(const struct m
goto out;
}
+ /* override MTD size */
+ if (md->cfg.chip_0_size) {
+ miu->size = md->cfg.chip_0_size;
+ }
+
/* verify it's a nand */
if (miu->type != MTD_NANDFLASH
&& miu->type != MTD_MLCNANDFLASH) {
@@ -3385,7 +3390,7 @@ static const struct {
} mtd_int_args[] = {
ARG_IGNORE(chip_count),
ARG_IGNORE(chip_0_offset),
- ARG_IGNORE(chip_0_size),
+ ARG(chip_0_size),
ARG_IGNORE(chip_1_offset),
ARG_IGNORE(chip_1_size),
ARG(search_exponent),
@@ -3578,7 +3583,7 @@ void mtd_cfg_dump(struct mtd_config *cfg
// Pd(chip_count);
Ps(chip_0_device_path);
// Pd(chip_0_offset);
-// Pd(chip_0_size);
+ Pd(chip_0_size);
Ps(chip_1_device_path);
// Pd(chip_1_offset);
// Pd(chip_1_size);

View File

@@ -0,0 +1,45 @@
The downstream Freescale vendor kernel has a patch that allows determining
if raw NAND flash mode is provided via a debugfs file. This is not present
in upstream kernels, but the raw access support was added in the 3.19
kernel, so we will check the kernel version if we can't find the file.
--- a/src/mtd.c
+++ b/src/mtd.c
@@ -34,6 +34,7 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/ioctl.h>
+#include <sys/utsname.h>
#include "mtd.h"
#include "rand.h"
@@ -808,15 +809,27 @@ struct mtd_data *mtd_open(const struct m
md->cfg = *cfg;
/* check if use new raw access mode */
+ /* by looking for debugfs from fsl patch */
+ md->raw_mode_flag = 0;
fp = fopen("/sys/kernel/debug/gpmi-nand/raw_mode", "r");
if (!fp) {
- md->raw_mode_flag = 0;
- vp(md, "mtd: use legacy raw access mode\n");
+ /* fallback to kernel version: raw access added in 3.19 */
+ struct utsname uts;
+ if (!uname(&uts)) {
+ int major = 0, minor = 0;
+ sscanf(uts.release, "%d.%d", &major, &minor);
+ vp(md, "mtd: Linux %d.%d\n", major, minor);
+ if ((major << 8 | minor) > (3 << 8 | 18))
+ md->raw_mode_flag = 1;
+ }
} else {
fclose(fp);
md->raw_mode_flag = 1;
- vp(md, "mtd: use new bch layout raw access mode\n");
}
+ if (md->raw_mode_flag)
+ vp(md, "mtd: use new bch layout raw access mode\n");
+ else
+ vp(md, "mtd: use legacy raw access mode\n");
if (plat_config_data->m_u32UseMultiBootArea) {

View File

@@ -0,0 +1,27 @@
The Freescale downstream vendor kernel has a patch that exports the bch
flash geometry via a debugfs file. This is not available in mainline linux
kernels so the fallback method calculates the geometry based on known info
from the mtd partition. A bug exists in this funcion where it fails to
assume that block0 ECC is the same as the other blocks by default.
--- a/src/mtd.c
+++ b/src/mtd.c
@@ -610,7 +610,7 @@ static int cal_nfc_geometry(struct mtd_d
/* The two are fixed, please change them when the driver changes. */
geo->metadata_size_in_bytes = 10;
geo->gf_len = 13;
- geo->ecc_chunkn_size_in_bytes = 512;
+ geo->ecc_chunkn_size_in_bytes = geo->ecc_chunk0_size_in_bytes = 512;
if (mtd->oobsize > geo->ecc_chunkn_size_in_bytes) {
geo->gf_len = 14;
@@ -700,8 +700,9 @@ int parse_nfc_geometry(struct mtd_data *
unsigned int value;
if (!plat_config_data->m_u32UseNfcGeo) {
+ /* fsl kernel patch provides bch_geometry via debugfs */
if (!(node = fopen(dbg_geometry_node_path, "r"))) {
- fprintf(stderr, "Cannot open BCH geometry node: \"%s\"",
+ fprintf(stderr, "Cannot open BCH geometry node: \"%s\"\n",
dbg_geometry_node_path);
return cal_nfc_geometry(md);
}