Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
42 changes: 42 additions & 0 deletions feeds/mediatek/fitblk/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=fitblk
PKG_RELEASE:=2
PKG_LICENSE:=GPL-2.0-only
PKG_MAINTAINER:=Daniel Golle <[email protected]>

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))
63 changes: 63 additions & 0 deletions feeds/mediatek/fitblk/files/fit.sh
Original file line number Diff line number Diff line change
@@ -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
}
24 changes: 24 additions & 0 deletions feeds/mediatek/fitblk/patches/100-header.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--- a/fitblk.c
+++ b/fitblk.c
@@ -5,7 +5,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
-#include <linux/fitblk.h>
+#include "fitblk.h"

static int fitblk_release(char *device)
{
--- /dev/null
+++ b/fitblk.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+#ifndef _LINUX_FITBLK_H
+#define _LINUX_FITBLK_H
+
+/*
+ * IOCTL commands --- we will commandeer 0x46 ('F')
+ */
+#define FITBLK_RELEASE 0x4600
+
+#endif /* _LINUX_FITBLK_H */
7 changes: 7 additions & 0 deletions feeds/mediatek/fitblk/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
all: fitblk

fitblk:
$(CC) $(CFLAGS) -o $@ fitblk.c $(LDFLAGS)

clean:
rm -f fitblk
45 changes: 45 additions & 0 deletions feeds/mediatek/fitblk/src/fitblk.c
Original file line number Diff line number Diff line change
@@ -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;
}
141 changes: 141 additions & 0 deletions feeds/mediatek/fstools/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#
# Copyright (C) 2014-2015 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:=fstools
PKG_RELEASE:=1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL=$(PROJECT_GIT)/project/fstools.git
PKG_MIRROR_HASH:=8fd5e2a582114c07066cabf90cf490c749735ee9839c3e13149b71aaab8ba522
PKG_SOURCE_DATE:=2024-07-14
PKG_SOURCE_VERSION:=408c2cc48e6694446c89da7f8121b399063e1067
CMAKE_INSTALL:=1

PKG_LICENSE:=GPL-2.0
PKG_LICENSE_FILES:=

PKG_BUILD_FLAGS:=no-mips16
PKG_FLAGS:=nonshared

PKG_BUILD_DEPENDS := util-linux
PKG_CONFIG_DEPENDS := CONFIG_NAND_SUPPORT CONFIG_FSTOOLS_UBIFS_EXTROOT

PKG_MAINTAINER:=John Crispin <[email protected]>

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk

CMAKE_OPTIONS += $(if $(CONFIG_FSTOOLS_UBIFS_EXTROOT),-DCMAKE_UBIFS_EXTROOT=y)
CMAKE_OPTIONS += $(if $(CONFIG_FSTOOLS_OVL_MOUNT_FULL_ACCESS_TIME),-DCMAKE_OVL_MOUNT_FULL_ACCESS_TIME=y)
CMAKE_OPTIONS += $(if $(CONFIG_FSTOOLS_OVL_MOUNT_COMPRESS_ZLIB),-DCMAKE_OVL_MOUNT_COMPRESS_ZLIB=y)

define Package/fstools
SECTION:=base
CATEGORY:=Base system
DEPENDS:=+ubox +NAND_SUPPORT:ubi-utils
TITLE:=OpenWrt filesystem tools
MENU:=1
endef

define Package/fstools/config
config FSTOOLS_UBIFS_EXTROOT
depends on PACKAGE_fstools
depends on NAND_SUPPORT
bool "Support extroot functionality with UBIFS"
default y
help
This option makes it possible to use extroot functionality if the root filesystem resides on an UBIFS partition

config FSTOOLS_OVL_MOUNT_FULL_ACCESS_TIME
depends on PACKAGE_fstools
bool "Full access time accounting"
default n
help
This option enables the full access time accounting (warning: it will increase the flash writes).

config FSTOOLS_OVL_MOUNT_COMPRESS_ZLIB
depends on PACKAGE_fstools
bool "Compress using zlib"
default n
help
This option enables the compression using zlib on the storage device.
endef

define Package/snapshot-tool
SECTION:=base
CATEGORY:=Base system
TITLE:=rootfs snapshoting tool
DEPENDS:=+libubox +fstools
endef

define Package/block-mount/conffiles
/etc/config/fstab
endef

define Package/block-mount
SECTION:=base
CATEGORY:=Base system
TITLE:=Block device mounting and checking
DEPENDS:=+ubox +libubox +libuci +libblobmsg-json +libjson-c
endef

define Package/blockd
SECTION:=base
CATEGORY:=Base system
TITLE:=Block device automounting
DEPENDS:=+block-mount +fstools +libubus +kmod-fs-autofs4 +libblobmsg-json +libjson-c
endef

define Package/fstools/install
$(INSTALL_DIR) $(1)/sbin $(1)/lib

$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/{mount_root,jffs2reset} $(1)/sbin/
$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libfstools.so $(1)/lib/
$(LN) jffs2reset $(1)/sbin/jffs2mark
endef

define Package/snapshot-tool/install
$(INSTALL_DIR) $(1)/sbin

$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/snapshot_tool $(1)/sbin/
$(INSTALL_BIN) ./files/snapshot $(1)/sbin/
endef

define Package/block-mount/install
$(INSTALL_DIR) $(1)/sbin $(1)/lib $(1)/usr/sbin $(1)/etc/hotplug.d/block $(1)/etc/init.d/ $(1)/etc/uci-defaults/

$(INSTALL_BIN) ./files/fstab.init $(1)/etc/init.d/fstab
$(INSTALL_CONF) ./files/fstab.default $(1)/etc/uci-defaults/10-fstab
$(INSTALL_CONF) ./files/mount.hotplug $(1)/etc/hotplug.d/block/10-mount
$(INSTALL_CONF) ./files/media-change.hotplug $(1)/etc/hotplug.d/block/00-media-change

$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/block $(1)/sbin/
$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libblkid-tiny.so $(1)/lib/
$(LN) ../../sbin/block $(1)/usr/sbin/swapon
$(LN) ../../sbin/block $(1)/usr/sbin/swapoff

endef

define Package/blockd/install
$(INSTALL_DIR) $(1)/sbin $(1)/etc/init.d/
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/blockd $(1)/sbin/
$(INSTALL_BIN) ./files/blockd.init $(1)/etc/init.d/blockd
endef

define Build/InstallDev
$(INSTALL_DIR) $(1)/usr/include
$(CP) $(PKG_INSTALL_DIR)/usr/include/*.h $(1)/usr/include/
$(INSTALL_DIR) $(1)/usr/lib/
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libubi-utils.a $(1)/usr/lib/
endef

$(eval $(call BuildPackage,fstools))
$(eval $(call BuildPackage,snapshot-tool))
$(eval $(call BuildPackage,block-mount))
$(eval $(call BuildPackage,blockd))
22 changes: 22 additions & 0 deletions feeds/mediatek/fstools/files/blockd.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh /etc/rc.common

START=80

USE_PROCD=1
PROG=/sbin/blockd

service_triggers() {
procd_add_reload_trigger "fstab"
}

reload_service() {
block autofs start
}

start_service() {
procd_open_instance
procd_set_param command "$PROG"
procd_set_param watch block
procd_set_param respawn
procd_close_instance
}
2 changes: 2 additions & 0 deletions feeds/mediatek/fstools/files/fstab.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[ ! -f /etc/config/fstab ] && ( block detect > /etc/config/fstab )
exit 0
22 changes: 22 additions & 0 deletions feeds/mediatek/fstools/files/fstab.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh /etc/rc.common
# SPDX-License-Identifier: GPL-2.0-only
#
# Copyright (C) 2013-2020 OpenWrt.org

START=11

boot() {
/sbin/block mount
}

start() {
return 0
}

restart() {
return 0
}

stop() {
/sbin/block umount
}
8 changes: 8 additions & 0 deletions feeds/mediatek/fstools/files/media-change.hotplug
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[ -n "$DISK_MEDIA_CHANGE" ] && /sbin/block info

if [ "$ACTION" = "add" -a "$DEVTYPE" = "disk" ]; then
case "$DEVNAME" in
mtd*) : ;;
*) echo 2000 > /sys/block/$DEVNAME/events_poll_msecs ;;
esac
fi
1 change: 1 addition & 0 deletions feeds/mediatek/fstools/files/mount.hotplug
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ "$ACTION" = "add" -o "$ACTION" = "remove" ] && /sbin/block hotplug
Loading