From 7b04258446e92c717260df3e4401828aeb8ba814 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Tue, 23 Jul 2024 17:24:04 +0900 Subject: [PATCH 01/16] packaging: Add missing overlay dt binary files In rpi5, dtb files are also used for dt overlays. Add the missing overlay dt binary files to packaging spec. This fixes below boot firmware logs from rpi5: 6.26 [sdcard] /overlays/overlay_map.dtb not found 6.27 /overlays/overlay_map.dtb Change-Id: I5382f3092d8b0ada366f4b39402f2de016091b36 Signed-off-by: Seung-Woo Kim --- build-rpi4.sh | 2 +- packaging/linux-rpi4.spec | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build-rpi4.sh b/build-rpi4.sh index 92df5cfb..1267e32 100755 --- a/build-rpi4.sh +++ b/build-rpi4.sh @@ -72,7 +72,7 @@ function mk_bootimg() cp -a arch/arm/boot/dts/broadcom/bcm*.dtb ${TMP_PATH} fi mkdir -p ${TMP_PATH}/overlays - cp -a arch/arm/boot/dts/overlays/*.dtbo ${TMP_PATH}/overlays + cp -a arch/arm/boot/dts/overlays/*.dtb* ${TMP_PATH}/overlays # install u-boot files extracted from u-boot-rpi4 rpm package in download.tizen.org. rm -rf ${TMP_UBOOT_PATH} diff --git a/packaging/linux-rpi4.spec b/packaging/linux-rpi4.spec index e739064..02237d1 100644 --- a/packaging/linux-rpi4.spec +++ b/packaging/linux-rpi4.spec @@ -191,7 +191,7 @@ install -m 644 rpi4/boot/fixup*.dat %{buildroot}/boot/ # Install kernel DTB install -m 644 build/%{variant}/arch/%{buildarch}/boot/dts/broadcom/bcm*.dtb %{buildroot}/boot/ mkdir -p %{buildroot}/boot/overlays -install -m 644 build/%{variant}/arch/%{buildarch}/boot/dts/overlays/*.dtbo %{buildroot}/boot/overlays/ +install -m 644 build/%{variant}/arch/%{buildarch}/boot/dts/overlays/*.dtb* %{buildroot}/boot/overlays/ # Install kernel headers make O=build/%{variant} headers_install %{?_smp_mflags} INSTALL_HDR_PATH=%{buildroot}/usr @@ -300,7 +300,7 @@ mv /boot/zImage /boot/zImage_rt /boot/zImage %endif /boot/bcm*.dtb -/boot/overlays/*.dtbo +/boot/overlays/*.dtb* /boot/config.txt /boot/LICENCE.broadcom /boot/start*.elf @@ -314,7 +314,7 @@ mv /boot/zImage /boot/zImage_rt /boot/zImage_rt %endif /boot/bcm*.dtb -/boot/overlays/*.dtbo +/boot/overlays/*.dtb* /boot/config.txt /boot/LICENCE.broadcom /boot/start*.elf -- 2.7.4 From a1201037d65e7e56f5ef6ba4ae7719af1d241f49 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Wed, 24 Jul 2024 13:37:58 +0900 Subject: [PATCH 02/16] ARM64: configs: tizen: Adjust for mipi csi camera of rpi5 To use mipi csi camera in rpi5, it is required dw i2c for the rpi5 board. Also, to support mipi csi of rpi5, pisp_be. Adjust for mipi csi camera of rpi5 and build camera sensors as module because they are only used when connected. Change-Id: I9b59b0f3816ba6a7801028162870566e262f23f5 Signed-off-by: Seung-Woo Kim --- arch/arm64/configs/tizen_bcm2711_defconfig | 6 ++++-- arch/arm64/configs/tizen_bcm2711_rt_defconfig | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/arm64/configs/tizen_bcm2711_defconfig b/arch/arm64/configs/tizen_bcm2711_defconfig index 9c1631b..d0cfe5c 100644 --- a/arch/arm64/configs/tizen_bcm2711_defconfig +++ b/arch/arm64/configs/tizen_bcm2711_defconfig @@ -282,6 +282,7 @@ CONFIG_I2C_MUX=y CONFIG_I2C_MUX_PINCTRL=y CONFIG_I2C_BCM2708=m CONFIG_I2C_BCM2835=y +CONFIG_I2C_DESIGNWARE_PLATFORM=m CONFIG_I2C_GPIO=y CONFIG_I2C_STUB=m CONFIG_SPI=y @@ -334,9 +335,10 @@ CONFIG_USB_VIDEO_CLASS=y CONFIG_V4L_PLATFORM_DRIVERS=y CONFIG_VIDEO_MUX=y CONFIG_VIDEO_BCM2835_UNICAM=y +CONFIG_VIDEO_RASPBERRYPI_PISP_BE=y CONFIG_VIDEO_RP1_CFE=y -CONFIG_VIDEO_IMX219=y -CONFIG_VIDEO_IMX708=y +CONFIG_VIDEO_IMX219=m +CONFIG_VIDEO_IMX708=m CONFIG_VIDEO_OV5647=y CONFIG_VIDEO_DW9807_VCM=y CONFIG_DRM=y diff --git a/arch/arm64/configs/tizen_bcm2711_rt_defconfig b/arch/arm64/configs/tizen_bcm2711_rt_defconfig index b6c5da7..0c555082 100644 --- a/arch/arm64/configs/tizen_bcm2711_rt_defconfig +++ b/arch/arm64/configs/tizen_bcm2711_rt_defconfig @@ -284,6 +284,7 @@ CONFIG_I2C_MUX=y CONFIG_I2C_MUX_PINCTRL=y CONFIG_I2C_BCM2708=m CONFIG_I2C_BCM2835=y +CONFIG_I2C_DESIGNWARE_PLATFORM=m CONFIG_I2C_GPIO=y CONFIG_I2C_STUB=m CONFIG_SPI=y @@ -336,9 +337,10 @@ CONFIG_USB_VIDEO_CLASS=y CONFIG_V4L_PLATFORM_DRIVERS=y CONFIG_VIDEO_MUX=y CONFIG_VIDEO_BCM2835_UNICAM=y +CONFIG_VIDEO_RASPBERRYPI_PISP_BE=y CONFIG_VIDEO_RP1_CFE=y -CONFIG_VIDEO_IMX219=y -CONFIG_VIDEO_IMX708=y +CONFIG_VIDEO_IMX219=m +CONFIG_VIDEO_IMX708=m CONFIG_VIDEO_OV5647=y CONFIG_VIDEO_DW9807_VCM=y CONFIG_DRM=y -- 2.7.4 From ef42d5799ec6ac7e0b0bb13cfa9fe5be11f5bdd9 Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Thu, 11 Jul 2024 16:41:45 +0200 Subject: [PATCH 03/16] initramfs: break loop when decompression finishes This fixes booting with initramfs (cpio.gz based) with additional garbage added after the main initramfs image. The below message is displayed during booting. [ 0.546162] rootfs image is not initramfs (invalid magic at start of compressed archive); looks like an initrd Change-Id: Iddf10f6696c7d15ec68d29bc69614523c9fd9b65 Signed-off-by: Marek Szyprowski --- init/initramfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/init/initramfs.c b/init/initramfs.c index efc477b..fb4e9d0 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -520,6 +520,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned long len) &my_inptr, error); if (res) error("decompressor failed"); + break; } else if (compress_name) { if (!message) { snprintf(msg_buf, sizeof msg_buf, -- 2.7.4 From ee5e7f0e1dc28123109f4c0651328aa310a6a8e7 Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Thu, 5 Sep 2024 13:49:49 +0200 Subject: [PATCH 04/16] Revert "misc: add Tizen reboot notifier for passing reboot parameter" Tizen specific inform-reboot kernel module has been moved to linux-tizen-modules-source repository, so keeping a copy of it in each kernel repository is not needed anymore. This reverts commit c9458239ab7b0103ff1d94958eb1b9a97968f938. Signed-off-by: Marek Szyprowski Change-Id: Ic73b4f6fc30ebb9699acbfa2bd98e0cf97ff6c7a --- drivers/misc/Kconfig | 16 --------- drivers/misc/Makefile | 1 - drivers/misc/tizen-inform-reboot.c | 71 -------------------------------------- 3 files changed, 88 deletions(-) delete mode 100644 drivers/misc/tizen-inform-reboot.c diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 75cdf21..a76c6c9 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -570,22 +570,6 @@ config TPS6594_PFSM This driver can also be built as a module. If so, the module will be called tps6594-pfsm. -config TIZEN_INFORM_REBOOT - bool "Tizen reboot parameter passing support" - default "n" - help - This enables support for passing reboot parameter through inform - partition. It is required to determine booting mode (e.g., fota or - normal). After passing reboot parameter, u-boot checks the contents - of inform file and then determines proper booting mode. - -config TIZEN_INFORM_PATH - depends on TIZEN_INFORM_REBOOT - string "Absolute path of inform file for passing reboot parameter" - help - This option determines the absolute path of inform file for passing - reboot parameter. - source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig" diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 777161c..02bc566 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -68,4 +68,3 @@ obj-$(CONFIG_TMR_MANAGER) += xilinx_tmr_manager.o obj-$(CONFIG_TMR_INJECT) += xilinx_tmr_inject.o obj-$(CONFIG_TPS6594_ESM) += tps6594-esm.o obj-$(CONFIG_TPS6594_PFSM) += tps6594-pfsm.o -obj-$(CONFIG_TIZEN_INFORM_REBOOT) += tizen-inform-reboot.o diff --git a/drivers/misc/tizen-inform-reboot.c b/drivers/misc/tizen-inform-reboot.c deleted file mode 100644 index f85386e..0000000 --- a/drivers/misc/tizen-inform-reboot.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Tizen reboot parameter passing notifier - * - * Written by: Junghoon Kim - * - * Copyright (C) 2017 Samsung Electronics Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ - -#include -#include -#include -#include -#include -#include - -static int inform_reboot_notifier(struct notifier_block *nb, - unsigned long val, void *buf) -{ - char *cmd = buf; - char *filename = CONFIG_TIZEN_INFORM_PATH; - struct file *file; - loff_t pos = 0; - - file = filp_open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644); - if (!IS_ERR(file)) { - struct super_block *sb = file->f_path.dentry->d_sb; - - if (cmd) { - if (!strncmp(cmd, "fota", 4)) - cmd = "upgr"; - else if (!strncmp(cmd, "recovery", 8)) - cmd = "rcvr"; - else if (!strncmp(cmd, "download", 8)) - cmd = "dwnl"; - else - cmd = "ndef"; - } else - cmd = "norm"; - - kernel_write(file, cmd, strlen(cmd), &pos); - - down_read(&sb->s_umount); - sync_filesystem(sb); - up_read(&sb->s_umount); - - fput(file); - } else { - pr_err("Reboot parameter passing is failed.\n" - "Inform file path should be described correctly in config.\n"); - } - - return NOTIFY_DONE; -} - -static struct notifier_block nb_inform_reboot_block = { - .notifier_call = inform_reboot_notifier, - .priority = 256, -}; - -static int __init inform_reboot_init(void) -{ - /* to support reboot parameter passing */ - register_reboot_notifier(&nb_inform_reboot_block); - return 0; -} - -subsys_initcall(inform_reboot_init); -- 2.7.4 From 07a05165dac9edabcc70be6733398a515b74d4be Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Fri, 6 Sep 2024 08:07:05 +0200 Subject: [PATCH 05/16] ARM/ARM64: configs: tizen: drop TIZEN_INFORM_REBOOT Tizen specific inform-reboot module has been moved to external linux-tizen-modules repository, so drop it from Tizen's defconfig. Signed-off-by: Marek Szyprowski Change-Id: Ied86f6cd4c47dd6f562a3eaa7e672d3121e50abf --- arch/arm/configs/tizen_bcm2711_defconfig | 2 -- arch/arm/configs/tizen_bcm2711_rt_defconfig | 2 -- arch/arm64/configs/tizen_bcm2711_defconfig | 2 -- arch/arm64/configs/tizen_bcm2711_rt_defconfig | 2 -- 4 files changed, 8 deletions(-) diff --git a/arch/arm/configs/tizen_bcm2711_defconfig b/arch/arm/configs/tizen_bcm2711_defconfig index 0ee62d5..544a1e2 100644 --- a/arch/arm/configs/tizen_bcm2711_defconfig +++ b/arch/arm/configs/tizen_bcm2711_defconfig @@ -204,8 +204,6 @@ CONFIG_BLK_DEV_LOOP=y CONFIG_BLK_DEV_NBD=m CONFIG_BLK_DEV_RAM=y CONFIG_BLK_DEV_RAM_SIZE=32768 -CONFIG_TIZEN_INFORM_REBOOT=y -CONFIG_TIZEN_INFORM_PATH="/mnt/inform/reboot-param.bin" CONFIG_SCSI=y # CONFIG_SCSI_PROC_FS is not set CONFIG_BLK_DEV_SD=y diff --git a/arch/arm/configs/tizen_bcm2711_rt_defconfig b/arch/arm/configs/tizen_bcm2711_rt_defconfig index b23eb11..351da3f 100644 --- a/arch/arm/configs/tizen_bcm2711_rt_defconfig +++ b/arch/arm/configs/tizen_bcm2711_rt_defconfig @@ -206,8 +206,6 @@ CONFIG_BLK_DEV_LOOP=y CONFIG_BLK_DEV_NBD=m CONFIG_BLK_DEV_RAM=y CONFIG_BLK_DEV_RAM_SIZE=32768 -CONFIG_TIZEN_INFORM_REBOOT=y -CONFIG_TIZEN_INFORM_PATH="/mnt/inform/reboot-param.bin" CONFIG_SCSI=y # CONFIG_SCSI_PROC_FS is not set CONFIG_BLK_DEV_SD=y diff --git a/arch/arm64/configs/tizen_bcm2711_defconfig b/arch/arm64/configs/tizen_bcm2711_defconfig index d0cfe5c..82fa9d9 100644 --- a/arch/arm64/configs/tizen_bcm2711_defconfig +++ b/arch/arm64/configs/tizen_bcm2711_defconfig @@ -203,8 +203,6 @@ CONFIG_BLK_DEV_LOOP=y CONFIG_BLK_DEV_NBD=m CONFIG_BLK_DEV_RAM=y CONFIG_BLK_DEV_RAM_SIZE=32768 -CONFIG_TIZEN_INFORM_REBOOT=y -CONFIG_TIZEN_INFORM_PATH="/mnt/inform/reboot-param.bin" CONFIG_SCSI=y # CONFIG_SCSI_PROC_FS is not set CONFIG_BLK_DEV_SD=y diff --git a/arch/arm64/configs/tizen_bcm2711_rt_defconfig b/arch/arm64/configs/tizen_bcm2711_rt_defconfig index 0c555082..84ce5fe 100644 --- a/arch/arm64/configs/tizen_bcm2711_rt_defconfig +++ b/arch/arm64/configs/tizen_bcm2711_rt_defconfig @@ -205,8 +205,6 @@ CONFIG_BLK_DEV_LOOP=y CONFIG_BLK_DEV_NBD=m CONFIG_BLK_DEV_RAM=y CONFIG_BLK_DEV_RAM_SIZE=32768 -CONFIG_TIZEN_INFORM_REBOOT=y -CONFIG_TIZEN_INFORM_PATH="/mnt/inform/reboot-param.bin" CONFIG_SCSI=y # CONFIG_SCSI_PROC_FS is not set CONFIG_BLK_DEV_SD=y -- 2.7.4 From 3c76e7e1e4890dc60b805968e2e4baf47c32e8cb Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Mon, 9 Sep 2024 13:35:54 +0200 Subject: [PATCH 06/16] Revert "device-mapper: Add dm-bow" The dm-bow kernel module (developed externally by Google team) has been moved to linux-tizen-modules-source repository, so keeping a copy of it in each kernel repository is not needed anymore. This reverts commit 540ba0d4e89eec45ddd9d41030fb6cf10392b42a. Signed-off-by: Marek Szyprowski Change-Id: I862b493f66319a651402067a1e81ac7119d5ebdf --- Documentation/device-mapper/dm-bow.txt | 99 --- drivers/md/Kconfig | 20 - drivers/md/Makefile | 1 - drivers/md/dm-bow.c | 1308 -------------------------------- 4 files changed, 1428 deletions(-) delete mode 100644 Documentation/device-mapper/dm-bow.txt delete mode 100644 drivers/md/dm-bow.c diff --git a/Documentation/device-mapper/dm-bow.txt b/Documentation/device-mapper/dm-bow.txt deleted file mode 100644 index e3fc4d2..0000000 --- a/Documentation/device-mapper/dm-bow.txt +++ /dev/null @@ -1,99 +0,0 @@ -dm_bow (backup on write) -======================== - -dm_bow is a device mapper driver that uses the free space on a device to back up -data that is overwritten. The changes can then be committed by a simple state -change, or rolled back by removing the dm_bow device and running a command line -utility over the underlying device. - -dm_bow has three states, set by writing ‘1’ or ‘2’ to /sys/block/dm-?/bow/state. -It is only possible to go from state 0 (initial state) to state 1, and then from -state 1 to state 2. - -State 0: dm_bow collects all trims to the device and assumes that these mark -free space on the overlying file system that can be safely used. Typically the -mount code would create the dm_bow device, mount the file system, call the -FITRIM ioctl on the file system then switch to state 1. These trims are not -propagated to the underlying device. - -State 1: All writes to the device cause the underlying data to be backed up to -the free (trimmed) area as needed in such a way as they can be restored. -However, the writes, with one exception, then happen exactly as they would -without dm_bow, so the device is always in a good final state. The exception is -that sector 0 is used to keep a log of the latest changes, both to indicate that -we are in this state and to allow rollback. See below for all details. If there -isn't enough free space, writes are failed with -ENOSPC. - -State 2: The transition to state 2 triggers replacing the special sector 0 with -the normal sector 0, and the freeing of all state information. dm_bow then -becomes a pass-through driver, allowing the device to continue to be used with -minimal performance impact. - -Usage -===== -dm-bow takes one command line parameter, the name of the underlying device. - -dm-bow will typically be used in the following way. dm-bow will be loaded with a -suitable underlying device and the resultant device will be mounted. A file -system trim will be issued via the FITRIM ioctl, then the device will be -switched to state 1. The file system will now be used as normal. At some point, -the changes can either be committed by switching to state 2, or rolled back by -unmounting the file system, removing the dm-bow device and running the command -line utility. Note that rebooting the device will be equivalent to unmounting -and removing, but the command line utility must still be run - -Details of operation in state 1 -=============================== - -dm_bow maintains a type for all sectors. A sector can be any of: - -SECTOR0 -SECTOR0_CURRENT -UNCHANGED -FREE -CHANGED -BACKUP - -SECTOR0 is the first sector on the device, and is used to hold the log of -changes. This is the one exception. - -SECTOR0_CURRENT is a sector picked from the FREE sectors, and is where reads and -writes from the true sector zero are redirected to. Note that like any backup -sector, if the sector is written to directly, it must be moved again. - -UNCHANGED means that the sector has not been changed since we entered state 1. -Thus if it is written to or trimmed, the contents must first be backed up. - -FREE means that the sector was trimmed in state 0 and has not yet been written -to or used for backup. On being written to, a FREE sector is changed to CHANGED. - -CHANGED means that the sector has been modified, and can be further modified -without further backup. - -BACKUP means that this is a free sector being used as a backup. On being written -to, the contents must first be backed up again. - -All backup operations are logged to the first sector. The log sector has the -format: --------------------------------------------------------- -| Magic | Count | Sequence | Log entry | Log entry | … --------------------------------------------------------- - -Magic is a magic number. Count is the number of log entries. Sequence is 0 -initially. A log entry is - ------------------------------------ -| Source | Dest | Size | Checksum | ------------------------------------ - -When SECTOR0 is full, the log sector is backed up and another empty log sector -created with sequence number one higher. The first entry in any log entry with -sequence > 0 therefore must be the log of the backing up of the previous log -sector. Note that sequence is not strictly needed, but is a useful sanity check -and potentially limits the time spent trying to restore a corrupted snapshot. - -On entering state 1, dm_bow has a list of free sectors. All other sectors are -unchanged. Sector0_current is selected from the free sectors and the contents of -sector 0 are copied there. The sector 0 is backed up, which triggers the first -log entry to be written. - diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig index f419ab5..3ff87cb 100644 --- a/drivers/md/Kconfig +++ b/drivers/md/Kconfig @@ -532,26 +532,6 @@ config DM_FLAKEY help A target that intermittently fails I/O for debugging purposes. -config DM_BOW - tristate "BOW support" - depends on BLK_DEV_DM - select CRYPTO - select CRYPTO_HASH - select DM_BUFIO - help - This device-mapper target creates a read-only device that - transparently validates the data on one underlying device against - a pre-generated tree of cryptographic checksums stored on a second - device. - - You'll need to activate the digests you're going to use in the - cryptoapi configuration. - - To compile this code as a module, choose M here: the module will - be called dm-verity. - - If unsure, say N. - config DM_VERITY tristate "Verity target support" depends on BLK_DEV_DM diff --git a/drivers/md/Makefile b/drivers/md/Makefile index d7df593..84291e3 100644 --- a/drivers/md/Makefile +++ b/drivers/md/Makefile @@ -83,7 +83,6 @@ obj-$(CONFIG_DM_LOG_WRITES) += dm-log-writes.o obj-$(CONFIG_DM_INTEGRITY) += dm-integrity.o obj-$(CONFIG_DM_ZONED) += dm-zoned.o obj-$(CONFIG_DM_WRITECACHE) += dm-writecache.o -obj-$(CONFIG_DM_BOW) += dm-bow.o obj-$(CONFIG_SECURITY_LOADPIN_VERITY) += dm-verity-loadpin.o ifeq ($(CONFIG_DM_INIT),y) diff --git a/drivers/md/dm-bow.c b/drivers/md/dm-bow.c deleted file mode 100644 index ea6cbf9..0000000 --- a/drivers/md/dm-bow.c +++ /dev/null @@ -1,1308 +0,0 @@ -/* - * Copyright (C) 2018 Google Limited. - * - * This file is released under the GPL. - */ - -#include "dm.h" -#include "dm-core.h" - -#include -#include -#include - -#define DM_MSG_PREFIX "bow" - -struct log_entry { - u64 source; - u64 dest; - u32 size; - u32 checksum; -} __packed; - -struct log_sector { - u32 magic; - u16 header_version; - u16 header_size; - u32 block_size; - u32 count; - u32 sequence; - sector_t sector0; - struct log_entry entries[]; -} __packed; - -/* - * MAGIC is BOW in ascii - */ -#define MAGIC 0x00574f42 -#define HEADER_VERSION 0x0100 - -/* - * A sorted set of ranges representing the state of the data on the device. - * Use an rb_tree for fast lookup of a given sector - * Consecutive ranges are always of different type - operations on this - * set must merge matching consecutive ranges. - * - * Top range is always of type TOP - */ -struct bow_range { - struct rb_node node; - sector_t sector; - enum { - INVALID, /* Type not set */ - SECTOR0, /* First sector - holds log record */ - SECTOR0_CURRENT,/* Live contents of sector0 */ - UNCHANGED, /* Original contents */ - TRIMMED, /* Range has been trimmed */ - CHANGED, /* Range has been changed */ - BACKUP, /* Range is being used as a backup */ - TOP, /* Final range - sector is size of device */ - } type; - struct list_head trimmed_list; /* list of TRIMMED ranges */ -}; - -static const char * const readable_type[] = { - "Invalid", - "Sector0", - "Sector0_current", - "Unchanged", - "Free", - "Changed", - "Backup", - "Top", -}; - -enum state { - TRIM, - CHECKPOINT, - COMMITTED, -}; - -struct bow_context { - struct dm_dev *dev; - u32 block_size; - u32 block_shift; - struct workqueue_struct *workqueue; - struct dm_bufio_client *bufio; - struct mutex ranges_lock; /* Hold to access this struct and/or ranges */ - struct rb_root ranges; - struct dm_kobject_holder kobj_holder; /* for sysfs attributes */ - atomic_t state; /* One of the enum state values above */ - u64 trims_total; - struct log_sector *log_sector; - struct list_head trimmed_list; - bool forward_trims; -}; - -sector_t range_top(struct bow_range *br) -{ - return container_of(rb_next(&br->node), struct bow_range, node) - ->sector; -} - -u64 range_size(struct bow_range *br) -{ - return (range_top(br) - br->sector) * SECTOR_SIZE; -} - -static sector_t bvec_top(struct bvec_iter *bi_iter) -{ - return bi_iter->bi_sector + bi_iter->bi_size / SECTOR_SIZE; -} - -/* - * Find the first range that overlaps with bi_iter - * bi_iter is set to the size of the overlapping sub-range - */ -static struct bow_range *find_first_overlapping_range(struct rb_root *ranges, - struct bvec_iter *bi_iter) -{ - struct rb_node *node = ranges->rb_node; - struct bow_range *br; - - while (node) { - br = container_of(node, struct bow_range, node); - - if (br->sector <= bi_iter->bi_sector - && bi_iter->bi_sector < range_top(br)) - break; - - if (bi_iter->bi_sector < br->sector) - node = node->rb_left; - else - node = node->rb_right; - } - - WARN_ON(!node); - if (!node) - return NULL; - - if (range_top(br) - bi_iter->bi_sector - < bi_iter->bi_size >> SECTOR_SHIFT) - bi_iter->bi_size = (range_top(br) - bi_iter->bi_sector) - << SECTOR_SHIFT; - - return br; -} - -void add_before(struct rb_root *ranges, struct bow_range *new_br, - struct bow_range *existing) -{ - struct rb_node *parent = &(existing->node); - struct rb_node **link = &(parent->rb_left); - - while (*link) { - parent = *link; - link = &((*link)->rb_right); - } - - rb_link_node(&new_br->node, parent, link); - rb_insert_color(&new_br->node, ranges); -} - -/* - * Given a range br returned by find_first_overlapping_range, split br into a - * leading range, a range matching the bi_iter and a trailing range. - * Leading and trailing may end up size 0 and will then be deleted. The - * new range matching the bi_iter is then returned and should have its type - * and type specific fields populated. - * If bi_iter runs off the end of the range, bi_iter is truncated accordingly - */ -static int split_range(struct bow_context *bc, struct bow_range **br, - struct bvec_iter *bi_iter) -{ - struct bow_range *new_br; - - if (bi_iter->bi_sector < (*br)->sector) { - WARN_ON(true); - return BLK_STS_IOERR; - } - - if (bi_iter->bi_sector > (*br)->sector) { - struct bow_range *leading_br = - kzalloc(sizeof(*leading_br), GFP_KERNEL); - - if (!leading_br) - return BLK_STS_RESOURCE; - - *leading_br = **br; - if (leading_br->type == TRIMMED) - list_add(&leading_br->trimmed_list, &bc->trimmed_list); - - add_before(&bc->ranges, leading_br, *br); - (*br)->sector = bi_iter->bi_sector; - } - - if (bvec_top(bi_iter) >= range_top(*br)) { - bi_iter->bi_size = (range_top(*br) - (*br)->sector) - * SECTOR_SIZE; - return BLK_STS_OK; - } - - /* new_br will be the beginning, existing br will be the tail */ - new_br = kzalloc(sizeof(*new_br), GFP_KERNEL); - if (!new_br) - return BLK_STS_RESOURCE; - - new_br->sector = (*br)->sector; - (*br)->sector = bvec_top(bi_iter); - add_before(&bc->ranges, new_br, *br); - *br = new_br; - - return BLK_STS_OK; -} - -/* - * Sets type of a range. May merge range into surrounding ranges - * Since br may be invalidated, always sets br to NULL to prevent - * usage after this is called - */ -static void set_type(struct bow_context *bc, struct bow_range **br, int type) -{ - struct bow_range *prev = container_of(rb_prev(&(*br)->node), - struct bow_range, node); - struct bow_range *next = container_of(rb_next(&(*br)->node), - struct bow_range, node); - - if ((*br)->type == TRIMMED) { - bc->trims_total -= range_size(*br); - list_del(&(*br)->trimmed_list); - } - - if (type == TRIMMED) { - bc->trims_total += range_size(*br); - list_add(&(*br)->trimmed_list, &bc->trimmed_list); - } - - (*br)->type = type; - - if (next->type == type) { - if (type == TRIMMED) - list_del(&next->trimmed_list); - rb_erase(&next->node, &bc->ranges); - kfree(next); - } - - if (prev->type == type) { - if (type == TRIMMED) - list_del(&(*br)->trimmed_list); - rb_erase(&(*br)->node, &bc->ranges); - kfree(*br); - } - - *br = NULL; -} - -static struct bow_range *find_free_range(struct bow_context *bc) -{ - if (list_empty(&bc->trimmed_list)) { - DMERR("Unable to find free space to back up to"); - return NULL; - } - - return list_first_entry(&bc->trimmed_list, struct bow_range, - trimmed_list); -} - -static sector_t sector_to_page(struct bow_context const *bc, sector_t sector) -{ - WARN_ON((sector & (((sector_t)1 << (bc->block_shift - SECTOR_SHIFT)) - 1)) - != 0); - return sector >> (bc->block_shift - SECTOR_SHIFT); -} - -static int copy_data(struct bow_context const *bc, - struct bow_range *source, struct bow_range *dest, - u32 *checksum) -{ - int i; - - if (range_size(source) != range_size(dest)) { - WARN_ON(1); - return BLK_STS_IOERR; - } - - if (checksum) - *checksum = sector_to_page(bc, source->sector); - - for (i = 0; i < range_size(source) >> bc->block_shift; ++i) { - struct dm_buffer *read_buffer, *write_buffer; - u8 *read, *write; - sector_t page = sector_to_page(bc, source->sector) + i; - - read = dm_bufio_read(bc->bufio, page, &read_buffer); - if (IS_ERR(read)) { - DMERR("Cannot read page %llu", - (unsigned long long)page); - return PTR_ERR(read); - } - - if (checksum) - *checksum = crc32(*checksum, read, bc->block_size); - - write = dm_bufio_new(bc->bufio, - sector_to_page(bc, dest->sector) + i, - &write_buffer); - if (IS_ERR(write)) { - DMERR("Cannot write sector"); - dm_bufio_release(read_buffer); - return PTR_ERR(write); - } - - memcpy(write, read, bc->block_size); - - dm_bufio_mark_buffer_dirty(write_buffer); - dm_bufio_release(write_buffer); - dm_bufio_release(read_buffer); - } - - dm_bufio_write_dirty_buffers(bc->bufio); - return BLK_STS_OK; -} - -/****** logging functions ******/ - -static int add_log_entry(struct bow_context *bc, sector_t source, sector_t dest, - unsigned int size, u32 checksum); - -static int backup_log_sector(struct bow_context *bc) -{ - struct bow_range *first_br, *free_br; - struct bvec_iter bi_iter; - u32 checksum = 0; - int ret; - - first_br = container_of(rb_first(&bc->ranges), struct bow_range, node); - - if (first_br->type != SECTOR0) { - WARN_ON(1); - return BLK_STS_IOERR; - } - - if (range_size(first_br) != bc->block_size) { - WARN_ON(1); - return BLK_STS_IOERR; - } - - free_br = find_free_range(bc); - /* No space left - return this error to userspace */ - if (!free_br) - return BLK_STS_NOSPC; - bi_iter.bi_sector = free_br->sector; - bi_iter.bi_size = bc->block_size; - ret = split_range(bc, &free_br, &bi_iter); - if (ret) - return ret; - if (bi_iter.bi_size != bc->block_size) { - WARN_ON(1); - return BLK_STS_IOERR; - } - - ret = copy_data(bc, first_br, free_br, &checksum); - if (ret) - return ret; - - bc->log_sector->count = 0; - bc->log_sector->sequence++; - ret = add_log_entry(bc, first_br->sector, free_br->sector, - range_size(first_br), checksum); - if (ret) - return ret; - - set_type(bc, &free_br, BACKUP); - return BLK_STS_OK; -} - -static int add_log_entry(struct bow_context *bc, sector_t source, sector_t dest, - unsigned int size, u32 checksum) -{ - struct dm_buffer *sector_buffer; - u8 *sector; - - if (sizeof(struct log_sector) - + sizeof(struct log_entry) * (bc->log_sector->count + 1) - > bc->block_size) { - int ret = backup_log_sector(bc); - - if (ret) - return ret; - } - - sector = dm_bufio_new(bc->bufio, 0, §or_buffer); - if (IS_ERR(sector)) { - DMERR("Cannot write boot sector"); - dm_bufio_release(sector_buffer); - return BLK_STS_NOSPC; - } - - bc->log_sector->entries[bc->log_sector->count].source = source; - bc->log_sector->entries[bc->log_sector->count].dest = dest; - bc->log_sector->entries[bc->log_sector->count].size = size; - bc->log_sector->entries[bc->log_sector->count].checksum = checksum; - bc->log_sector->count++; - - memcpy(sector, bc->log_sector, bc->block_size); - dm_bufio_mark_buffer_dirty(sector_buffer); - dm_bufio_release(sector_buffer); - dm_bufio_write_dirty_buffers(bc->bufio); - return BLK_STS_OK; -} - -static int prepare_log(struct bow_context *bc) -{ - struct bow_range *free_br, *first_br; - struct bvec_iter bi_iter; - u32 checksum = 0; - int ret; - - /* Carve out first sector as log sector */ - first_br = container_of(rb_first(&bc->ranges), struct bow_range, node); - if (first_br->type != UNCHANGED) { - WARN_ON(1); - return BLK_STS_IOERR; - } - - if (range_size(first_br) < bc->block_size) { - WARN_ON(1); - return BLK_STS_IOERR; - } - bi_iter.bi_sector = 0; - bi_iter.bi_size = bc->block_size; - ret = split_range(bc, &first_br, &bi_iter); - if (ret) - return ret; - first_br->type = SECTOR0; - if (range_size(first_br) != bc->block_size) { - WARN_ON(1); - return BLK_STS_IOERR; - } - - /* Find free sector for active sector0 reads/writes */ - free_br = find_free_range(bc); - if (!free_br) - return BLK_STS_NOSPC; - bi_iter.bi_sector = free_br->sector; - bi_iter.bi_size = bc->block_size; - ret = split_range(bc, &free_br, &bi_iter); - if (ret) - return ret; - - /* Copy data */ - ret = copy_data(bc, first_br, free_br, NULL); - if (ret) - return ret; - - bc->log_sector->sector0 = free_br->sector; - - set_type(bc, &free_br, SECTOR0_CURRENT); - - /* Find free sector to back up original sector zero */ - free_br = find_free_range(bc); - if (!free_br) - return BLK_STS_NOSPC; - bi_iter.bi_sector = free_br->sector; - bi_iter.bi_size = bc->block_size; - ret = split_range(bc, &free_br, &bi_iter); - if (ret) - return ret; - - /* Back up */ - ret = copy_data(bc, first_br, free_br, &checksum); - if (ret) - return ret; - - /* - * Set up our replacement boot sector - it will get written when we - * add the first log entry, which we do immediately - */ - bc->log_sector->magic = MAGIC; - bc->log_sector->header_version = HEADER_VERSION; - bc->log_sector->header_size = sizeof(*bc->log_sector); - bc->log_sector->block_size = bc->block_size; - bc->log_sector->count = 0; - bc->log_sector->sequence = 0; - - /* Add log entry */ - ret = add_log_entry(bc, first_br->sector, free_br->sector, - range_size(first_br), checksum); - if (ret) - return ret; - - set_type(bc, &free_br, BACKUP); - return BLK_STS_OK; -} - -static struct bow_range *find_sector0_current(struct bow_context *bc) -{ - struct bvec_iter bi_iter; - - bi_iter.bi_sector = bc->log_sector->sector0; - bi_iter.bi_size = bc->block_size; - return find_first_overlapping_range(&bc->ranges, &bi_iter); -} - -/****** sysfs interface functions ******/ - -static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr, - char *buf) -{ - struct bow_context *bc = container_of(kobj, struct bow_context, - kobj_holder.kobj); - - return scnprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&bc->state)); -} - -static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, - const char *buf, size_t count) -{ - struct bow_context *bc = container_of(kobj, struct bow_context, - kobj_holder.kobj); - enum state state, original_state; - int ret; - - state = buf[0] - '0'; - if (state < TRIM || state > COMMITTED) { - DMERR("State value %d out of range", state); - return -EINVAL; - } - - mutex_lock(&bc->ranges_lock); - original_state = atomic_read(&bc->state); - if (state != original_state + 1) { - DMERR("Invalid state change from %d to %d", - original_state, state); - ret = -EINVAL; - goto bad; - } - - DMINFO("Switching to state %s", state == CHECKPOINT ? "Checkpoint" - : state == COMMITTED ? "Committed" : "Unknown"); - - if (state == CHECKPOINT) { - ret = prepare_log(bc); - if (ret) { - DMERR("Failed to switch to checkpoint state"); - goto bad; - } - } else if (state == COMMITTED) { - struct bow_range *br = find_sector0_current(bc); - struct bow_range *sector0_br = - container_of(rb_first(&bc->ranges), struct bow_range, - node); - - ret = copy_data(bc, br, sector0_br, 0); - if (ret) { - DMERR("Failed to switch to committed state"); - goto bad; - } - } - atomic_inc(&bc->state); - ret = count; - -bad: - mutex_unlock(&bc->ranges_lock); - return ret; -} - -static ssize_t free_show(struct kobject *kobj, struct kobj_attribute *attr, - char *buf) -{ - struct bow_context *bc = container_of(kobj, struct bow_context, - kobj_holder.kobj); - u64 trims_total; - - mutex_lock(&bc->ranges_lock); - trims_total = bc->trims_total; - mutex_unlock(&bc->ranges_lock); - - return scnprintf(buf, PAGE_SIZE, "%llu\n", trims_total); -} - -static struct kobj_attribute attr_state = __ATTR_RW(state); -static struct kobj_attribute attr_free = __ATTR_RO(free); - -static struct attribute *bow_attrs[] = { - &attr_state.attr, - &attr_free.attr, - NULL -}; -ATTRIBUTE_GROUPS(bow); - -static struct kobj_type bow_ktype = { - .sysfs_ops = &kobj_sysfs_ops, - .default_groups = bow_groups, - .release = dm_kobject_release -}; - -/****** constructor/destructor ******/ - -static void dm_bow_dtr(struct dm_target *ti) -{ - struct bow_context *bc = (struct bow_context *) ti->private; - struct kobject *kobj; - - if (bc->workqueue) - destroy_workqueue(bc->workqueue); - if (bc->bufio) - dm_bufio_client_destroy(bc->bufio); - - kobj = &bc->kobj_holder.kobj; - if (kobj->state_initialized) { - kobject_put(kobj); - wait_for_completion(dm_get_completion_from_kobject(kobj)); - } - - while (rb_first(&bc->ranges)) { - struct bow_range *br = container_of(rb_first(&bc->ranges), - struct bow_range, node); - - rb_erase(&br->node, &bc->ranges); - kfree(br); - } - - mutex_destroy(&bc->ranges_lock); - kfree(bc->log_sector); - kfree(bc); -} - -static void dm_bow_io_hints(struct dm_target *ti, struct queue_limits *limits) -{ - struct bow_context *bc = ti->private; - const unsigned int block_size = bc->block_size; - - limits->logical_block_size = - max_t(unsigned int, limits->logical_block_size, block_size); - limits->physical_block_size = - max_t(unsigned int, limits->physical_block_size, block_size); - limits->io_min = max_t(unsigned int, limits->io_min, block_size); - - if (limits->max_discard_sectors == 0) { - limits->discard_granularity = 1 << 12; - limits->max_hw_discard_sectors = 1 << 15; - limits->max_discard_sectors = 1 << 15; - bc->forward_trims = false; - } else { - limits->discard_granularity = 1 << 12; - bc->forward_trims = true; - } -} - -static int dm_bow_ctr_optional(struct dm_target *ti, unsigned int argc, char **argv) -{ - struct bow_context *bc = ti->private; - struct dm_arg_set as; - static const struct dm_arg _args[] = { - {0, 1, "Invalid number of feature args"}, - }; - unsigned int opt_params; - const char *opt_string; - int err; - char dummy; - - as.argc = argc; - as.argv = argv; - - err = dm_read_arg_group(_args, &as, &opt_params, &ti->error); - if (err) - return err; - - while (opt_params--) { - opt_string = dm_shift_arg(&as); - if (!opt_string) { - ti->error = "Not enough feature arguments"; - return -EINVAL; - } - - if (sscanf(opt_string, "block_size:%u%c", - &bc->block_size, &dummy) == 1) { - if (bc->block_size < SECTOR_SIZE || - bc->block_size > 4096 || - !is_power_of_2(bc->block_size)) { - ti->error = "Invalid block_size"; - return -EINVAL; - } - } else { - ti->error = "Invalid feature arguments"; - return -EINVAL; - } - } - - return 0; -} - -static int dm_bow_ctr(struct dm_target *ti, unsigned int argc, char **argv) -{ - struct bow_context *bc; - struct bow_range *br; - int ret; - - if (argc < 1) { - ti->error = "Invalid argument count"; - return -EINVAL; - } - - bc = kzalloc(sizeof(*bc), GFP_KERNEL); - if (!bc) { - ti->error = "Cannot allocate bow context"; - return -ENOMEM; - } - - ti->num_flush_bios = 1; - ti->num_discard_bios = 1; - ti->private = bc; - - ret = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), - &bc->dev); - if (ret) { - ti->error = "Device lookup failed"; - goto bad; - } - - bc->block_size = - bdev_get_queue(bc->dev->bdev)->limits.logical_block_size; - if (argc > 1) { - ret = dm_bow_ctr_optional(ti, argc - 1, &argv[1]); - if (ret) - goto bad; - } - - bc->block_shift = ilog2(bc->block_size); - bc->log_sector = kzalloc(bc->block_size, GFP_KERNEL); - if (!bc->log_sector) { - ti->error = "Cannot allocate log sector"; - goto bad; - } - - init_completion(&bc->kobj_holder.completion); - mutex_init(&bc->ranges_lock); - bc->ranges = RB_ROOT; - bc->bufio = dm_bufio_client_create(bc->dev->bdev, bc->block_size, 1, 0, - NULL, NULL, 0); - if (IS_ERR(bc->bufio)) { - ti->error = "Cannot initialize dm-bufio"; - ret = PTR_ERR(bc->bufio); - bc->bufio = NULL; - goto bad; - } - - bc->workqueue = alloc_workqueue("dm-bow", - WQ_CPU_INTENSIVE | WQ_MEM_RECLAIM - | WQ_UNBOUND, num_online_cpus()); - if (!bc->workqueue) { - ti->error = "Cannot allocate workqueue"; - ret = -ENOMEM; - goto bad; - } - - INIT_LIST_HEAD(&bc->trimmed_list); - - br = kzalloc(sizeof(*br), GFP_KERNEL); - if (!br) { - ti->error = "Cannot allocate ranges"; - ret = -ENOMEM; - goto bad; - } - - br->sector = ti->len; - br->type = TOP; - rb_link_node(&br->node, NULL, &bc->ranges.rb_node); - rb_insert_color(&br->node, &bc->ranges); - - br = kzalloc(sizeof(*br), GFP_KERNEL); - if (!br) { - ti->error = "Cannot allocate ranges"; - ret = -ENOMEM; - goto bad; - } - - br->sector = 0; - br->type = UNCHANGED; - rb_link_node(&br->node, bc->ranges.rb_node, - &bc->ranges.rb_node->rb_left); - rb_insert_color(&br->node, &bc->ranges); - - ti->discards_supported = true; - - return 0; - -bad: - dm_bow_dtr(ti); - return ret; -} - -void dm_bow_resume(struct dm_target *ti) -{ - struct mapped_device *md = dm_table_get_md(ti->table); - struct bow_context *bc = ti->private; - int ret; - - if (bc->kobj_holder.kobj.state_initialized) - return; - - ret = kobject_init_and_add(&bc->kobj_holder.kobj, &bow_ktype, - &disk_to_dev(dm_disk(md))->kobj, "%s", - "bow"); - if (ret) - ti->error = "Cannot create sysfs node"; -} - -/****** Handle writes ******/ - -static int prepare_unchanged_range(struct bow_context *bc, struct bow_range *br, - struct bvec_iter *bi_iter, - bool record_checksum) -{ - struct bow_range *backup_br; - struct bvec_iter backup_bi; - sector_t log_source, log_dest; - unsigned int log_size; - u32 checksum = 0; - int ret; - int original_type; - sector_t sector0; - - /* Find a free range */ - backup_br = find_free_range(bc); - if (!backup_br) - return BLK_STS_NOSPC; - - /* Carve out a backup range. This may be smaller than the br given */ - backup_bi.bi_sector = backup_br->sector; - backup_bi.bi_size = min(range_size(backup_br), (u64) bi_iter->bi_size); - ret = split_range(bc, &backup_br, &backup_bi); - if (ret) - return ret; - - /* - * Carve out a changed range. This will not be smaller than the backup - * br since the backup br is smaller than the source range and iterator - */ - bi_iter->bi_size = backup_bi.bi_size; - ret = split_range(bc, &br, bi_iter); - if (ret) - return ret; - if (range_size(br) != range_size(backup_br)) { - WARN_ON(1); - return BLK_STS_IOERR; - } - - - /* Copy data over */ - ret = copy_data(bc, br, backup_br, record_checksum ? &checksum : NULL); - if (ret) - return ret; - - /* Add an entry to the log */ - log_source = br->sector; - log_dest = backup_br->sector; - log_size = range_size(br); - - /* - * Set the types. Note that since set_type also amalgamates ranges - * we have to set both sectors to their final type before calling - * set_type on either - */ - original_type = br->type; - sector0 = backup_br->sector; - bc->trims_total -= range_size(backup_br); - if (backup_br->type == TRIMMED) - list_del(&backup_br->trimmed_list); - backup_br->type = br->type == SECTOR0_CURRENT ? SECTOR0_CURRENT - : BACKUP; - br->type = CHANGED; - set_type(bc, &backup_br, backup_br->type); - - /* - * Add the log entry after marking the backup sector, since adding a log - * can cause another backup - */ - ret = add_log_entry(bc, log_source, log_dest, log_size, checksum); - if (ret) { - br->type = original_type; - return ret; - } - - /* Now it is safe to mark this backup successful */ - if (original_type == SECTOR0_CURRENT) - bc->log_sector->sector0 = sector0; - - set_type(bc, &br, br->type); - return ret; -} - -static int prepare_free_range(struct bow_context *bc, struct bow_range *br, - struct bvec_iter *bi_iter) -{ - int ret; - - ret = split_range(bc, &br, bi_iter); - if (ret) - return ret; - set_type(bc, &br, CHANGED); - return BLK_STS_OK; -} - -static int prepare_changed_range(struct bow_context *bc, struct bow_range *br, - struct bvec_iter *bi_iter) -{ - /* Nothing to do ... */ - return BLK_STS_OK; -} - -static int prepare_one_range(struct bow_context *bc, - struct bvec_iter *bi_iter) -{ - struct bow_range *br = find_first_overlapping_range(&bc->ranges, - bi_iter); - switch (br->type) { - case CHANGED: - return prepare_changed_range(bc, br, bi_iter); - - case TRIMMED: - return prepare_free_range(bc, br, bi_iter); - - case UNCHANGED: - case BACKUP: - return prepare_unchanged_range(bc, br, bi_iter, true); - - /* - * We cannot track the checksum for the active sector0, since it - * may change at any point. - */ - case SECTOR0_CURRENT: - return prepare_unchanged_range(bc, br, bi_iter, false); - - case SECTOR0: /* Handled in the dm_bow_map */ - case TOP: /* Illegal - top is off the end of the device */ - default: - WARN_ON(1); - return BLK_STS_IOERR; - } -} - -struct write_work { - struct work_struct work; - struct bow_context *bc; - struct bio *bio; -}; - -static void bow_write(struct work_struct *work) -{ - struct write_work *ww = container_of(work, struct write_work, work); - struct bow_context *bc = ww->bc; - struct bio *bio = ww->bio; - struct bvec_iter bi_iter = bio->bi_iter; - int ret = BLK_STS_OK; - - kfree(ww); - - mutex_lock(&bc->ranges_lock); - do { - ret = prepare_one_range(bc, &bi_iter); - bi_iter.bi_sector += bi_iter.bi_size / SECTOR_SIZE; - bi_iter.bi_size = bio->bi_iter.bi_size - - (bi_iter.bi_sector - bio->bi_iter.bi_sector) - * SECTOR_SIZE; - } while (!ret && bi_iter.bi_size); - - mutex_unlock(&bc->ranges_lock); - - if (!ret) { - bio_set_dev(bio, bc->dev->bdev); - submit_bio(bio); - } else { - DMERR("Write failure with error %d", -ret); - bio->bi_status = ret; - bio_endio(bio); - } -} - -static int queue_write(struct bow_context *bc, struct bio *bio) -{ - struct write_work *ww = kmalloc(sizeof(*ww), GFP_NOIO | __GFP_NORETRY - | __GFP_NOMEMALLOC | __GFP_NOWARN); - if (!ww) { - DMERR("Failed to allocate write_work"); - return -ENOMEM; - } - - INIT_WORK(&ww->work, bow_write); - ww->bc = bc; - ww->bio = bio; - queue_work(bc->workqueue, &ww->work); - return DM_MAPIO_SUBMITTED; -} - -static int handle_sector0(struct bow_context *bc, struct bio *bio) -{ - int ret = DM_MAPIO_REMAPPED; - - if (bio->bi_iter.bi_size > bc->block_size) { - struct bio * split = bio_split(bio, - bc->block_size >> SECTOR_SHIFT, - GFP_NOIO, - &fs_bio_set); - if (!split) { - DMERR("Failed to split bio"); - bio->bi_status = BLK_STS_RESOURCE; - bio_endio(bio); - return DM_MAPIO_SUBMITTED; - } - - bio_chain(split, bio); - split->bi_iter.bi_sector = bc->log_sector->sector0; - bio_set_dev(split, bc->dev->bdev); - submit_bio(split); - - if (bio_data_dir(bio) == WRITE) - ret = queue_write(bc, bio); - } else { - bio->bi_iter.bi_sector = bc->log_sector->sector0; - } - - return ret; -} - -static int add_trim(struct bow_context *bc, struct bio *bio) -{ - struct bow_range *br; - struct bvec_iter bi_iter = bio->bi_iter; - - DMDEBUG("add_trim: %llu, %u", - (unsigned long long)bio->bi_iter.bi_sector, - bio->bi_iter.bi_size); - - do { - br = find_first_overlapping_range(&bc->ranges, &bi_iter); - - switch (br->type) { - case UNCHANGED: - if (!split_range(bc, &br, &bi_iter)) - set_type(bc, &br, TRIMMED); - break; - - case TRIMMED: - /* Nothing to do */ - break; - - default: - /* No other case is legal in TRIM state */ - WARN_ON(true); - break; - } - - bi_iter.bi_sector += bi_iter.bi_size / SECTOR_SIZE; - bi_iter.bi_size = bio->bi_iter.bi_size - - (bi_iter.bi_sector - bio->bi_iter.bi_sector) - * SECTOR_SIZE; - - } while (bi_iter.bi_size); - - bio_endio(bio); - return DM_MAPIO_SUBMITTED; -} - -static int remove_trim(struct bow_context *bc, struct bio *bio) -{ - struct bow_range *br; - struct bvec_iter bi_iter = bio->bi_iter; - - DMDEBUG("remove_trim: %llu, %u", - (unsigned long long)bio->bi_iter.bi_sector, - bio->bi_iter.bi_size); - - do { - br = find_first_overlapping_range(&bc->ranges, &bi_iter); - - switch (br->type) { - case UNCHANGED: - /* Nothing to do */ - break; - - case TRIMMED: - if (!split_range(bc, &br, &bi_iter)) - set_type(bc, &br, UNCHANGED); - break; - - default: - /* No other case is legal in TRIM state */ - WARN_ON(true); - break; - } - - bi_iter.bi_sector += bi_iter.bi_size / SECTOR_SIZE; - bi_iter.bi_size = bio->bi_iter.bi_size - - (bi_iter.bi_sector - bio->bi_iter.bi_sector) - * SECTOR_SIZE; - - } while (bi_iter.bi_size); - - return DM_MAPIO_REMAPPED; -} - -int remap_unless_illegal_trim(struct bow_context *bc, struct bio *bio) -{ - if (!bc->forward_trims && bio_op(bio) == REQ_OP_DISCARD) { - bio->bi_status = BLK_STS_NOTSUPP; - bio_endio(bio); - return DM_MAPIO_SUBMITTED; - } else { - bio_set_dev(bio, bc->dev->bdev); - return DM_MAPIO_REMAPPED; - } -} - -/****** dm interface ******/ - -static int dm_bow_map(struct dm_target *ti, struct bio *bio) -{ - int ret = DM_MAPIO_REMAPPED; - struct bow_context *bc = ti->private; - - if (likely(bc->state.counter == COMMITTED)) - return remap_unless_illegal_trim(bc, bio); - - if (bio_data_dir(bio) == READ && bio->bi_iter.bi_sector != 0) - return remap_unless_illegal_trim(bc, bio); - - if (atomic_read(&bc->state) != COMMITTED) { - enum state state; - - mutex_lock(&bc->ranges_lock); - state = atomic_read(&bc->state); - if (state == TRIM) { - if (bio_op(bio) == REQ_OP_DISCARD) - ret = add_trim(bc, bio); - else if (bio_data_dir(bio) == WRITE) - ret = remove_trim(bc, bio); - else - /* pass-through */; - } else if (state == CHECKPOINT) { - if (bio->bi_iter.bi_sector == 0) - ret = handle_sector0(bc, bio); - else if (bio_data_dir(bio) == WRITE) - ret = queue_write(bc, bio); - else - /* pass-through */; - } else { - /* pass-through */ - } - mutex_unlock(&bc->ranges_lock); - } - - if (ret == DM_MAPIO_REMAPPED) - return remap_unless_illegal_trim(bc, bio); - - return ret; -} - -static void dm_bow_tablestatus(struct dm_target *ti, char *result, - unsigned int maxlen) -{ - char *end = result + maxlen; - struct bow_context *bc = ti->private; - struct rb_node *i; - int trimmed_list_length = 0; - int trimmed_range_count = 0; - struct bow_range *br; - - if (maxlen == 0) - return; - result[0] = 0; - - list_for_each_entry(br, &bc->trimmed_list, trimmed_list) - if (br->type == TRIMMED) { - ++trimmed_list_length; - } else { - scnprintf(result, end - result, - "ERROR: non-trimmed entry in trimmed_list"); - return; - } - - if (!rb_first(&bc->ranges)) { - scnprintf(result, end - result, "ERROR: Empty ranges"); - return; - } - - if (container_of(rb_first(&bc->ranges), struct bow_range, node) - ->sector) { - scnprintf(result, end - result, - "ERROR: First range does not start at sector 0"); - return; - } - - for (i = rb_first(&bc->ranges); i; i = rb_next(i)) { - struct bow_range *br = container_of(i, struct bow_range, node); - - result += scnprintf(result, end - result, "%s: %llu", - readable_type[br->type], - (unsigned long long)br->sector); - if (result >= end) - return; - - result += scnprintf(result, end - result, "\n"); - if (result >= end) - return; - - if (br->type == TRIMMED) - ++trimmed_range_count; - - if (br->type == TOP) { - if (br->sector != ti->len) { - scnprintf(result, end - result, - "\nERROR: Top sector is incorrect"); - } - - if (&br->node != rb_last(&bc->ranges)) { - scnprintf(result, end - result, - "\nERROR: Top sector is not last"); - } - - break; - } - - if (!rb_next(i)) { - scnprintf(result, end - result, - "\nERROR: Last range not of type TOP"); - return; - } - - if (br->sector > range_top(br)) { - scnprintf(result, end - result, - "\nERROR: sectors out of order"); - return; - } - } - - if (trimmed_range_count != trimmed_list_length) - scnprintf(result, end - result, - "\nERROR: not all trimmed ranges in trimmed list"); -} - -static void dm_bow_status(struct dm_target *ti, status_type_t type, - unsigned int status_flags, char *result, - unsigned int maxlen) -{ - switch (type) { - case STATUSTYPE_INFO: - default: - if (maxlen) - result[0] = 0; - break; - - case STATUSTYPE_TABLE: - dm_bow_tablestatus(ti, result, maxlen); - break; - } -} - -int dm_bow_prepare_ioctl(struct dm_target *ti, struct block_device **bdev) -{ - struct bow_context *bc = ti->private; - struct dm_dev *dev = bc->dev; - - *bdev = dev->bdev; - /* Only pass ioctls through if the device sizes match exactly. */ - return ti->len != i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT; -} - -static int dm_bow_iterate_devices(struct dm_target *ti, - iterate_devices_callout_fn fn, void *data) -{ - struct bow_context *bc = ti->private; - - return fn(ti, bc->dev, 0, ti->len, data); -} - -static struct target_type bow_target = { - .name = "bow", - .version = {1, 2, 0}, - .module = THIS_MODULE, - .ctr = dm_bow_ctr, - .resume = dm_bow_resume, - .dtr = dm_bow_dtr, - .map = dm_bow_map, - .status = dm_bow_status, - .prepare_ioctl = dm_bow_prepare_ioctl, - .iterate_devices = dm_bow_iterate_devices, - .io_hints = dm_bow_io_hints, -}; - -int __init dm_bow_init(void) -{ - int r = dm_register_target(&bow_target); - - if (r < 0) - DMERR("registering bow failed %d", r); - return r; -} - -void dm_bow_exit(void) -{ - dm_unregister_target(&bow_target); -} - -MODULE_LICENSE("GPL"); - -module_init(dm_bow_init); -module_exit(dm_bow_exit); -- 2.7.4 From df7620f0578285448a500a780246a7450936ea1f Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Fri, 6 Sep 2024 08:07:05 +0200 Subject: [PATCH 07/16] ARM/ARM64: configs: tizen: drop DM_BOW dm-bow kernel module has been moved to external linux-tizen-modules repository, so drop it from Tizen's defconfig. Signed-off-by: Marek Szyprowski Change-Id: I76c0a73cd9f9ce6291419a21b352886e7098df70 --- arch/arm/configs/tizen_bcm2711_defconfig | 1 - arch/arm/configs/tizen_bcm2711_rt_defconfig | 1 - arch/arm64/configs/tizen_bcm2711_defconfig | 1 - arch/arm64/configs/tizen_bcm2711_rt_defconfig | 1 - 4 files changed, 4 deletions(-) diff --git a/arch/arm/configs/tizen_bcm2711_defconfig b/arch/arm/configs/tizen_bcm2711_defconfig index 544a1e2..368b858 100644 --- a/arch/arm/configs/tizen_bcm2711_defconfig +++ b/arch/arm/configs/tizen_bcm2711_defconfig @@ -213,7 +213,6 @@ CONFIG_BLK_DEV_DM=y CONFIG_DM_CRYPT=y CONFIG_DM_INIT=y CONFIG_DM_UEVENT=y -CONFIG_DM_BOW=y CONFIG_DM_VERITY=y CONFIG_NETDEVICES=y CONFIG_WIREGUARD=y diff --git a/arch/arm/configs/tizen_bcm2711_rt_defconfig b/arch/arm/configs/tizen_bcm2711_rt_defconfig index 351da3f..12fb4a5 100644 --- a/arch/arm/configs/tizen_bcm2711_rt_defconfig +++ b/arch/arm/configs/tizen_bcm2711_rt_defconfig @@ -215,7 +215,6 @@ CONFIG_BLK_DEV_DM=y CONFIG_DM_CRYPT=y CONFIG_DM_INIT=y CONFIG_DM_UEVENT=y -CONFIG_DM_BOW=y CONFIG_DM_VERITY=y CONFIG_NETDEVICES=y CONFIG_WIREGUARD=y diff --git a/arch/arm64/configs/tizen_bcm2711_defconfig b/arch/arm64/configs/tizen_bcm2711_defconfig index 82fa9d9..626ac10 100644 --- a/arch/arm64/configs/tizen_bcm2711_defconfig +++ b/arch/arm64/configs/tizen_bcm2711_defconfig @@ -212,7 +212,6 @@ CONFIG_BLK_DEV_DM=y CONFIG_DM_CRYPT=y CONFIG_DM_INIT=y CONFIG_DM_UEVENT=y -CONFIG_DM_BOW=y CONFIG_DM_VERITY=y CONFIG_NETDEVICES=y CONFIG_WIREGUARD=y diff --git a/arch/arm64/configs/tizen_bcm2711_rt_defconfig b/arch/arm64/configs/tizen_bcm2711_rt_defconfig index 84ce5fe..afbdf23 100644 --- a/arch/arm64/configs/tizen_bcm2711_rt_defconfig +++ b/arch/arm64/configs/tizen_bcm2711_rt_defconfig @@ -214,7 +214,6 @@ CONFIG_BLK_DEV_DM=y CONFIG_DM_CRYPT=y CONFIG_DM_INIT=y CONFIG_DM_UEVENT=y -CONFIG_DM_BOW=y CONFIG_DM_VERITY=y CONFIG_NETDEVICES=y CONFIG_WIREGUARD=y -- 2.7.4 From cd1aad8aaa2a12470563fd156f3ce3a8581d3ee6 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Fri, 27 Sep 2024 19:17:45 +0900 Subject: [PATCH 08/16] script: build: enable inform_reboot and dm_bow out-of-tree modules Because of TIZEN_INFORM_REBOOT and DM_BOW drop, it should be built from linux-tizen-modules-source as module. Also adjust module list with linux-tizen-modules commit: https://git.tizen.org/cgit/platform/kernel/linux-tizen-modules/commit/?h=tizen&id=e60a1c0a5ec4e20aee046b58700e3320a4b8ee96 Change-Id: Ia1c5c44fe9b7453e51d430b032adf19d55a16b1b Signed-off-by: Seung-Woo Kim --- build-rpi4.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build-rpi4.sh b/build-rpi4.sh index 1267e32..0b134ab 100755 --- a/build-rpi4.sh +++ b/build-rpi4.sh @@ -106,14 +106,16 @@ function mk_tizen_modules() ln -s ${PWD}/include kernel - export BUILD_logger=m export LOGGER_MAIN_BUFFER_SIZE=256 export LOGGER_EVENTS_BUFFER_SIZE=256 export LOGGER_RADIO_BUFFER_SIZE=256 export LOGGER_SYSTEM_BUFFER_SIZE=256 - export BUILD_proc_tsm=m + export BUILD_dm_bow=m + export BUILD_inform_reboot=m export BUILD_kdbus=m + export BUILD_logger=m + export BUILD_proc_tsm=m export BUILD_zlogger=m ARCH="${ARM_ARCH}" CROSS_COMPILE="${CROSS_COMPILER}" make -C kernel KERNELDIR=${BUILD_ROOT} -- 2.7.4 From e6a18dc08636a064944999ea5497478451717ee7 Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Mon, 7 Oct 2024 11:06:10 +0200 Subject: [PATCH 09/16] Revert "initramfs: break loop when decompression finishes" This reverts commit 455261dc71f1db53e458196bf6e00ff766b1b7b1. This workaround is no longer needed after adding initramfs unpacking in Tizen boot script. Signed-off-by: Marek Szyprowski Change-Id: I65cdced9d6f4baed820eed7f442569ef928351a8 --- init/initramfs.c | 1 - 1 file changed, 1 deletion(-) diff --git a/init/initramfs.c b/init/initramfs.c index fb4e9d0..efc477b 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -520,7 +520,6 @@ static char * __init unpack_to_rootfs(char *buf, unsigned long len) &my_inptr, error); if (res) error("decompressor failed"); - break; } else if (compress_name) { if (!message) { snprintf(msg_buf, sizeof msg_buf, -- 2.7.4 From 1a01cc8c5dd70cd37fe8b3bba84fa4169c18993d Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Tue, 8 Oct 2024 12:14:32 +0200 Subject: [PATCH 10/16] rpi4: boot: Switch back to the generic DWC2 overlay Since adding a standalone Tizen-specific kernel extcon-usb-fixed module, which reports USB cable as always connected, the extcon hack/workaround in the DWC2 driver is no longer needed, thus a generic dwc2-overlay can be used. Signed-off-by: Marek Szyprowski Change-Id: Idcd1b2ab5680cc7e57153d768751bbddbc3adfaa --- rpi4/boot/config.txt | 2 +- rpi4/boot/config_64bit.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rpi4/boot/config.txt b/rpi4/boot/config.txt index cb964ac..000e819 100644 --- a/rpi4/boot/config.txt +++ b/rpi4/boot/config.txt @@ -64,7 +64,7 @@ max_framebuffers=2 force_eeprom_read=0 # Enable dwc2 driver -dtoverlay=dwc2-tizen,dr_mode=peripheral +dtoverlay=dwc2,dr_mode=peripheral kernel=u-boot.bin diff --git a/rpi4/boot/config_64bit.txt b/rpi4/boot/config_64bit.txt index 2143670..93b9593 100644 --- a/rpi4/boot/config_64bit.txt +++ b/rpi4/boot/config_64bit.txt @@ -79,7 +79,7 @@ arm_64bit=1 kernel=u-boot.bin # Enable dwc2 driver -dtoverlay=dwc2-tizen,dr_mode=peripheral +dtoverlay=dwc2,dr_mode=peripheral # Enable the camera module camera_auto_detect=1 -- 2.7.4 From c4e0329c456240e8fbf9f7063b908c76fcf4e35c Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Tue, 8 Oct 2024 12:10:27 +0200 Subject: [PATCH 11/16] Revert "overlays: Add dwc2-tizen-overlay" Since adding a standalone Tizen-specific kernel extcon-usb-fixed module, which reports USB cable as always connected, the extcon hack/workaround in the DWC2 driver is no longer needed. This reverts commit ba0b4a5cd974d3a7a016bb6d3a1a533ed00470ca. Signed-off-by: Marek Szyprowski Change-Id: I3b9bf211b0b910cca09f515676f327336b58375e --- arch/arm/boot/dts/overlays/Makefile | 1 - arch/arm/boot/dts/overlays/dwc2-tizen-overlay.dts | 14 -------------- 2 files changed, 15 deletions(-) delete mode 100644 arch/arm/boot/dts/overlays/dwc2-tizen-overlay.dts diff --git a/arch/arm/boot/dts/overlays/Makefile b/arch/arm/boot/dts/overlays/Makefile index 6ea9611..6b60068 100644 --- a/arch/arm/boot/dts/overlays/Makefile +++ b/arch/arm/boot/dts/overlays/Makefile @@ -60,7 +60,6 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \ draws.dtbo \ dwc-otg.dtbo \ dwc2.dtbo \ - dwc2-tizen.dtbo \ edt-ft5406.dtbo \ enc28j60.dtbo \ enc28j60-spi2.dtbo \ diff --git a/arch/arm/boot/dts/overlays/dwc2-tizen-overlay.dts b/arch/arm/boot/dts/overlays/dwc2-tizen-overlay.dts deleted file mode 100644 index d2a929f..0000000 --- a/arch/arm/boot/dts/overlays/dwc2-tizen-overlay.dts +++ /dev/null @@ -1,14 +0,0 @@ -/dts-v1/; -/plugin/; - -#include "dwc2-overlay.dts" - -/{ - compatible = "brcm,bcm2835"; - - fragment@0 { - dwc2_usb: __overlay__ { - g-extcon-always-on; - }; - }; -}; -- 2.7.4 From ca603fdda2861197b2d6c1a3988fa0acdfc7725d Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Tue, 8 Oct 2024 12:07:51 +0200 Subject: [PATCH 12/16] Revert "usb: dwc2: gadget: Set extcon state for usb cable as always true" Since adding a standalone Tizen-specific kernel extcon-usb-fixed module, which reports USB cable as always connected, the extcon hack/workaround in the DWC2 driver is no longer needed. This reverts commit df63e899d9d8298b05656a9c3511756f58837afd. Signed-off-by: Marek Szyprowski Change-Id: I4e8aad53bea292681139b6d2895f2dd1d88cbdf9 --- drivers/usb/dwc2/core.h | 3 --- drivers/usb/dwc2/gadget.c | 20 -------------------- drivers/usb/dwc2/params.c | 5 ----- 3 files changed, 28 deletions(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index bdc8a89..7cf62c0 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -497,9 +497,6 @@ struct dwc2_core_params { u32 g_rx_fifo_size; u32 g_np_tx_fifo_size; u32 g_tx_fifo_size[MAX_EPS_CHANNELS]; -#if IS_ENABLED(CONFIG_EXTCON) - bool g_extcon_always_on; -#endif bool change_speed_quirk; }; diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index 772d871..d3ee700 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -5073,25 +5072,6 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg) hsotg->gadget.quirk_ep_out_aligned_size = true; dwc2_hsotg_dump(hsotg); -#if IS_ENABLED(CONFIG_EXTCON) - if (hsotg->params.g_extcon_always_on) { - struct extcon_dev *edev; - static const unsigned int supported_cable[] = { - EXTCON_USB, - EXTCON_NONE, - }; - - edev = devm_extcon_dev_allocate(dev, supported_cable); - if (IS_ERR(edev)) - return PTR_ERR(edev); - - ret = devm_extcon_dev_register(dev, edev); - if (ret) - return ret; - - extcon_set_state_sync(edev, EXTCON_USB, true); - } -#endif return 0; } diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c index 5e0f85c..cee044c 100644 --- a/drivers/usb/dwc2/params.c +++ b/drivers/usb/dwc2/params.c @@ -546,11 +546,6 @@ static void dwc2_get_device_properties(struct dwc2_hsotg *hsotg) &p->g_np_tx_fifo_size); num = device_property_count_u32(hsotg->dev, "g-tx-fifo-size"); -#if IS_ENABLED(CONFIG_EXTCON) - if (of_find_property(hsotg->dev->of_node, - "g-extcon-always-on", NULL)) - p->g_extcon_always_on = 1; -#endif if (num > 0) { num = min(num, 15); memset(p->g_tx_fifo_size, 0, -- 2.7.4 From 3ae2e3717764a87f61f35414c4903feb55814742 Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Tue, 8 Oct 2024 13:05:14 +0200 Subject: [PATCH 13/16] script: build: enable building extcon-usb-fixed module Signed-off-by: Marek Szyprowski Change-Id: Icad14d891cd7cfb9e3a3a450ca255d8da344e63f --- build-rpi4.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/build-rpi4.sh b/build-rpi4.sh index 0b134ab..7c6855e 100755 --- a/build-rpi4.sh +++ b/build-rpi4.sh @@ -114,6 +114,7 @@ function mk_tizen_modules() export BUILD_dm_bow=m export BUILD_inform_reboot=m export BUILD_kdbus=m + export BUILD_extcon_usb_fixed=m export BUILD_logger=m export BUILD_proc_tsm=m export BUILD_zlogger=m -- 2.7.4 From 01fd90665da45d9267de2e2a5606b76e04687408 Mon Sep 17 00:00:00 2001 From: Sung-hun Kim Date: Wed, 6 Nov 2024 19:10:42 +0900 Subject: [PATCH 14/16] script: Make linux-tizen-modules-source git repo up-to-date on the same branch If the version of linux-tizen-modules-source is different from the kernel, the created boot image may not boot the target exactly. This patch executes `git pull` on the linux-tizen-modules-source repo after making the branch of linux-tizen-modules-source synced with the kernel. If the user don't want it, just passes "dontpull" as the last argument of the build script. It will not execute `git pull`. Change-Id: I553738259e23d1bac1009f0c948beaefb08ed27a Signed-off-by: Sung-hun Kim --- build-rpi4.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/build-rpi4.sh b/build-rpi4.sh index 7c6855e..cb6865f 100755 --- a/build-rpi4.sh +++ b/build-rpi4.sh @@ -14,11 +14,14 @@ BUILD_ROOT=$PWD KERNEL_PATH=`basename ${BUILD_ROOT}` if [ $# == 0 ]; then - echo "Usage : $0 [rt] [bootimg]" + echo "Usage : $0 [rt] [bootimg] [dontpull]" echo " architecture : arm or arm64" + echo " dontpull : do not execute \"git pull\" on linux-tizen-modules-source" echo " e.g) $0 arm" + echo " e.g) $0 arm dontpull" echo " e.g) $0 arm64 rt" echo " e.g) $0 arm64 bootimg" + echo " e.g) $0 arm64 bootimg dontpull" echo " e.g) $0 arm rt bootimg" exit fi @@ -102,8 +105,18 @@ function mk_bootimg() function mk_tizen_modules() { if [ -e ${BUILD_ROOT}/../linux-tizen-modules-source ]; then + if [ $MODULE_PULL = "1" ]; then + BRANCH=`git rev-parse --abbrev-ref HEAD` + echo "Current branch is "$BRANCH + fi + pushd ${BUILD_ROOT}/../linux-tizen-modules-source + if [ $MODULE_PULL = "1" ]; then + git checkout $BRANCH + git pull + fi + ln -s ${PWD}/include kernel export LOGGER_MAIN_BUFFER_SIZE=256 @@ -218,6 +231,12 @@ if [ "$2" = "bootimg" ] || [ "$3" = "bootimg" ]; then IS_BOOTIMG=1 fi +MODULE_PULL=1 +if [ "$2" = "dontpull" ] || [ "$3" = "dontpull" ] || [ "$4" = "dontpull" ]; then + echo "Modules don't be pulled from git repo" + MODULE_PULL=0 +fi + if [ "$IS_RT" = "1" ]; then echo "Build RT-Kernel" BUILD_VERSION=`cat .kernel_buildenv` -- 2.7.4 From 5f0dc1e40f9c9ce4d8f0327a7192679958c7ca40 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Wed, 13 Nov 2024 12:55:35 +0900 Subject: [PATCH 15/16] rpi4: boot: Set uart gpio pins only from rpi4 The RPI5 has its own uart port, so need to set gpio pins for another uart port. Set uart gpio pins only from rpi4. Change-Id: Id058c84eadb92628435795902975bdd316598472 Signed-off-by: Seung-Woo Kim --- rpi4/boot/config_64bit.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rpi4/boot/config_64bit.txt b/rpi4/boot/config_64bit.txt index 93b9593..e71e28f 100644 --- a/rpi4/boot/config_64bit.txt +++ b/rpi4/boot/config_64bit.txt @@ -63,6 +63,9 @@ max_framebuffers=2 # Disable ID_SC and ID_SD pins to use UART2 force_eeprom_read=0 +# Set gpio pins to Input, Pullup mode. +gpio=6,12,13,16,25=ip,pu + [pi5] # Enable DRM VC4 V3D driver dtoverlay=vc4-kms-v3d-pi5 @@ -90,6 +93,3 @@ disable_camera_led=1 # Defines the HDMI output group DMT, set defualt mode 720p hdmi_group=2 hdmi_mode=85 - -# Set gpio pins to Input, Pullup mode. -gpio=6,12,13,16,25=ip,pu -- 2.7.4 From 3e2e6c7eac44e9febc053c9432583b5e811d8e65 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Wed, 13 Nov 2024 13:00:31 +0900 Subject: [PATCH 16/16] ARM64: configs: tizen: Enable hailo ai kit module To support RPI5 Hailo AI-Kit pcie hat, enable CONFIG_MEDIA_PCI_SUPPORT and CONFIG_MEDIA_PCI_HAILO as like bcm2711_defconfig. Change-Id: I3f21d2a0b9b623e0c568833dd78dbc247d24d949 Ref: https://www.raspberrypi.com/products/ai-kit/ Signed-off-by: Seung-Woo Kim --- arch/arm64/configs/tizen_bcm2711_defconfig | 2 ++ arch/arm64/configs/tizen_bcm2711_rt_defconfig | 2 ++ 2 files changed, 4 insertions(+) diff --git a/arch/arm64/configs/tizen_bcm2711_defconfig b/arch/arm64/configs/tizen_bcm2711_defconfig index 626ac10..c2e9f4fc 100644 --- a/arch/arm64/configs/tizen_bcm2711_defconfig +++ b/arch/arm64/configs/tizen_bcm2711_defconfig @@ -328,6 +328,8 @@ CONFIG_MEDIA_USB_SUPPORT=y CONFIG_USB_GSPCA=m CONFIG_USB_GSPCA_ZC3XX=m CONFIG_USB_VIDEO_CLASS=y +CONFIG_MEDIA_PCI_SUPPORT=y +CONFIG_MEDIA_PCI_HAILO=m # CONFIG_RADIO_ADAPTERS is not set CONFIG_V4L_PLATFORM_DRIVERS=y CONFIG_VIDEO_MUX=y diff --git a/arch/arm64/configs/tizen_bcm2711_rt_defconfig b/arch/arm64/configs/tizen_bcm2711_rt_defconfig index afbdf23..0b639a7 100644 --- a/arch/arm64/configs/tizen_bcm2711_rt_defconfig +++ b/arch/arm64/configs/tizen_bcm2711_rt_defconfig @@ -330,6 +330,8 @@ CONFIG_MEDIA_USB_SUPPORT=y CONFIG_USB_GSPCA=m CONFIG_USB_GSPCA_ZC3XX=m CONFIG_USB_VIDEO_CLASS=y +CONFIG_MEDIA_PCI_SUPPORT=y +CONFIG_MEDIA_PCI_HAILO=m # CONFIG_RADIO_ADAPTERS is not set CONFIG_V4L_PLATFORM_DRIVERS=y CONFIG_VIDEO_MUX=y -- 2.7.4