Skip to content

Commit 507bd4c

Browse files
committed
boot: Introduce support for U-Boot support for Airoha EN7581/AN7583
Introduce support for U-Boot for Airoha EN7581/AN7583. For EN7581 initial patch are already in U-Boot mainline and doesn't require backport, for AN7583 some patch are still pending but already posted upstream. Also add for now, precompiled binary for ATF BL2 and BL31. Support for ATF is planned and will come later. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com> (cherry picked from commit 04f6769)
1 parent 44df997 commit 507bd4c

17 files changed

Lines changed: 2101 additions & 0 deletions

package/boot/uboot-airoha/Makefile

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
include $(TOPDIR)/rules.mk
2+
include $(INCLUDE_DIR)/kernel.mk
3+
4+
PKG_VERSION:=2025.07
5+
PKG_HASH:=0f933f6c5a426895bf306e93e6ac53c60870e4b54cda56d95211bec99e63bec7
6+
PKG_BUILD_DEPENDS:=arm-trusted-firmware-tools/host
7+
8+
UBOOT_USE_INTREE_DTC:=1
9+
10+
include $(INCLUDE_DIR)/u-boot.mk
11+
include $(INCLUDE_DIR)/package.mk
12+
include $(INCLUDE_DIR)/host-build.mk
13+
14+
define U-Boot/Default
15+
BUILD_TARGET:=airoha
16+
HIDDEN:=1
17+
FIP_COMPRESS:=1
18+
endef
19+
20+
define U-Boot/an7581_rfb
21+
NAME:=AN7581 Reference Board
22+
UBOOT_CONFIG:=an7581_evb
23+
BUILD_DEVICES:=airoha_an7581-evb
24+
BUILD_SUBTARGET:=an7581
25+
UBOOT_IMAGE:=u-boot.fip
26+
BL2_IMAGE:=an7581-bl2.bin
27+
BL31_IMAGE:=an7581-bl31.bin
28+
endef
29+
30+
define U-Boot/an7583_rfb
31+
NAME:=AN7583 Reference Board
32+
UBOOT_CONFIG:=an7583_evb
33+
BUILD_DEVICES:=airoha_an7583-evb
34+
BUILD_SUBTARGET:=an7583
35+
UBOOT_IMAGE:=u-boot.fip
36+
BL2_IMAGE:=an7583-bl2.bin
37+
BL31_IMAGE:=an7583-bl31.bin
38+
endef
39+
40+
UBOOT_TARGETS := \
41+
an7581_rfb \
42+
an7583_rfb
43+
44+
UBOOT_CUSTOMIZE_CONFIG := \
45+
--disable TOOLS_KWBIMAGE \
46+
--disable TOOLS_LIBCRYPTO \
47+
--disable TOOLS_MKEFICAPSULE \
48+
--enable SERIAL_RX_BUFFER \
49+
--set-val SERIAL_RX_BUFFER_SIZE 256
50+
51+
define Build/fip-image-bl2
52+
$(STAGING_DIR_HOST)/bin/fiptool create \
53+
--tb-fw files/$(BL2_IMAGE) \
54+
$(PKG_BUILD_DIR)/bl2.fip
55+
endef
56+
57+
define Build/fip-image
58+
$(if $(FIP_COMPRESS), $(STAGING_DIR_HOST)/bin/lzma e \
59+
$(PKG_BUILD_DIR)/u-boot.bin \
60+
$(PKG_BUILD_DIR)/u-boot.bin.lzma)
61+
$(if $(FIP_COMPRESS), $(STAGING_DIR_HOST)/bin/lzma e \
62+
files/$(BL31_IMAGE) \
63+
$(PKG_BUILD_DIR)/bl31.bin.lzma)
64+
$(STAGING_DIR_HOST)/bin/fiptool create \
65+
--soc-fw $(PKG_BUILD_DIR)/bl31.bin$(if $(FIP_COMPRESS),.lzma) \
66+
--nt-fw $(PKG_BUILD_DIR)/u-boot.bin$(if $(FIP_COMPRESS),.lzma) \
67+
$(PKG_BUILD_DIR)/u-boot.fip
68+
endef
69+
70+
define Build/Configure
71+
$(call Build/Configure/U-Boot)
72+
sed -i 's/CONFIG_TOOLS_LIBCRYPTO=y/# CONFIG_TOOLS_LIBCRYPTO is not set/' $(PKG_BUILD_DIR)/.config
73+
endef
74+
75+
define Build/Compile
76+
$(call Build/Compile/U-Boot)
77+
ifeq ($(UBOOT_IMAGE),u-boot.fip)
78+
$(call Build/fip-image-bl2)
79+
$(call Build/fip-image)
80+
endif
81+
endef
82+
83+
# don't stage files to bindir, let target/linux/airoha/image/*.mk do that
84+
define Package/u-boot/install
85+
endef
86+
87+
define Build/InstallDev
88+
$(INSTALL_DIR) $(STAGING_DIR_IMAGE)
89+
ifeq ($(UBOOT_IMAGE),u-boot.fip)
90+
$(INSTALL_DATA) $(PKG_BUILD_DIR)/bl2.fip $(STAGING_DIR_IMAGE)/$(BUILD_VARIANT)-bl2.fip
91+
$(INSTALL_DATA) $(PKG_BUILD_DIR)/u-boot.fip $(STAGING_DIR_IMAGE)/$(BUILD_VARIANT)-bl31-u-boot.fip
92+
endif
93+
endef
94+
95+
$(eval $(call BuildPackage/U-Boot))
111 KB
Binary file not shown.
106 KB
Binary file not shown.
117 KB
Binary file not shown.
130 KB
Binary file not shown.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
From 4f1fcf5281ee4e22b1e89a62bd0417878bcbeca5 Mon Sep 17 00:00:00 2001
2+
From: Christian Marangi <ansuelsmth@gmail.com>
3+
Date: Tue, 3 Jun 2025 10:41:18 +0200
4+
Subject: [PATCH 1/2] linux/bitfield.h: import FIELD_PREP_CONST macro from
5+
Linux Kernel
6+
7+
Import FIELD_PREP_CONST macro from Linux Kernel to permit usage of
8+
FIELD_PREP with scenario where a constant value is needed.
9+
10+
Refer to commit e2192de59e45 ("bitfield: add FIELD_PREP_CONST()") in
11+
Linux kernel for extensive explaination of why this is useful.
12+
13+
This is also to better align with the Linux Kernel for easier porting of
14+
driver.
15+
16+
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
17+
---
18+
include/linux/bitfield.h | 26 ++++++++++++++++++++++++++
19+
1 file changed, 26 insertions(+)
20+
21+
--- a/include/linux/bitfield.h
22+
+++ b/include/linux/bitfield.h
23+
@@ -90,6 +90,32 @@
24+
((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask); \
25+
})
26+
27+
+#define __BF_CHECK_POW2(n) BUILD_BUG_ON_ZERO(((n) & ((n) - 1)) != 0)
28+
+
29+
+/**
30+
+ * FIELD_PREP_CONST() - prepare a constant bitfield element
31+
+ * @_mask: shifted mask defining the field's length and position
32+
+ * @_val: value to put in the field
33+
+ *
34+
+ * FIELD_PREP_CONST() masks and shifts up the value. The result should
35+
+ * be combined with other fields of the bitfield using logical OR.
36+
+ *
37+
+ * Unlike FIELD_PREP() this is a constant expression and can therefore
38+
+ * be used in initializers. Error checking is less comfortable for this
39+
+ * version, and non-constant masks cannot be used.
40+
+ */
41+
+#define FIELD_PREP_CONST(_mask, _val) \
42+
+ ( \
43+
+ /* mask must be non-zero */ \
44+
+ BUILD_BUG_ON_ZERO((_mask) == 0) + \
45+
+ /* check if value fits */ \
46+
+ BUILD_BUG_ON_ZERO(~((_mask) >> __bf_shf(_mask)) & (_val)) + \
47+
+ /* check if mask is contiguous */ \
48+
+ __BF_CHECK_POW2((_mask) + (1ULL << __bf_shf(_mask))) + \
49+
+ /* and create the value */ \
50+
+ (((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask)) \
51+
+ )
52+
+
53+
/**
54+
* FIELD_GET() - extract a bitfield element
55+
* @_mask: shifted mask defining the field's length and position
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
From 00e8038b8be74d599f7bc8078731cc2505832f57 Mon Sep 17 00:00:00 2001
2+
From: Christian Marangi <ansuelsmth@gmail.com>
3+
Date: Tue, 3 Jun 2025 10:47:15 +0200
4+
Subject: [PATCH 2/2] mtd: spinand: winbond: add Winbond W25N04KV flash support
5+
6+
Add Winbond W25N04KV flash support that use a different value to detect
7+
ECC bitflip.
8+
9+
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
10+
---
11+
drivers/mtd/nand/spi/winbond.c | 13 +++++++++++++
12+
1 file changed, 13 insertions(+)
13+
14+
--- a/drivers/mtd/nand/spi/winbond.c
15+
+++ b/drivers/mtd/nand/spi/winbond.c
16+
@@ -11,6 +11,7 @@
17+
#include <linux/device.h>
18+
#include <linux/kernel.h>
19+
#endif
20+
+#include <linux/bitfield.h>
21+
#include <linux/bug.h>
22+
#include <linux/mtd/spinand.h>
23+
24+
@@ -18,6 +19,8 @@
25+
26+
#define WINBOND_CFG_BUF_READ BIT(3)
27+
28+
+#define W25N04KV_STATUS_ECC_5_8_BITFLIPS FIELD_PREP_CONST(STATUS_ECC_MASK, 0x3)
29+
+
30+
static SPINAND_OP_VARIANTS(read_cache_variants,
31+
SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
32+
SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
33+
@@ -121,6 +124,7 @@ static int w25n02kv_ecc_get_status(struc
34+
return -EBADMSG;
35+
36+
case STATUS_ECC_HAS_BITFLIPS:
37+
+ case W25N04KV_STATUS_ECC_5_8_BITFLIPS:
38+
/*
39+
* Let's try to retrieve the real maximum number of bitflips
40+
* in order to avoid forcing the wear-leveling layer to move
41+
@@ -169,6 +173,15 @@ static const struct spinand_info winbond
42+
NAND_ECCREQ(8, 512),
43+
SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
44+
&write_cache_variants,
45+
+ &update_cache_variants),
46+
+ 0,
47+
+ SPINAND_ECCINFO(&w25n02kv_ooblayout, w25n02kv_ecc_get_status)),
48+
+ SPINAND_INFO("W25N04KV",
49+
+ SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x23),
50+
+ NAND_MEMORG(1, 2048, 128, 64, 4096, 40, 2, 1, 1),
51+
+ NAND_ECCREQ(8, 512),
52+
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
53+
+ &write_cache_variants,
54+
&update_cache_variants),
55+
0,
56+
SPINAND_ECCINFO(&w25n02kv_ooblayout, w25n02kv_ecc_get_status)),

0 commit comments

Comments
 (0)