From 27c142c3efbfc494e01c8c92b0d5d2e58879ea3b Mon Sep 17 00:00:00 2001 From: Dmitry Ilyin <6576495+widgetii@users.noreply.github.com> Date: Sun, 3 May 2026 19:44:02 +0300 Subject: [PATCH 1/2] load_hisilicon: derive os_mem_size from kernel cmdline mem= load_hisilicon was deciding where to put the MMZ region by reading osmem from the U-Boot environment. But the kernel's actual memory size is set by the mem= argument on the kernel command line -- osmem is just a hint U-Boot uses when it builds that command line at boot. When those two drift apart (observed on a hi3516av200 with the kernel booted with mem=256M while osmem in the env still said 128M), the script trusted osmem, computed mmz_start = 0x80000000 + 128M = 0x88000000, and asked the MMZ allocator for a 384MB region starting there. The kernel had already claimed everything up to 0x8FFFFFFF, so the request overlapped kernel memory by 128MB and got rejected -- silent on older opensdk builds, hard insmod failure on opensdk e866011 and later (openhisilicon PR openipc/openhisilicon#73). Read mem= directly from /proc/cmdline -- that's what the running kernel actually claimed, it can't lie -- and use it as os_mem_size. Fall back to the env value when the kernel was booted without an explicit mem=, so boot paths that never set it keep working. Same patch applied to all eight load_hisilicon scripts since they share the formula. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../files/script/load_hisilicon | 7 ++++++- .../files/script/load_hisilicon | 7 ++++++- .../files/script/load_hisilicon | 7 ++++++- .../files/script/load_hisilicon | 7 ++++++- .../files/script/load_hisilicon | 7 ++++++- .../files/script/load_hisilicon | 7 ++++++- .../hisilicon-osdrv-hi3519v101/files/script/load_hisilicon | 7 ++++++- .../files/script/load_hisilicon | 7 ++++++- 8 files changed, 48 insertions(+), 8 deletions(-) diff --git a/general/package/hisilicon-osdrv-hi3516av100/files/script/load_hisilicon b/general/package/hisilicon-osdrv-hi3516av100/files/script/load_hisilicon index e4934ca465..f1776deb3b 100755 --- a/general/package/hisilicon-osdrv-hi3516av100/files/script/load_hisilicon +++ b/general/package/hisilicon-osdrv-hi3516av100/files/script/load_hisilicon @@ -12,7 +12,12 @@ mem_start=0x80000000 # phy mem start mem_total=$(fw_printenv -n totalmem | tr -d 'M') mem_total=${mem_total:=128} -os_mem_size=$(fw_printenv -n osmem | tr -d 'M') +# Prefer kernel cmdline mem=NM -- that's the authoritative kernel/MMZ split. +# Fall back to U-Boot osmem env only when the kernel was booted without mem=. +os_mem_size=$(awk 'BEGIN{RS=" "} /^mem=[0-9]+M/{gsub(/^mem=|M.*$/,""); print; exit}' /proc/cmdline) +if [ -z "$os_mem_size" ]; then + os_mem_size=$(fw_printenv -n osmem | tr -d 'M') +fi os_mem_size=${os_mem_size:=32} report_error() { diff --git a/general/package/hisilicon-osdrv-hi3516cv100/files/script/load_hisilicon b/general/package/hisilicon-osdrv-hi3516cv100/files/script/load_hisilicon index 2a4965a1c2..e97c37ed00 100755 --- a/general/package/hisilicon-osdrv-hi3516cv100/files/script/load_hisilicon +++ b/general/package/hisilicon-osdrv-hi3516cv100/files/script/load_hisilicon @@ -9,7 +9,12 @@ mem_start=0x80000000 # phy mem start mem_total=$(fw_printenv -n totalmem | tr -d 'M') mem_total=${mem_total:=64} -os_mem_size=$(fw_printenv -n osmem | tr -d 'M') +# Prefer kernel cmdline mem=NM -- that's the authoritative kernel/MMZ split. +# Fall back to U-Boot osmem env only when the kernel was booted without mem=. +os_mem_size=$(awk 'BEGIN{RS=" "} /^mem=[0-9]+M/{gsub(/^mem=|M.*$/,""); print; exit}' /proc/cmdline) +if [ -z "$os_mem_size" ]; then + os_mem_size=$(fw_printenv -n osmem | tr -d 'M') +fi os_mem_size=${os_mem_size:=32} # Sensor config diff --git a/general/package/hisilicon-osdrv-hi3516cv200/files/script/load_hisilicon b/general/package/hisilicon-osdrv-hi3516cv200/files/script/load_hisilicon index 533d0a631d..b29427adff 100755 --- a/general/package/hisilicon-osdrv-hi3516cv200/files/script/load_hisilicon +++ b/general/package/hisilicon-osdrv-hi3516cv200/files/script/load_hisilicon @@ -13,7 +13,12 @@ mem_start=0x80000000 # phy mem start mem_total=$(fw_printenv -n totalmem | tr -d 'M') mem_total=${mem_total:=64} -os_mem_size=$(fw_printenv -n osmem | tr -d 'M') +# Prefer kernel cmdline mem=NM -- that's the authoritative kernel/MMZ split. +# Fall back to U-Boot osmem env only when the kernel was booted without mem=. +os_mem_size=$(awk 'BEGIN{RS=" "} /^mem=[0-9]+M/{gsub(/^mem=|M.*$/,""); print; exit}' /proc/cmdline) +if [ -z "$os_mem_size" ]; then + os_mem_size=$(fw_printenv -n osmem | tr -d 'M') +fi os_mem_size=${os_mem_size:=32} report_error() { diff --git a/general/package/hisilicon-osdrv-hi3516cv300/files/script/load_hisilicon b/general/package/hisilicon-osdrv-hi3516cv300/files/script/load_hisilicon index 834f4b26b1..91fe59768b 100755 --- a/general/package/hisilicon-osdrv-hi3516cv300/files/script/load_hisilicon +++ b/general/package/hisilicon-osdrv-hi3516cv300/files/script/load_hisilicon @@ -13,7 +13,12 @@ mem_start=0x80000000; # phy mem start mem_total=$(fw_printenv -n totalmem | tr -d 'M') mem_total=${mem_total:=64} -os_mem_size=$(fw_printenv -n osmem | tr -d 'M') +# Prefer kernel cmdline mem=NM -- that's the authoritative kernel/MMZ split. +# Fall back to U-Boot osmem env only when the kernel was booted without mem=. +os_mem_size=$(awk 'BEGIN{RS=" "} /^mem=[0-9]+M/{gsub(/^mem=|M.*$/,""); print; exit}' /proc/cmdline) +if [ -z "$os_mem_size" ]; then + os_mem_size=$(fw_printenv -n osmem | tr -d 'M') +fi os_mem_size=${os_mem_size:=32} # Sensor config diff --git a/general/package/hisilicon-osdrv-hi3516cv500/files/script/load_hisilicon b/general/package/hisilicon-osdrv-hi3516cv500/files/script/load_hisilicon index 782f9c0e67..173af22f40 100755 --- a/general/package/hisilicon-osdrv-hi3516cv500/files/script/load_hisilicon +++ b/general/package/hisilicon-osdrv-hi3516cv500/files/script/load_hisilicon @@ -15,7 +15,12 @@ mem_start=0x80000000 # phy mem start mem_total=$(fw_printenv -n totalmem | tr -d 'M') mem_total=${mem_total:=64} -os_mem_size=$(fw_printenv -n osmem | tr -d 'M') +# Prefer kernel cmdline mem=NM -- that's the authoritative kernel/MMZ split. +# Fall back to U-Boot osmem env only when the kernel was booted without mem=. +os_mem_size=$(awk 'BEGIN{RS=" "} /^mem=[0-9]+M/{gsub(/^mem=|M.*$/,""); print; exit}' /proc/cmdline) +if [ -z "$os_mem_size" ]; then + os_mem_size=$(fw_printenv -n osmem | tr -d 'M') +fi os_mem_size=${os_mem_size:=32} SNS_TYPE0=imx327 # sensor type diff --git a/general/package/hisilicon-osdrv-hi3516ev200/files/script/load_hisilicon b/general/package/hisilicon-osdrv-hi3516ev200/files/script/load_hisilicon index 1fcb130328..d3628a2be3 100755 --- a/general/package/hisilicon-osdrv-hi3516ev200/files/script/load_hisilicon +++ b/general/package/hisilicon-osdrv-hi3516ev200/files/script/load_hisilicon @@ -15,7 +15,12 @@ mem_start=0x40000000 # phy mem start mem_total=$(fw_printenv -n totalmem | tr -d 'M') mem_total=${mem_total:=64} -os_mem_size=$(fw_printenv -n osmem | tr -d 'M') +# Prefer kernel cmdline mem=NM -- that's the authoritative kernel/MMZ split. +# Fall back to U-Boot osmem env only when the kernel was booted without mem=. +os_mem_size=$(awk 'BEGIN{RS=" "} /^mem=[0-9]+M/{gsub(/^mem=|M.*$/,""); print; exit}' /proc/cmdline) +if [ -z "$os_mem_size" ]; then + os_mem_size=$(fw_printenv -n osmem | tr -d 'M') +fi os_mem_size=${os_mem_size:=32} YUV_TYPE0=0 # 0 -- raw, 1 --DC, 2 --bt1120, 3 --bt656 diff --git a/general/package/hisilicon-osdrv-hi3519v101/files/script/load_hisilicon b/general/package/hisilicon-osdrv-hi3519v101/files/script/load_hisilicon index a5221ddd6d..d25aabf130 100755 --- a/general/package/hisilicon-osdrv-hi3519v101/files/script/load_hisilicon +++ b/general/package/hisilicon-osdrv-hi3519v101/files/script/load_hisilicon @@ -12,7 +12,12 @@ mem_start=0x80000000 # phy mem start mem_total=$(fw_printenv -n totalmem | tr -d 'M') mem_total=${mem_total:=64} -os_mem_size=$(fw_printenv -n osmem | tr -d 'M') +# Prefer kernel cmdline mem=NM -- that's the authoritative kernel/MMZ split. +# Fall back to U-Boot osmem env only when the kernel was booted without mem=. +os_mem_size=$(awk 'BEGIN{RS=" "} /^mem=[0-9]+M/{gsub(/^mem=|M.*$/,""); print; exit}' /proc/cmdline) +if [ -z "$os_mem_size" ]; then + os_mem_size=$(fw_printenv -n osmem | tr -d 'M') +fi os_mem_size=${os_mem_size:=32} # Sensor config diff --git a/general/package/hisilicon-osdrv-hi3536dv100/files/script/load_hisilicon b/general/package/hisilicon-osdrv-hi3536dv100/files/script/load_hisilicon index bc29d537c4..55ff864c41 100755 --- a/general/package/hisilicon-osdrv-hi3536dv100/files/script/load_hisilicon +++ b/general/package/hisilicon-osdrv-hi3536dv100/files/script/load_hisilicon @@ -8,7 +8,12 @@ mem_start=0x80000000 mem_total=$(fw_printenv -n totalmem | tr -d 'M') mem_total=${mem_total:=64} -os_mem_size=$(fw_printenv -n osmem | tr -d 'M') +# Prefer kernel cmdline mem=NM -- that's the authoritative kernel/MMZ split. +# Fall back to U-Boot osmem env only when the kernel was booted without mem=. +os_mem_size=$(awk 'BEGIN{RS=" "} /^mem=[0-9]+M/{gsub(/^mem=|M.*$/,""); print; exit}' /proc/cmdline) +if [ -z "$os_mem_size" ]; then + os_mem_size=$(fw_printenv -n osmem | tr -d 'M') +fi os_mem_size=${os_mem_size:=32} mmz_start=0 From 534a5db53c836f15551e075a228a3c33ad0001fc Mon Sep 17 00:00:00 2001 From: Dmitry Ilyin <6576495+widgetii@users.noreply.github.com> Date: Sun, 3 May 2026 19:44:09 +0300 Subject: [PATCH 2/2] hisilicon-opensdk: bump to e866011 (mmz: fail-fast on zone conflict) Picks up openipc/openhisilicon#73: mmz: fail allocator init when every configured zone is rejected. Pairs with the previous commit -- without the bump, a corrected osmem from /proc/cmdline still leaves users on older opensdk builds silently passing a bad mmz= range without noticing; with the bump, that case becomes a loud insmod failure. Co-Authored-By: Claude Opus 4.7 (1M context) --- general/package/hisilicon-opensdk/hisilicon-opensdk.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/general/package/hisilicon-opensdk/hisilicon-opensdk.mk b/general/package/hisilicon-opensdk/hisilicon-opensdk.mk index 99bf909bd0..b90fa4e007 100644 --- a/general/package/hisilicon-opensdk/hisilicon-opensdk.mk +++ b/general/package/hisilicon-opensdk/hisilicon-opensdk.mk @@ -5,7 +5,7 @@ ################################################################################ HISILICON_OPENSDK_SITE = $(call github,openipc,openhisilicon,$(HISILICON_OPENSDK_VERSION)) -HISILICON_OPENSDK_VERSION = b73fc65 +HISILICON_OPENSDK_VERSION = e866011 HISILICON_OPENSDK_LICENSE = GPL-3.0 HISILICON_OPENSDK_LICENSE_FILES = LICENSE