Skip to content

Commit 851e7f7

Browse files
thom24hauke
authored andcommitted
stm32: add new stm32 target
New stm32 target introduces support for stm32mp1 based devices. For now it includes an initial support of the STM32MP135F-DK device. The specifications bellow only list supported features. Specifications -------------- SOC: STM32MP135FAF7 RAM: 512 MiB Storage: SD Card Ethernet: 2x 100 Mbps Wireless: 2.4GHz Cypress CYW43455 (802.11b/g/n) LEDs: Heartbeat (Blue) Buttons: 1x Reset, 1x User (USER2) USB: 4x 2.0 Type-A Signed-off-by: Thomas Richard <[email protected]> Link: openwrt/openwrt#16716 Signed-off-by: Hauke Mehrtens <[email protected]>
1 parent e109831 commit 851e7f7

File tree

31 files changed

+4674
-0
lines changed

31 files changed

+4674
-0
lines changed

target/linux/stm32/Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
#
3+
# Copyright (C) 2024 Bootlin
4+
#
5+
6+
include $(TOPDIR)/rules.mk
7+
8+
BOARD:=stm32
9+
BOARDNAME:=STMicroelectronics STM32
10+
FEATURES:=boot-part emmc ext4 gpio rtc usb
11+
SUBTARGETS:=stm32mp1
12+
CPU_TYPE:=
13+
14+
KERNEL_PATCHVER:=6.6
15+
16+
include $(INCLUDE_DIR)/target.mk
17+
18+
DEFAULT_PACKAGES += blockdev kmod-gpio-button-hotplug
19+
20+
define Target/Description
21+
Build firmware image for STM32 devices
22+
endef
23+
24+
$(eval $(call BuildTarget))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
. /lib/functions/uci-defaults.sh
3+
. /lib/functions.sh
4+
. /lib/functions/system.sh
5+
6+
board_config_update
7+
8+
board=$(board_name)
9+
10+
case "$board" in
11+
st,stm32mp135f-dk)
12+
ucidef_set_interfaces_lan_wan "eth0" "eth1"
13+
;;
14+
esac
15+
16+
board_config_flush
17+
18+
exit 0
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
move_config() {
3+
. /lib/upgrade/common.sh
4+
. /lib/upgrade/platform.sh
5+
6+
if export_bootdevice && export_partdevice partdev 4; then
7+
mount -t ext4 -o rw,noatime "/dev/$partdev" /mnt
8+
if [ -f "/mnt/$BACKUP_FILE" ]; then
9+
mv -f "/mnt/$BACKUP_FILE" /
10+
fi
11+
umount /mnt
12+
fi
13+
}
14+
15+
boot_hook_add preinit_mount_root move_config
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
REQUIRE_IMAGE_METADATA=1
2+
3+
UBOOT_ENV_PART=3
4+
BOOT_PART=4
5+
ROOTFS_PART=5
6+
7+
RAMFS_COPY_BIN='blockdev'
8+
9+
export_bootdevice() {
10+
local cmdline uuid blockdev uevent line class
11+
local MAJOR MINOR DEVNAME DEVTYPE
12+
local rootpart="$(cmdline_get_var root)"
13+
14+
case "$rootpart" in
15+
PARTUUID=????????-????-????-????-??????????0?/PARTNROFF=1 | \
16+
PARTUUID=????????-????-????-????-??????????05)
17+
uuid="${rootpart#PARTUUID=}"
18+
uuid="${uuid%/PARTNROFF=1}"
19+
uuid="${uuid%0?}00"
20+
for disk in $(find /dev -type b); do
21+
set -- $(dd if=$disk bs=1 skip=568 count=16 2>/dev/null | hexdump -v -e '8/1 "%02x "" "2/1 "%02x""-"6/1 "%02x"')
22+
if [ "$4$3$2$1-$6$5-$8$7-$9" = "$uuid" ]; then
23+
uevent="/sys/class/block/${disk##*/}/uevent"
24+
break
25+
fi
26+
done
27+
;;
28+
esac
29+
30+
if [ -e "$uevent" ]; then
31+
while read line; do
32+
export -n "$line"
33+
done < "$uevent"
34+
export BOOTDEV_MAJOR=$MAJOR
35+
export BOOTDEV_MINOR=$MINOR
36+
return 0
37+
fi
38+
39+
return 1
40+
}
41+
42+
platform_check_image() {
43+
local diskdev partdev diff
44+
45+
[ "$#" -gt 1 ] && return 1
46+
47+
export_bootdevice && export_partdevice diskdev 0 || {
48+
v "platform_check_image: Unable to determine upgrade device"
49+
return 1
50+
}
51+
52+
get_partitions "/dev/$diskdev" bootdisk
53+
54+
v "Extract the boot sector from the image"
55+
get_image_dd "$1" of=/tmp/image.bs count=63 bs=512b
56+
57+
get_partitions /tmp/image.bs image
58+
59+
#compare tables
60+
diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
61+
62+
rm -f /tmp/image.bs /tmp/partmap.bootdisk /tmp/partmap.image
63+
64+
if [ -n "$diff" ]; then
65+
echo "Partition layout has changed. Full image will be written."
66+
ask_bool 0 "Abort" && exit 1
67+
return 0
68+
fi
69+
}
70+
71+
platform_do_upgrade() {
72+
local diskdev partdev diff partlabel
73+
74+
export_bootdevice && export_partdevice diskdev 0 || {
75+
v "platform_do_upgrade: Unable to determine upgrade device"
76+
return 1
77+
}
78+
79+
sync
80+
81+
if [ "$UPGRADE_OPT_SAVE_PARTITIONS" = "1" ]; then
82+
get_partitions "/dev/$diskdev" bootdisk
83+
84+
v "Extract boot sector from the image"
85+
get_image_dd "$1" of=/tmp/image.bs count=63 bs=512b
86+
87+
get_partitions /tmp/image.bs image
88+
89+
#compare tables
90+
diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
91+
else
92+
diff=1
93+
fi
94+
95+
if [ -n "$diff" ]; then
96+
rm -rf /tmp/ubootenv
97+
98+
if export_partdevice partdev $UBOOT_ENV_PART; then
99+
v "Saving u-boot env (/dev/$partdev) before to write image"
100+
get_image_dd "/dev/$partdev" of=/tmp/ubootenv
101+
fi
102+
103+
v "Writing image to /dev/$diskdev..."
104+
get_image_dd "$1" of="/dev/$diskdev" conv=fsync
105+
106+
blockdev --rereadpt "/dev/$diskdev"
107+
108+
[ -f /tmp/ubootenv ] && {
109+
# iterate over each partition from the image to find the
110+
# u-boot-env partition and restore u-boot env.
111+
while read part start size; do
112+
if export_partdevice partdev $part; then
113+
while read line; do
114+
eval "local l$line"
115+
done < "/sys/class/block/$partdev/uevent"
116+
117+
[ "$lPARTNAME" = "u-boot-env" ] || continue
118+
119+
v "Writting u-boot env to /dev/$partdev"
120+
get_image_dd /tmp/ubootenv of="/dev/$partdev" conv=fsync
121+
122+
return 0
123+
fi
124+
done < /tmp/partmap.image
125+
}
126+
return 0
127+
fi
128+
129+
#iterate over each partition from the image and write it to the boot disk
130+
while read part start size; do
131+
if export_partdevice partdev $part; then
132+
# do not erase u-boot env
133+
[ "$part" = "$UBOOT_ENV_PART" ] && continue
134+
135+
v "Writing image to /dev/$partdev..."
136+
v "Normal partition, doing DD"
137+
get_image_dd "$1" of="/dev/$partdev" ibs=512 obs=1M skip="$start" \
138+
count="$size" conv=fsync
139+
else
140+
v "Unable to find partition $part device, skipped."
141+
fi
142+
done < /tmp/partmap.image
143+
144+
if export_partdevice partdev "$BOOT_PART"; then
145+
mount -t ext4 -o rw,noatime "/dev/$partdev" /mnt
146+
local partuuid="$(cmdline_get_var root)"
147+
v "Setting rootfs ${partuuid}"
148+
sed -i "s/PARTUUID=[a-f0-9-]\+/${partuuid}/ig" \
149+
/mnt/extlinux/extlinux.conf
150+
umount /mnt
151+
fi
152+
}
153+
154+
platform_copy_config() {
155+
local partdev
156+
157+
# Iterate over each partition from the image to find the boot partition
158+
# and copy the config tarball.
159+
# The partlabel is used to find the partition.
160+
# An hardcoded partition number cannot be used, as it could be wrong if
161+
# the partition table changed, and the full image was written.
162+
while read part start size; do
163+
# config is copied in the boot partition, as for squashfs image, the
164+
# rootfs partition is not writable.
165+
if export_partdevice partdev "$part"; then
166+
while read line; do
167+
eval "local l$line"
168+
done < "/sys/class/block/$partdev/uevent"
169+
170+
[ "$lPARTNAME" = "boot" ] || continue
171+
172+
mount -t ext4 -o rw,noatime "/dev/$partdev" /mnt
173+
cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
174+
umount /mnt
175+
return 0
176+
else
177+
v "ERROR: Unable to find partition to copy config data to"
178+
fi
179+
done < /tmp/partmap.image
180+
}
181+

target/linux/stm32/image/Makefile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
#
3+
# Copyright (C) 2024 Bootlin
4+
#
5+
6+
include $(TOPDIR)/rules.mk
7+
include $(INCLUDE_DIR)/image.mk
8+
9+
define Build/boot-img-ext4
10+
rm -fR $@.boot
11+
mkdir -p $@.boot
12+
$(foreach dts,$(DEVICE_DTS), $(CP) $(KDIR)/image-$(dts).dtb $@.boot/$(dts).dtb;)
13+
$(CP) $(IMAGE_KERNEL) $@.boot/$(KERNEL_IMG)
14+
$(INSTALL_DIR) $@.boot/extlinux
15+
$(CP) ./extlinux.conf $@.boot/extlinux/
16+
$(SED) 's/@KERNEL@/$(KERNEL_IMG)/' $@.boot/extlinux/extlinux.conf
17+
$(SED) 's/@DEVICE@/$(DEVICE_NAME)/' $@.boot/extlinux/extlinux.conf
18+
$(SED) 's/@DTS@/$(DEVICE_DTS)/' $@.boot/extlinux/extlinux.conf
19+
$(SED) 's/@ROOT@/PARTUUID=$(shell echo $(IMG_PART_DISKGUID) | sed 's/00$$/05/')/' $@.boot/extlinux/extlinux.conf
20+
21+
make_ext4fs -J -L kernel -l $(CONFIG_TARGET_KERNEL_PARTSIZE)M \
22+
$(if $(SOURCE_DATE_EPOCH),-T $(SOURCE_DATE_EPOCH)) \
23+
$@.bootimg $@.boot
24+
endef
25+
26+
define Build/sdcard-img
27+
GUID=$(IMG_PART_DISKGUID) ./gen_stm32_sdcard_img.sh \
28+
$@ $(STAGING_DIR_IMAGE)/tf-a-$(DEVICE_NAME).stm32 \
29+
$(STAGING_DIR_IMAGE)/fip-$(DEVICE_NAME).bin $@.bootimg $(IMAGE_ROOTFS) \
30+
$(ENV_SIZE) $(CONFIG_TARGET_KERNEL_PARTSIZE) $(CONFIG_TARGET_ROOTFS_PARTSIZE)
31+
endef
32+
33+
define Device/Default
34+
PROFILES := Default
35+
DEVICE_VENDOR := STMicroelectronics
36+
IMAGES := factory.img.gz sysupgrade.img.gz
37+
IMAGE/factory.img.gz := boot-img-ext4 | sdcard-img | gzip
38+
IMAGE/sysupgrade.img.gz := boot-img-ext4 | sdcard-img | gzip | append-metadata
39+
KERNEL := kernel-bin
40+
KERNEL_NAME := zImage
41+
KERNEL_IMG := zImage
42+
DEVICE_DTS_DIR := $(DTS_DIR)/st
43+
ENV_SIZE := 0x200000
44+
DEVICE_PACKAGES := kmod-brcmfmac \
45+
murata-firmware-43430-sdio \
46+
murata-nvram-43430-sdio \
47+
wpad-basic-mbedtls \
48+
kmod-phy-stm32-usbphyc \
49+
kmod-usb2 \
50+
kmod-usb-storage \
51+
kmod-usb-ledtrig-usbport \
52+
-mtd
53+
endef
54+
55+
define Device/stm32mp135f-dk
56+
DEVICE_MODEL := STM32MP135F-DK
57+
DEVICE_DTS := stm32mp135f-dk
58+
SUPPORTED_DEVICES := st,stm32mp135f-dk
59+
endef
60+
61+
TARGET_DEVICES += stm32mp135f-dk
62+
63+
$(eval $(call BuildImage))
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
label @DEVICE@-openwrt
2+
kernel /@KERNEL@
3+
devicetree /@[email protected]
4+
append root=@ROOT@ rootwait
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
# Copyright (C) 2024 Bootlin
3+
4+
set -ex
5+
[ $# -eq 8 ] || {
6+
echo "SYNTAX: $0 <file> <fsbl> <fip> <bootfs image> <rootfs image> <env size> <bootfs size> <rootfs size>"
7+
exit 1
8+
}
9+
10+
OUTPUT="${1}"
11+
FSBL="${2}"
12+
FIP="${3}"
13+
BOOTFS="${4}"
14+
ROOTFS="${5}"
15+
ENVSIZE="$((${6} / 1024))"
16+
BOOTFSSIZE="${7}"
17+
ROOTFSSIZE="${8}"
18+
19+
set $(ptgen -o "${OUTPUT}" -g -a 4 -l 2048 -G ${GUID} -N fsbla -p 2M -N fip -p 3M -N u-boot-env -p "${ENVSIZE}" -N boot -p${BOOTFSSIZE}M -N rootfs -p ${ROOTFSSIZE}M)
20+
FSBLAOFFSET="$((${1} / 512))"
21+
FSBLASIZE="$((${2} / 512))"
22+
FIPOFFSET="$((${3} / 512))"
23+
FIPSIZE="$((${4} / 512))"
24+
ENVOFFSET="$((${5} / 512))"
25+
ENVSIZE="$((${6} / 512))"
26+
BOOTFSOFFSET="$((${7} / 512))"
27+
BOOTFSSIZE="$((${8} / 512))"
28+
ROOTFSOFFSET="$((${9} / 512))"
29+
ROOTFSSIZE="$((${10} / 512))"
30+
31+
dd bs=512 if="${FSBL}" of="${OUTPUT}" seek="${FSBLAOFFSET}" conv=notrunc
32+
dd bs=512 if="${FIP}" of="${OUTPUT}" seek="${FIPOFFSET}" conv=notrunc
33+
dd bs=512 if=/dev/zero of="${OUTPUT}" seek="${ENVOFFSET}" count="${ENVSIZE}" conv=notrunc
34+
dd bs=512 if="${BOOTFS}" of="${OUTPUT}" seek="${BOOTFSOFFSET}" conv=notrunc
35+
dd bs=512 if="${ROOTFS}" of="${OUTPUT}" seek="${ROOTFSOFFSET}" conv=notrunc

0 commit comments

Comments
 (0)