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,42 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=fitblk
PKG_RELEASE:=2
PKG_LICENSE:=GPL-2.0-only
PKG_MAINTAINER:=Daniel Golle <daniel@makrotopia.org>
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
PKG_FLAGS:=nonshared
include $(INCLUDE_DIR)/package.mk
define Package/fitblk
HIDDEN:=1
SECTION:=base
CATEGORY:=Base system
TITLE:=fitblk firmware release tool
endef
define Package/fitblk/description
Release uImage.FIT block devices using ioctl.
endef
define Build/Configure
endef
define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
CC="$(TARGET_CC)" \
CFLAGS="$(TARGET_CFLAGS) -Wall -Werror" \
LDFLAGS="$(TARGET_LDFLAGS)"
endef
define Package/fitblk/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/fitblk $(1)/usr/sbin/
$(INSTALL_DIR) $(1)/lib/upgrade
$(INSTALL_DATA) ./files/fit.sh $(1)/lib/upgrade
endef
$(eval $(call BuildPackage,fitblk))

View File

@@ -0,0 +1,63 @@
export_fitblk_bootdev() {
[ -e /sys/firmware/devicetree/base/chosen/rootdisk ] || return
local rootdisk="$(cat /sys/firmware/devicetree/base/chosen/rootdisk)"
local handle bootdev
for handle in /sys/class/mtd/mtd*/of_node/volumes/*/phandle; do
[ ! -e "$handle" ] && continue
if [ "$rootdisk" = "$(cat "$handle")" ]; then
if [ -e "${handle%/phandle}/volname" ]; then
export CI_KERNPART="$(cat "${handle%/phandle}/volname")"
elif [ -e "${handle%/phandle}/volid" ]; then
export CI_KERNVOLID="$(cat "${handle%/phandle}/volid")"
else
return
fi
export CI_UBIPART="$(cat "${handle%%/of_node*}/name")"
export CI_METHOD="ubi"
return
fi
done
for handle in /sys/class/mtd/mtd*/of_node/phandle; do
[ ! -e "$handle" ] && continue
if [ "$rootdisk" = "$(cat $handle)" ]; then
bootdev="${handle%/of_node/phandle}"
bootdev="${bootdev#/sys/class/mtd/}"
export PART_NAME="/dev/$bootdev"
export CI_METHOD="default"
return
fi
done
for handle in /sys/class/block/*/of_node/phandle; do
[ ! -e "$handle" ] && continue
if [ "$rootdisk" = "$(cat $handle)" ]; then
bootdev="${handle%/of_node/phandle}"
bootdev="${bootdev#/sys/class/block/}"
export EMMC_KERN_DEV="/dev/$bootdev"
export CI_METHOD="emmc"
return
fi
done
}
fit_do_upgrade() {
export_fitblk_bootdev
[ -n "$CI_METHOD" ] || return 1
[ -e /dev/fit0 ] && fitblk /dev/fit0
[ -e /dev/fitrw ] && fitblk /dev/fitrw
case "$CI_METHOD" in
emmc)
emmc_do_upgrade "$1"
;;
default)
default_do_upgrade "$1"
;;
ubi)
nand_do_upgrade "$1"
;;
esac
}

View File

@@ -0,0 +1,7 @@
all: fitblk
fitblk:
$(CC) $(CFLAGS) -o $@ fitblk.c $(LDFLAGS)
clean:
rm -f fitblk

View File

@@ -0,0 +1,45 @@
// SPDX-License-Identifier: GPL-2.0-only
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/fitblk.h>
static int fitblk_release(char *device)
{
int fd, ret;
fd = open(device, O_RDONLY);
if (fd == -1)
return errno;
ret = ioctl(fd, FITBLK_RELEASE, NULL);
close(fd);
if (ret == -1)
return errno;
return 0;
}
int main(int argc, char *argp[])
{
int ret;
if (argc != 2) {
fprintf(stderr, "Release uImage.FIT sub-image block device\n");
fprintf(stderr, "Syntax: %s /dev/fitXXX\n", argp[0]);
return -EINVAL;
}
ret = fitblk_release(argp[1]);
if (ret)
fprintf(stderr, "fitblk: error releasing %s: %s\n", argp[1],
strerror(ret));
else
fprintf(stderr, "fitblk: %s released\n", argp[1]);
return ret;
}