From 4a8bbd88e830d87911ab5c927e26def6eff575c0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Th=C3=A9o=20Friberg?= <fsmnarmosta@posteo.net>
Date: Wed, 26 Feb 2020 20:14:40 +0200
Subject: [PATCH] samsung-nevisp: support wifi

---
 device/device-samsung-nevisp/APKBUILD         | 18 +++++++++++----
 .../device-samsung-nevisp/modules-load.conf   |  5 ++++
 device/linux-samsung-nevisp/APKBUILD          | 19 +++++++++++++--
 .../config-samsung-nevisp.armv7               |  4 ++--
 firmware/firmware-samsung-nevisp/APKBUILD     | 23 +++++++++++++++++++
 5 files changed, 61 insertions(+), 8 deletions(-)
 create mode 100644 device/device-samsung-nevisp/modules-load.conf
 create mode 100644 firmware/firmware-samsung-nevisp/APKBUILD

diff --git a/device/device-samsung-nevisp/APKBUILD b/device/device-samsung-nevisp/APKBUILD
index 64c4b93e881..b16342fc98b 100644
--- a/device/device-samsung-nevisp/APKBUILD
+++ b/device/device-samsung-nevisp/APKBUILD
@@ -3,15 +3,17 @@
 # Reference: <https://postmarketos.org/devicepkg>
 pkgname="device-samsung-nevisp"
 pkgdesc="Samsung Galaxy Fame GT-S6810P"
-pkgver=0.1
-pkgrel=0
+pkgver=0.2
+pkgrel=5
 url="https://postmarketos.org"
 license="MIT"
 arch="armv7"
 options="!check !archcheck"
 depends="postmarketos-base linux-samsung-nevisp mkbootimg mesa-dri-swrast msm-fb-refresher"
 makedepends="devicepkg-dev"
-source="deviceinfo"
+subpackages="$pkgname-nonfree-firmware:nonfree_firmware"
+source="deviceinfo
+	modules-load.conf"
 
 build() {
 	devicepkg_build $startdir $pkgname
@@ -19,7 +21,15 @@ build() {
 
 package() {
 	devicepkg_package $startdir $pkgname
+	install -Dm644 "$srcdir"/modules-load.conf \
+		"$pkgdir"/etc/modules-load.d/00-$pkgname.conf
 }
 
+nonfree_firmware() {
+	pkgdesc="Firmware for wifi."
+	depends="firmware-samsung-nevisp"
+	mkdir "$subpkgdir"
+}
 
-sha512sums="233d1fca39301b3ba995b6ae9a52aa19d7124efd2f452009f828d1fe0ae88fcde98a46257990adf75281d8cf99b3bf1d24c30ff949393e54f4f0e6a55a35734e  deviceinfo"
+sha512sums="233d1fca39301b3ba995b6ae9a52aa19d7124efd2f452009f828d1fe0ae88fcde98a46257990adf75281d8cf99b3bf1d24c30ff949393e54f4f0e6a55a35734e  deviceinfo
+0aa06f2147be0ce89fb1ae418abff809ffa8de677afce4e3b29926ccea66f776065d2bb95675a8692230e40e57ec2ce657d9b3f79be56f1db35f4a724a3484f9  modules-load.conf"
diff --git a/device/device-samsung-nevisp/modules-load.conf b/device/device-samsung-nevisp/modules-load.conf
new file mode 100644
index 00000000000..64fb03c1365
--- /dev/null
+++ b/device/device-samsung-nevisp/modules-load.conf
@@ -0,0 +1,5 @@
+# This file contains the names of kernel modules that should be loaded
+# at boot time, one per line. Lines beginning with "#" are ignored.
+# wifi module
+
+dhd
diff --git a/device/linux-samsung-nevisp/APKBUILD b/device/linux-samsung-nevisp/APKBUILD
index 924cc6e81a4..6cb1894ce41 100644
--- a/device/linux-samsung-nevisp/APKBUILD
+++ b/device/linux-samsung-nevisp/APKBUILD
@@ -5,7 +5,7 @@
 
 pkgname="linux-samsung-nevisp"
 pkgver=3.0.101
-pkgrel=0
+pkgrel=3
 pkgdesc="Samsung Galaxy Fame GT-S6810P kernel fork"
 arch="armv7"
 _carch="arm"
@@ -15,6 +15,7 @@ license="GPL-2.0-only"
 options="!strip !check !tracedeps"
 makedepends="perl sed installkernel bash gmp-dev bc linux-headers elfutils-dev devicepkg-dev gcc4 xz"
 
+# I have not managed to build the kernel with any gcc > 4
 
 if [ "${CC:0:5}" != "gcc4-" ]; then
 	CC="gcc4-$CC"
@@ -45,6 +46,12 @@ build() {
 	unset LDFLAGS
 	make ARCH="$_carch" CC="${CC:-gcc}" \
 		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"
+
+	# the 'no-pic' flag is necessary to avoid the
+	# error 'Unknown symbol _GLOBAL_OFFSET_TABLE_ (err 0)' when loading the module
+	make ARCH="$_carch" CC="${CC:-gcc}" CFLAGS_MODULE="-fno-pic" \
+		KBUILD_BUILD_VERSION="$((pkgrel + 1))-postmarketOS" modules
+
 }
 
 package() {
@@ -65,10 +72,18 @@ package() {
 		error "Could not find zImage in $PWD!"
 		return 1
 	fi
+
+	# Modules
+	cd "$builddir"
+	unset LDFLAGS
+	make ARCH="$_carch" CC="${CC:-gcc}" \
+		KBUILD_BUILD_VERSION="$((pkgrel + 1))-postmarketOS" \
+		INSTALL_MOD_PATH="$pkgdir" INSTALL_MOD_STRIP=1 \
+		modules_install
 }
 
 sha512sums="1c62313451ff2a04ab9259a4b2c954388a360f45f20af90d05e9cfe73d31f49fc4847f24c1742c89a45f1646e1d27999fc6f5bd224baba7046b07ab324e7baae  linux-samsung-nevisp-8224116dca7de79d181c0761468f569e6ac3505e.tar.gz
-18056bc314704d2a6f9f2c14cddd970663297c49296909ebe4d42ec5b4b55d107a86ef1b6b8df82c46f6ac1cd4b09e8aca1383d54a005bc380fa4134c87b4372  config-samsung-nevisp.armv7
+a6c7bff882eb299c11f8fc8e1d3e70119e78493c5ecec7c8607b44bf5930bfe7bf11033005cd1912264d30fba8fda8b39737f5b37a91778110e3a4ff038e421d  config-samsung-nevisp.armv7
 d8cdc1137e6a4ad78a3a31acc40f0c98f4db272eaf5b90ee850abb83b80916c4ff3c18a0a181e94eebead44213f6314e3363d0c4b91d95ee1adafbcad6dc57ab  android_paranoid_network.patch
 77eba606a71eafb36c32e9c5fe5e77f5e4746caac292440d9fb720763d766074a964db1c12bc76fe583c5d1a5c864219c59941f5e53adad182dbc70bf2bc14a7  gcc7-give-up-on-ilog2-const-optimizations.patch
 197d40a214ada87fcb2dfc0ae4911704b9a93354b75179cd6b4aadbb627a37ec262cf516921c84a8b1806809b70a7b440cdc8310a4a55fca5d2c0baa988e3967  gcc8-fix-put-user.patch"
diff --git a/device/linux-samsung-nevisp/config-samsung-nevisp.armv7 b/device/linux-samsung-nevisp/config-samsung-nevisp.armv7
index 605efc769cb..fe3b383b07b 100644
--- a/device/linux-samsung-nevisp/config-samsung-nevisp.armv7
+++ b/device/linux-samsung-nevisp/config-samsung-nevisp.armv7
@@ -1380,8 +1380,8 @@ CONFIG_BROADCOM_WIFI_RESERVED_MEM=y
 # CONFIG_B43 is not set
 # CONFIG_B43LEGACY is not set
 # CONFIG_BCMDHD_4334 is not set
-CONFIG_BCMDHD_FW_PATH="/system/etc/firmware/fw_bcmdhd.bin"
-CONFIG_BCMDHD_NVRAM_PATH="/system/etc/wifi/bcmdhd.cal"
+CONFIG_BCMDHD_FW_PATH="/lib/firmware/postmarketos/fw_bcmdhd.bin"
+CONFIG_BCMDHD_NVRAM_PATH="/lib/firmware/postmarketos/bcmdhd.cal"
 # CONFIG_BCM4330 is not set
 CONFIG_BCM4334=m
 # CONFIG_BCM43241 is not set
diff --git a/firmware/firmware-samsung-nevisp/APKBUILD b/firmware/firmware-samsung-nevisp/APKBUILD
new file mode 100644
index 00000000000..ec270868a77
--- /dev/null
+++ b/firmware/firmware-samsung-nevisp/APKBUILD
@@ -0,0 +1,23 @@
+# Contributor: Théo Friberg <fsmnarmosta@posteo.net>
+# Maintainer: Théo Friberg <fsmnarmosta@posteo.net>§
+pkgname="firmware-samsung-nevisp"
+pkgver=1
+pkgrel=114
+pkgdesc="Non-free firmware for the Samsung Galaxy Fame (wifi)"
+url="https://github.com/wulsic/android_vendor_samsung_nevisp"
+arch="armv7"
+license="other:proprietary"
+
+# Sources
+_commit="fbbefae4c3b06978d0e2948211a8138bb6a6a11c"
+source="$pkgname-$_commit.tar.gz::https://github.com/wulsic/android_vendor_samsung_nevisp/archive/$_commit.tar.gz"
+builddir="$srcdir/android_vendor_samsung_nevisp-$_commit"
+
+package() {
+	install -Dm644 "$builddir"/proprietary/etc/wifi/nvram_net.txt \
+		"$pkgdir"/lib/firmware/postmarketos/bcmdhd.cal
+	install -Dm644 "$builddir"/proprietary/etc/wifi/bcmdhd_sta.bin_b2 \
+		"$pkgdir"/lib/firmware/postmarketos/fw_bcmdhd.bin_b2
+}
+
+sha512sums="9e27f2fe1c897d9fcf8d4736a35bab729079842f7f18e29c0d02fe63e7321400af40541b235b7ae80f9ad551489ba14bbe8fea2539106a6394f612e298876033  firmware-samsung-nevisp-fbbefae4c3b06978d0e2948211a8138bb6a6a11c.tar.gz"
-- 
GitLab