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 14:35:53 +02:00
commit c06fb25d1f
9263 changed files with 1750214 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
#
# Copyright (C) 2013-2014 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=kobs-ng
PKG_VERSION:=5.4
PKG_RELEASE:=1
PKG_SOURCE:=imx-kobs-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.freescale.com/lgfiles/NMG/MAD/YOCTO/
PKG_HASH:=85171b46068ac47c42fedb8104167bf9afd33dd9527ed127e1ca2eb29d7a86bf
PKG_BUILD_DIR:=$(BUILD_DIR)/imx-kobs-$(PKG_VERSION)
PKG_LICENSE:=GPLv2
PKG_LICENSE_FILES:=COPYING
PKG_FLAGS:=nonshared
include $(INCLUDE_DIR)/package.mk
define Package/kobs-ng
SECTION:=utils
CATEGORY:=Utilities
TITLE:=Application for writing bootstreams to NAND flash
DEPENDS:=@TARGET_imx
endef
define Package/kobs-ng/description
The kobs-ng application writes a bootstream to NAND flash with the proper
FCB/DBBT headers and replicated streams.
endef
define Build/Prepare
$(call Build/Prepare/Default)
echo "const char* git_sha = \"$(PKG_VERSION)\";" > $(PKG_BUILD_DIR)/autoversion.h
endef
define Package/kobs-ng/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/kobs-ng $(1)/usr/sbin/
endef
$(eval $(call BuildPackage,kobs-ng))

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);
}