From: Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: [PATCH v1 3/4] ARM: boards: add support for Samsung Galaxy S8 (dreamlte)
Date: Tue, 29 Jul 2025 23:36:58 +0300 [thread overview]
Message-ID: <20250729203659.1858575-4-ivo.ivanov.ivanov1@gmail.com> (raw)
In-Reply-To: <20250729203659.1858575-1-ivo.ivanov.ivanov1@gmail.com>
Phones utilizing an exynos SoC boot android with samsung's proprietary
bootloader, called s-boot (s-lk on newer devices). However, not only is
it closed source, it also enforces some limitations that prevent us from
booting mainline linux cleanly on them, such as an applied overlay device
tree, disabled framebuffer refreshing, misaligned kernel image at boot.
Therefore, having another stage bootloader, loaded as a linux kernel
image by s-boot, is best.
Add support for Samsung Galaxy S8, utilizing the exynos 8895 SoC. Support
is modelled to be as reusable on other devices as possible, requiring
only a minimal set of changes to boot - a barebox device tree, which in
this case is basically imported torvalds tree for dreamlte, that is then
matched from the downstream device tree, provided by s-boot at x0.
For some reason, on certain devices the stack set up by the previous
bootloader is not enough. Since the idea of this board support is to be
as generic as possible, setting a fixed stack top via
ENTRY_FUNCTION_WITHSTACK does not make sense, due to different exynos
devices having different memory layouts - exynos8895's dram starts at
0x80000000, whereas exynos7870's starts at 0x40000000. Instead, set the
SP as early as possible in the entry C function by taking the memory base
from the downstream fdt + (SZ_8M - SZ_64K).
Barebox has to be packaged as an android boot image:
mkbootimg --kernel images/barebox-exynos.img \
--ramdisk ramdisk.bin \
--dt stock.dtb
--cmdline "buildvariant=eng" \
--base 0x10000000 \
--kernel_offset 0x00008000 \
--ramdisk_offset 0x01000000 \
--second_offset 0x00f00000 \
--tags_offset 0x00000100 \
--os_version 9.0.0 \
--os_patch_level 2019-10 \
--pagesize 2048 \
--hash sha1 \
--output boot.img
And then flashed to the boot partition:
heimdall flash --BOOT boot.img
Currently, only a minimal set of features work. An image can be booted by
barebox by configuring barebox to jump to the address where ramdisk gets
loaded by s-boot, and packaging that payload as a ramdisk with mkbootimg.
Signed-off-by: Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
---
arch/arm/Kconfig | 5 ++
arch/arm/boards/Makefile | 1 +
arch/arm/boards/samsung-exynos/Makefile | 4 ++
arch/arm/boards/samsung-exynos/board.c | 63 ++++++++++++++++++
arch/arm/boards/samsung-exynos/lowlevel.c | 78 +++++++++++++++++++++++
arch/arm/dts/Makefile | 1 +
arch/arm/dts/exynos8895-dreamlte.dts | 13 ++++
arch/arm/mach-samsung/Kconfig | 13 ++++
images/Makefile | 1 +
images/Makefile.exynos | 8 +++
10 files changed, 187 insertions(+)
create mode 100644 arch/arm/boards/samsung-exynos/Makefile
create mode 100644 arch/arm/boards/samsung-exynos/board.c
create mode 100644 arch/arm/boards/samsung-exynos/lowlevel.c
create mode 100644 arch/arm/dts/exynos8895-dreamlte.dts
create mode 100644 arch/arm/mach-samsung/Kconfig
create mode 100644 images/Makefile.exynos
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 7a395270..095f189f 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -212,6 +212,10 @@ config ARCH_ROCKCHIP
select HAS_DEBUG_LL
imply GPIO_ROCKCHIP
+config ARCH_SAMSUNG
+ bool "ARM Exynos boards"
+ depends on ARCH_MULTIARCH
+
config ARCH_STM32MP
bool "STMicroelectronics STM32MP"
depends on 32BIT
@@ -268,6 +272,7 @@ source "arch/arm/mach-k3/Kconfig"
source "arch/arm/mach-omap/Kconfig"
source "arch/arm/mach-pxa/Kconfig"
source "arch/arm/mach-rockchip/Kconfig"
+source "arch/arm/mach-samsung/Kconfig"
source "arch/arm/mach-socfpga/Kconfig"
source "arch/arm/mach-sunxi/Kconfig"
source "arch/arm/mach-stm32mp/Kconfig"
diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile
index ac1fa74d..ff2efe04 100644
--- a/arch/arm/boards/Makefile
+++ b/arch/arm/boards/Makefile
@@ -30,6 +30,7 @@ obj-$(CONFIG_MACH_CHUMBY) += chumby_falconwing/
obj-$(CONFIG_MACH_CLEP7212) += clep7212/
obj-$(CONFIG_MACH_DFI_FS700_M60) += dfi-fs700-m60/
obj-$(CONFIG_MACH_DIGI_CCIMX6ULSBCPRO) += digi-ccimx6ulsom/
+obj-$(CONFIG_MACH_EXYNOS) += samsung-exynos/
obj-$(CONFIG_MACH_DUCKBILL) += duckbill/
obj-$(CONFIG_MACH_DSS11) += dss11/
obj-$(CONFIG_MACH_EFIKA_MX_SMARTBOOK) += efika-mx-smartbook/
diff --git a/arch/arm/boards/samsung-exynos/Makefile b/arch/arm/boards/samsung-exynos/Makefile
new file mode 100644
index 00000000..da63d262
--- /dev/null
+++ b/arch/arm/boards/samsung-exynos/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-y += board.o
+lwl-y += lowlevel.o
diff --git a/arch/arm/boards/samsung-exynos/board.c b/arch/arm/boards/samsung-exynos/board.c
new file mode 100644
index 00000000..25e4add6
--- /dev/null
+++ b/arch/arm/boards/samsung-exynos/board.c
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2025 Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
+ */
+#include <common.h>
+#include <init.h>
+#include <of.h>
+#include <deep-probe.h>
+#include <asm/memory.h>
+#include <linux/sizes.h>
+#include <asm/system.h>
+#include <of_address.h>
+
+#define MACHINE "samsung-exynos"
+
+#define HW_SW_TRIG_CONTROL 0x70
+#define TRIG_AUTO_MASK_EN BIT(12)
+#define SW_TRIG_EN BIT(8)
+#define HW_TRIG_EN BIT(0)
+
+static int exynos_postcore_init(void)
+{
+ void __iomem *decon0_base;
+
+ /*
+ * Devices past galaxy S7 keep framebuffer refreshing disabled after
+ * s-boot. Set the required bit so we can have output. This should
+ * ideally be dropped from board files once we have a decon driver.
+ */
+ if (of_machine_is_compatible("samsung,exynos8895"))
+ decon0_base = IOMEM(0x12860000);
+ else
+ return 0;
+
+ writel(TRIG_AUTO_MASK_EN | SW_TRIG_EN | HW_TRIG_EN,
+ decon0_base + HW_SW_TRIG_CONTROL);
+
+ return 0;
+}
+coredevice_initcall(exynos_postcore_init);
+
+static inline int exynos_init(struct device *dev)
+{
+ barebox_set_model("ARM SAMSUNG " MACHINE);
+ barebox_set_hostname(MACHINE);
+
+ return 0;
+}
+
+static const struct of_device_id exynos_of_match[] = {
+ { .compatible = "samsung,dreamlte" },
+ { /* Sentinel */},
+};
+
+MODULE_DEVICE_TABLE(of, exynos_of_match);
+
+static struct driver exynos_board_driver = {
+ .name = "board-exynos",
+ .probe = exynos_init,
+ .of_compatible = exynos_of_match,
+};
+
+postcore_platform_driver(exynos_board_driver);
diff --git a/arch/arm/boards/samsung-exynos/lowlevel.c b/arch/arm/boards/samsung-exynos/lowlevel.c
new file mode 100644
index 00000000..9c4a0297
--- /dev/null
+++ b/arch/arm/boards/samsung-exynos/lowlevel.c
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2025 Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
+ */
+#include <common.h>
+#include <pbl.h>
+#include <linux/sizes.h>
+#include <asm/barebox-arm-head.h>
+#include <asm/barebox-arm.h>
+#include <asm/sections.h>
+#include <asm/cache.h>
+#include <asm/mmu.h>
+
+extern char __dtb_exynos8895_dreamlte_start[];
+
+static bool is_compat(const void *fdt, const char *prefix)
+{
+ int node, len;
+ const char *compat;
+
+ node = fdt_path_offset(fdt, "/");
+ if (node < 0)
+ return false;
+
+ compat = fdt_getprop(fdt, node, "model", &len);
+ if (!compat)
+ return false;
+
+ while (*prefix) {
+ if (*compat++ != *prefix++)
+ return false;
+ }
+ return true;
+}
+
+static noinline void exynos_continue(void *downstream_fdt)
+{
+ void *fdt;
+ unsigned long membase, memsize;
+ char *__dtb_start;
+
+ /* select device tree dynamically */
+ if (is_compat(downstream_fdt, "Samsung DREAMLTE")) {
+ __dtb_start = __dtb_exynos8895_dreamlte_start;
+ } else {
+ /* we didn't match any device */
+ return;
+ }
+ fdt = __dtb_start + get_runtime_offset();
+ fdt_find_mem(fdt, &membase, &memsize);
+
+ barebox_arm_entry(membase, memsize, fdt);
+}
+
+ENTRY_FUNCTION(start_exynos, x0, x1, x2)
+{
+ void *downstream_fdt = (void *)x0;
+ unsigned long mem_base, mem_size;
+
+ if (!downstream_fdt || fdt_check_header(downstream_fdt))
+ return;
+
+ /*
+ * The previous bootloader has a stack set up, but it seems to not be
+ * enough as we can't get past the relocation on some devices. Set up
+ * a stack determined by the memory node from the downstream fdt.
+ */
+ fdt_find_mem(downstream_fdt, &mem_base, &mem_size);
+ asm volatile("mov sp, %0" : : "r"(mem_base + SZ_8M - SZ_64K));
+
+ arm_cpu_lowlevel_init();
+
+ relocate_to_current_adr();
+
+ setup_c();
+
+ exynos_continue(downstream_fdt);
+}
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 6612a514..a53834f7 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -13,6 +13,7 @@ lwl-$(CONFIG_MACH_BEAGLEPLAY) += k3-am625-beagleplay.dtb.o k3-am625-r5-beaglepla
lwl-$(CONFIG_MACH_CLEP7212) += ep7212-clep7212.dtb.o
lwl-$(CONFIG_MACH_CM_FX6) += imx6dl-cm-fx6.dtb.o imx6q-cm-fx6.dtb.o imx6q-utilite.dtb.o
lwl-$(CONFIG_MACH_DFI_FS700_M60) += imx6q-dfi-fs700-m60-6q.dtb.o imx6dl-dfi-fs700-m60-6s.dtb.o
+lwl-$(CONFIG_MACH_EXYNOS) += exynos8895-dreamlte.dtb.o
lwl-$(CONFIG_MACH_DUCKBILL) += imx28-duckbill.dtb.o
lwl-$(CONFIG_MACH_KINDLE_MX50) += imx50-kindle-d01100.dtb.o imx50-kindle-d01200.dtb.o imx50-kindle-ey21.dtb.o
lwl-$(CONFIG_MACH_EFIKA_MX_SMARTBOOK) += imx51-genesi-efika-sb.dtb.o
diff --git a/arch/arm/dts/exynos8895-dreamlte.dts b/arch/arm/dts/exynos8895-dreamlte.dts
new file mode 100644
index 00000000..36b5271e
--- /dev/null
+++ b/arch/arm/dts/exynos8895-dreamlte.dts
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
+/*
+ * Samsung Galaxy S8 (dreamlte/SM-G950F) barebox device tree source
+ *
+ * Copyright (c) 2025, Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
+ */
+
+/dts-v1/;
+#include <arm64/exynos/exynos8895-dreamlte.dts>
+
+/ {
+ barebox,disable-deep-probe;
+};
diff --git a/arch/arm/mach-samsung/Kconfig b/arch/arm/mach-samsung/Kconfig
new file mode 100644
index 00000000..106a48a6
--- /dev/null
+++ b/arch/arm/mach-samsung/Kconfig
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+if ARCH_SAMSUNG
+
+config MACH_EXYNOS
+ bool "Samsung Exynos boards support"
+ depends on 64BIT
+ select CPU_V8
+ select ARM_PSCI_CLIENT
+ select HW_HAS_PCI
+ select OF_OVERLAY
+
+endif
diff --git a/images/Makefile b/images/Makefile
index e20d11e1..4be5c3cd 100644
--- a/images/Makefile
+++ b/images/Makefile
@@ -176,6 +176,7 @@ include $(srctree)/images/Makefile.mvebu
include $(srctree)/images/Makefile.mxs
include $(srctree)/images/Makefile.omap3
include $(srctree)/images/Makefile.rockchip
+include $(srctree)/images/Makefile.exynos
include $(srctree)/images/Makefile.sandbox
include $(srctree)/images/Makefile.socfpga
include $(srctree)/images/Makefile.stm32mp
diff --git a/images/Makefile.exynos b/images/Makefile.exynos
new file mode 100644
index 00000000..3beb9107
--- /dev/null
+++ b/images/Makefile.exynos
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# barebox image generation Makefile for exynos images
+#
+
+pblb-$(CONFIG_MACH_EXYNOS) += start_exynos
+FILE_barebox-exynos.img = start_exynos.pblb
+image-$(CONFIG_MACH_EXYNOS) += barebox-exynos.img
--
2.43.0
next prev parent reply other threads:[~2025-07-29 20:37 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-29 20:36 [PATCH v1 0/4] ARM: boards: add support for Samsung Galaxy S8 and S20 5G Ivaylo Ivanov
2025-07-29 20:36 ` [PATCH v1 1/4] video: simplefb-client: switch to dev_get_resource Ivaylo Ivanov
2025-07-30 8:11 ` Ahmad Fatoum
2025-07-30 11:28 ` Ivaylo Ivanov
2025-07-30 12:31 ` Ahmad Fatoum
2025-07-29 20:36 ` [PATCH v1 2/4] clocksource: arm_architected_timer: support clock-frequency Ivaylo Ivanov
2025-07-30 8:13 ` Ahmad Fatoum
2025-08-05 7:40 ` (subset) " Sascha Hauer
2025-07-29 20:36 ` Ivaylo Ivanov [this message]
2025-07-30 8:31 ` [PATCH v1 3/4] ARM: boards: add support for Samsung Galaxy S8 (dreamlte) Ahmad Fatoum
2025-07-30 9:09 ` Ivaylo Ivanov
2025-07-30 9:33 ` Ahmad Fatoum
2025-07-30 11:12 ` Ivaylo Ivanov
2025-07-29 20:36 ` [PATCH v1 4/4] ARM: boards: add support for Samsung Galaxy S20 5G (x1s) Ivaylo Ivanov
2025-07-30 8:48 ` Ahmad Fatoum
2025-07-30 9:16 ` Ivaylo Ivanov
2025-07-30 9:44 ` Ahmad Fatoum
2025-07-30 11:18 ` Ivaylo Ivanov
2025-07-30 12:50 ` Ahmad Fatoum
2025-07-30 13:12 ` Ivaylo Ivanov
2025-07-30 13:26 ` Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250729203659.1858575-4-ivo.ivanov.ivanov1@gmail.com \
--to=ivo.ivanov.ivanov1@gmail.com \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox