From b11bdc6ffa9e568e478bb097405704867a628bf2 Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Tue, 16 Apr 2019 19:58:06 +0900 Subject: [PATCH 01/16] packaging: include hostapd config file To use hostapd, include hostapd config file under /usr/lib/firmware/brcm. Change-Id: I1a26796c6ff4ab1b1da7014c38c440151027aa31 Signed-off-by: Jaehoon Chung --- data/hostapd.conf | 7 +++++++ packaging/initrd-flash.spec | 2 ++ scripts/41-flash.list | 1 + 3 files changed, 10 insertions(+) create mode 100644 data/hostapd.conf diff --git a/data/hostapd.conf b/data/hostapd.conf new file mode 100644 index 0000000..80cefcd --- /dev/null +++ b/data/hostapd.conf @@ -0,0 +1,7 @@ +interface=wlan0 +driver=nl80211 +ssid=TIZEN_RPI3 +channel=6 +ignore_broadcast_ssid=0 +hw_mode=g +ieee80211n=1 diff --git a/packaging/initrd-flash.spec b/packaging/initrd-flash.spec index 004fd91..d549718 100644 --- a/packaging/initrd-flash.spec +++ b/packaging/initrd-flash.spec @@ -54,6 +54,7 @@ cp ./data/partition_* %{buildroot}%{_datadir}/ mkdir -p %{buildroot}%{_libdir}/firmware/brcm cp ./data/brcmfmac* %{buildroot}%{_libdir}/firmware/brcm cp ./data/LICENCE.broadcom_bcm43xx %{buildroot}%{_libdir}/firmware/brcm +cp ./data/hostapd.conf %{buildroot}%{_libdir}/firmware/brcm %post @@ -70,6 +71,7 @@ mv %{_datadir}/partition_rpi3.info %{_datadir}/partition.info %attr(700,root,root) %{_datadir}/initrd-recovery/initrd.list.d/*.list %attr(700,root,root) %{_libdir}/firmware/brcm/brcmfmac* %attr(700,root,root) %{_libdir}/firmware/brcm/LICENCE.broadcom_bcm43xx +%attr(700,root,root) %{_libdir}/firmware/brcm/hostapd.conf %files -n fm-data-rpi3 %attr(700,root,root) %{_datadir}/partition_rpi3.info diff --git a/scripts/41-flash.list b/scripts/41-flash.list index cffd31c..1c48b74 100755 --- a/scripts/41-flash.list +++ b/scripts/41-flash.list @@ -33,4 +33,5 @@ VERBATIMS=" /usr/lib/firmware/brcm/brcmfmac43430-sdio.txt /usr/lib/firmware/brcm/brcmfmac43455-sdio.txt /usr/lib/firmware/brcm/LICENCE.broadcom_bcm43xx +/usr/lib/firmware/brcm/hostapd.conf " -- 2.7.4 From 0728bfecea8ed3f9fe1dd6b48abdfd37ee541857 Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Tue, 16 Apr 2019 20:00:35 +0900 Subject: [PATCH 02/16] packaging: add dnsmasq package as Requires Add dnsmasq package as Requires. dnsmasq provides DHCP/DNS server role. When client try to associate to AP, it will be assigned to client's ip address. Change-Id: I6c3cace46ff7e3df87ef212e772251968405a914 Signed-off-by: Jaehoon Chung --- packaging/initrd-flash.spec | 1 + scripts/41-flash.list | 1 + 2 files changed, 2 insertions(+) diff --git a/packaging/initrd-flash.spec b/packaging/initrd-flash.spec index d549718..b791e48 100644 --- a/packaging/initrd-flash.spec +++ b/packaging/initrd-flash.spec @@ -15,6 +15,7 @@ Requires: initrd-recovery Requires: fm-data Requires: module-init-tools Requires: wpa_supplicant +Requires: dnsmasq %description Provide kernel-based target image downloader. diff --git a/scripts/41-flash.list b/scripts/41-flash.list index 1c48b74..5aa0eda 100755 --- a/scripts/41-flash.list +++ b/scripts/41-flash.list @@ -18,6 +18,7 @@ WITHLIBS=" /sbin/insmod /bin/find /bin/hostapd +/bin/dnsmasq " # LinkFileName:Target -- 2.7.4 From af5cfb03e4896792de8cf060d5d24349d3f9cd63 Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Tue, 16 Apr 2019 20:07:33 +0900 Subject: [PATCH 03/16] packaging: include dnsmasq config file To use dnsmasq, include dnsmasq.conf file. - run background with pid-file - user/group don't assigne to nothing for ramdisk-recovery Change-Id: I71e517e1f4cb74b5493a50668823f3d43fa3c982 Signed-off-by: Jaehoon Chung --- data/dnsmasq.conf | 7 +++++++ packaging/initrd-flash.spec | 2 ++ scripts/41-flash.list | 1 + 3 files changed, 10 insertions(+) create mode 100755 data/dnsmasq.conf diff --git a/data/dnsmasq.conf b/data/dnsmasq.conf new file mode 100755 index 0000000..a8d5a27 --- /dev/null +++ b/data/dnsmasq.conf @@ -0,0 +1,7 @@ +dhcp-range=192.168.43.3,192.168.43.254,255.255.255.0 +enable-dbus +group="" +user="" +dhcp-option=tag:blue,option:router,192.168.129.3 +dhcp-option=6,0.0.0.0 +pid-file=/lib/firmware/brcm/dnsmasq.pid diff --git a/packaging/initrd-flash.spec b/packaging/initrd-flash.spec index b791e48..9bfc980 100644 --- a/packaging/initrd-flash.spec +++ b/packaging/initrd-flash.spec @@ -56,6 +56,7 @@ mkdir -p %{buildroot}%{_libdir}/firmware/brcm cp ./data/brcmfmac* %{buildroot}%{_libdir}/firmware/brcm cp ./data/LICENCE.broadcom_bcm43xx %{buildroot}%{_libdir}/firmware/brcm cp ./data/hostapd.conf %{buildroot}%{_libdir}/firmware/brcm +cp ./data/dnsmasq.conf %{buildroot}%{_libdir}/firmware/brcm %post @@ -73,6 +74,7 @@ mv %{_datadir}/partition_rpi3.info %{_datadir}/partition.info %attr(700,root,root) %{_libdir}/firmware/brcm/brcmfmac* %attr(700,root,root) %{_libdir}/firmware/brcm/LICENCE.broadcom_bcm43xx %attr(700,root,root) %{_libdir}/firmware/brcm/hostapd.conf +%attr(700,root,root) %{_libdir}/firmware/brcm/dnsmasq.conf %files -n fm-data-rpi3 %attr(700,root,root) %{_datadir}/partition_rpi3.info diff --git a/scripts/41-flash.list b/scripts/41-flash.list index 5aa0eda..3f165d1 100755 --- a/scripts/41-flash.list +++ b/scripts/41-flash.list @@ -35,4 +35,5 @@ VERBATIMS=" /usr/lib/firmware/brcm/brcmfmac43455-sdio.txt /usr/lib/firmware/brcm/LICENCE.broadcom_bcm43xx /usr/lib/firmware/brcm/hostapd.conf +/usr/lib/firmware/brcm/dnsmasq.conf " -- 2.7.4 From 9ca062dd778ea1c997837005351f66601b1eb025 Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Wed, 17 Apr 2019 07:39:01 +0900 Subject: [PATCH 04/16] scripts: flash-init: use dnsmasq and hostapd Use dnsmasq and hostapd for AP mode. wlan0 is used static ip as 192.168.43.1. Change-Id: Id9f8fdd1d1b1a3d30dd9306f13834b86267df978 Signed-off-by: Jaehoon Chung --- scripts/flash-init.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/flash-init.sh b/scripts/flash-init.sh index 2c0aa81..7ccf3ca 100755 --- a/scripts/flash-init.sh +++ b/scripts/flash-init.sh @@ -16,6 +16,8 @@ SYNC="/usr/bin/sync" COPY="/usr/bin/cp" FIND="/usr/bin/find" INSMOD="/usr/sbin/insmod" +DNSMASQ="/usr/bin/dnsmasq" +HOSTAPD="/usr/bin/hostapd" NETIF="eth0" WLANIF="wlan0" @@ -51,7 +53,11 @@ copy_module() { $INSMOD /lib/firmware/brcm/brcmfmac.ko sleep 1 - $IFCONFIG $WLANIF up + echo "wlan0 ipaddr is 192.168.43.1" + $IFCONFIG $WLANIF 192.168.43.1 up + + $DNSMASQ -p 0 -9 -C /lib/firmware/brcm/dnsmasq.conf + $HOSTAPD -B /lib/firmware/brcm/hostapd.conf else echo "There is no module partition" fi -- 2.7.4 From 43f87fca042a7dab32a5ec8bd57b22e786491ddc Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Thu, 18 Apr 2019 10:36:43 +0900 Subject: [PATCH 05/16] scripts: Prevent failure of ip assigning If init script tries to assign ip before usb nic is ready, it fails and the target is rebooted. To prevent this, tries several times for assigning, and determine failure after exceeding maximum tries. Change-Id: Iaa8dfbcee57985c69055e4742818f8256fba1cdd Signed-off-by: Dongwoo Lee --- scripts/flash-init.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/flash-init.sh b/scripts/flash-init.sh index 7ccf3ca..aba4d7e 100755 --- a/scripts/flash-init.sh +++ b/scripts/flash-init.sh @@ -71,16 +71,25 @@ print_ip() { if [ "z$IPADDR" == "z" ]; then IPADDR="192.168.0.100" - RESULT=`"$IFCONFIG" $NETIF $IPADDR up` - - if [ "z$RESULT" != "z" ]; then + RETRY_MAX=5 + RETRY=0 + while [ $RETRY -lt $RETRY_MAX ]; do + RESULT=`"$IFCONFIG" $NETIF $IPADDR up 2>&1` + if [ "z$RESULT" == "z" ]; then + echo "IP address is not set, using default (192.168.0.100)" + break + fi + + RETRY=$((RETRY + 1)) + echo "Retry to set IP address #${RETRY}" + sleep 1 + done + + if [ $RETRY -eq $RETRY_MAX ]; then echo "Failed to set IP address, Reboot..." "$REBOOT" fi - - echo "IP address is not set, using default (192.168.0.100)" fi - echo "IP address is set to ${IPADDR}" } #------------------------------------------------ -- 2.7.4 From 3ac733180b0c18d04106ef2650a45c1f7c532ff1 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Mon, 22 Apr 2019 16:53:12 +0900 Subject: [PATCH 06/16] scripts: Print out brief information about network connection This patch refactors init script in order to provide brief information of the target network as below: Network Information: Wired: xxx.xxx.xxx.xxx Wireless: xxx.xxx.xxx.xxx [SSID: xxxxxxxxx] Change-Id: I5df962443cc846e60a5952dbb3e8dadb37273dd3 Signed-off-by: Dongwoo Lee --- scripts/flash-init.sh | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/scripts/flash-init.sh b/scripts/flash-init.sh index aba4d7e..e5d12f8 100755 --- a/scripts/flash-init.sh +++ b/scripts/flash-init.sh @@ -34,7 +34,7 @@ clear_bootmode() { #------------------------------------------------ # Copy Module and Firmware file #------------------------------------------------ -copy_module() { +setup_wireless() { MODULES_PART=`"$BLKID" --label modules` if [ "$MODULES_PART" != "" ]; then echo "Module partition is $MODULES_PART" @@ -53,20 +53,22 @@ copy_module() { $INSMOD /lib/firmware/brcm/brcmfmac.ko sleep 1 - echo "wlan0 ipaddr is 192.168.43.1" - $IFCONFIG $WLANIF 192.168.43.1 up + WLANIP="192.168.43.1" + $IFCONFIG $WLANIF ${WLANIP} up $DNSMASQ -p 0 -9 -C /lib/firmware/brcm/dnsmasq.conf - $HOSTAPD -B /lib/firmware/brcm/hostapd.conf + SSID=`$HOSTAPD -B /lib/firmware/brcm/hostapd.conf | "$GREP" -oP '(?<=ssid\s\")(.*?)(?=\")'` else echo "There is no module partition" + WLANIP="N/A" + SSID="N/A" fi } #------------------------------------------------ -# print_ip +# setup_writed_nic() #------------------------------------------------ -print_ip() { +setup_wired_nic() { IPADDR=`"$IP" -4 addr show $NETIF | "$GREP" -oP '(?<=inet\s)\d+(\.\d+){3}'` if [ "z$IPADDR" == "z" ]; then IPADDR="192.168.0.100" @@ -93,6 +95,18 @@ print_ip() { } #------------------------------------------------ +# print_info() +#------------------------------------------------ +print_info() { + echo "" + echo "Tizen flash manager is ready." + echo "" + echo "Network Information:" + echo "Wired: ${IPADDR}" + echo "Wireless: ${WLANIP} [SSID: ${SSID}]" +} + +#------------------------------------------------ # do_flash #------------------------------------------------ do_flash() { @@ -108,7 +122,8 @@ do_flash() { #------------------------------------------------ # Main Routine Start #------------------------------------------------ -print_ip +setup_wired_nic +setup_wireless clear_bootmode -copy_module +print_info do_flash -- 2.7.4 From 6d921f96e595d984efb9dc9cb9a47e87478c373a Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Thu, 9 May 2019 14:24:14 +0900 Subject: [PATCH 07/16] packaging: move firmware file to data directory Move firmare file to data directory from /lib/firmware/brcm/. Change-Id: I5d37d3fda035bc271fb62ef0c8f8b2926828fbf1 Signed-off-by: Jaehoon Chung --- packaging/initrd-flash.spec | 18 +++++++++--------- scripts/41-flash.list | 14 +++++++------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packaging/initrd-flash.spec b/packaging/initrd-flash.spec index 9bfc980..d6dc741 100644 --- a/packaging/initrd-flash.spec +++ b/packaging/initrd-flash.spec @@ -52,11 +52,11 @@ cp ./scripts/41-flash.list %{buildroot}%{_datadir}/initrd-recovery/initrd.list.d cp ./data/partition_* %{buildroot}%{_datadir}/ -mkdir -p %{buildroot}%{_libdir}/firmware/brcm -cp ./data/brcmfmac* %{buildroot}%{_libdir}/firmware/brcm -cp ./data/LICENCE.broadcom_bcm43xx %{buildroot}%{_libdir}/firmware/brcm -cp ./data/hostapd.conf %{buildroot}%{_libdir}/firmware/brcm -cp ./data/dnsmasq.conf %{buildroot}%{_libdir}/firmware/brcm +mkdir -p %{buildroot}%{_datadir}/firmware/brcm +cp ./data/brcmfmac* %{buildroot}%{_datadir}/firmware/brcm +cp ./data/LICENCE.broadcom_bcm43xx %{buildroot}%{_datadir}/firmware/brcm +cp ./data/hostapd.conf %{buildroot}%{_datadir}/firmware/brcm +cp ./data/dnsmasq.conf %{buildroot}%{_datadir}/firmware/brcm %post @@ -71,10 +71,10 @@ mv %{_datadir}/partition_rpi3.info %{_datadir}/partition.info %attr(700,root,root) %{_bindir}/flash-manager %attr(700,root,root) %{init_script_dir}/*.sh %attr(700,root,root) %{_datadir}/initrd-recovery/initrd.list.d/*.list -%attr(700,root,root) %{_libdir}/firmware/brcm/brcmfmac* -%attr(700,root,root) %{_libdir}/firmware/brcm/LICENCE.broadcom_bcm43xx -%attr(700,root,root) %{_libdir}/firmware/brcm/hostapd.conf -%attr(700,root,root) %{_libdir}/firmware/brcm/dnsmasq.conf %files -n fm-data-rpi3 %attr(700,root,root) %{_datadir}/partition_rpi3.info +%attr(700,root,root) %{_datadir}/firmware/brcm/brcmfmac* +%attr(700,root,root) %{_datadir}/firmware/brcm/LICENCE.broadcom_bcm43xx +%attr(700,root,root) %{_datadir}/firmware/brcm/hostapd.conf +%attr(700,root,root) %{_datadir}/firmware/brcm/dnsmasq.conf diff --git a/scripts/41-flash.list b/scripts/41-flash.list index 3f165d1..66a2c69 100755 --- a/scripts/41-flash.list +++ b/scripts/41-flash.list @@ -2,6 +2,13 @@ MVWITHLIBS=" /usr/lib/initrd-recovery/flash/flash-init.sh /bin/flash-manager +/usr/share/firmware/brcm/brcmfmac43430-sdio.bin +/usr/share/firmware/brcm/brcmfmac43455-sdio.bin +/usr/share/firmware/brcm/brcmfmac43430-sdio.txt +/usr/share/firmware/brcm/brcmfmac43455-sdio.txt +/usr/share/firmware/brcm/LICENCE.broadcom_bcm43xx +/usr/share/firmware/brcm/hostapd.conf +/usr/share/firmware/brcm/dnsmasq.conf " WITHLIBS=" @@ -29,11 +36,4 @@ SYMLINKS=" VERBATIMS=" /usr/share/partition.info -/usr/lib/firmware/brcm/brcmfmac43430-sdio.bin -/usr/lib/firmware/brcm/brcmfmac43455-sdio.bin -/usr/lib/firmware/brcm/brcmfmac43430-sdio.txt -/usr/lib/firmware/brcm/brcmfmac43455-sdio.txt -/usr/lib/firmware/brcm/LICENCE.broadcom_bcm43xx -/usr/lib/firmware/brcm/hostapd.conf -/usr/lib/firmware/brcm/dnsmasq.conf " -- 2.7.4 From 19f856576e42745cf8a1d2256c3b6cb54e4263eb Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Thu, 9 May 2019 16:10:40 +0900 Subject: [PATCH 08/16] scripts: flash-init: create symbolic link about firmware path Create symbolic link about firmware path. Change-Id: Ia0243afbafddbeef2bf797b3ad184150af75f4c5 Signed-off-by: Jaehoon Chung --- scripts/41-flash.list | 1 + scripts/flash-init.sh | 2 ++ 2 files changed, 3 insertions(+) diff --git a/scripts/41-flash.list b/scripts/41-flash.list index 66a2c69..c9c2611 100755 --- a/scripts/41-flash.list +++ b/scripts/41-flash.list @@ -26,6 +26,7 @@ WITHLIBS=" /bin/find /bin/hostapd /bin/dnsmasq +/bin/ln " # LinkFileName:Target diff --git a/scripts/flash-init.sh b/scripts/flash-init.sh index e5d12f8..799e80a 100755 --- a/scripts/flash-init.sh +++ b/scripts/flash-init.sh @@ -18,6 +18,7 @@ FIND="/usr/bin/find" INSMOD="/usr/sbin/insmod" DNSMASQ="/usr/bin/dnsmasq" HOSTAPD="/usr/bin/hostapd" +LINK="/usr/bin/ln" NETIF="eth0" WLANIF="wlan0" @@ -44,6 +45,7 @@ setup_wireless() { BRCMUTIL=`$FIND ${TMP_PATH} -name brcmutil.ko` echo "Module brcmfmac is $BRCMFMAC" echo "Module brcmutil is $BRCMUTIL" + $LINK -s /usr/share/firmware /lib/firmware $COPY $BRCMFMAC /lib/firmware/brcm/ $COPY $BRCMUTIL /lib/firmware/brcm/ $SYNC -- 2.7.4 From b45ae10a1ffaa0ee18581c655c0b4117d25eba69 Mon Sep 17 00:00:00 2001 From: Junghoon Kim Date: Thu, 9 May 2019 21:26:39 +0900 Subject: [PATCH 09/16] data: Update the partition info file to support 32-bit architecture This patch adds the dtb and zImage to the partition info file, in order to support 32-bit architecture. Also, common u-boot and config files have been added to facilitate testing between 32-bit and 64-bit architectures. Change-Id: Idf27f33e50bbafbf438b78d6b336d4794416aa18 Signed-off-by: Junghoon Kim --- data/partition_rpi3.info | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/data/partition_rpi3.info b/data/partition_rpi3.info index 8acd369..e22defc 100644 --- a/data/partition_rpi3.info +++ b/data/partition_rpi3.info @@ -6,7 +6,13 @@ p:/dev/mmcblk0p6:modules.img:x p:/dev/mmcblk0p7:ramdisk.img:x p:/dev/mmcblk0p8:ramdisk-recovery.img:x f:/dev/mmcblk0p1:Image:/ +f:/dev/mmcblk0p1:zImage:/ f:/dev/mmcblk0p1:bcm2710-rpi-3-b-plus.dtb:/ f:/dev/mmcblk0p1:bcm2710-rpi-cm3.dtb:/ f:/dev/mmcblk0p1:bcm2710-rpi-3-b.dtb:/ f:/dev/mmcblk0p1:bcm2837-rpi-3-b.dtb:/ +f:/dev/mmcblk0p1:bcm2837-rpi-3-b-plus.dtb:/ +f:/dev/mmcblk0p1:u-boot.bin:/ +f:/dev/mmcblk0p1:uboot.env:/ +f:/dev/mmcblk0p1:boot.scr.uimg:/ +f:/dev/mmcblk0p1:config.txt:/ -- 2.7.4 From ad730409dcecc9e34e7b5ecc2da459a43640854b Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Tue, 25 Jun 2019 10:23:49 +0900 Subject: [PATCH 10/16] CMakeLists: Apply PIE flags To support ASLR, this patch applies PIE (position independent executable) flags to CMakeLists.txt. Change-Id: If7eae9c8aad08fe9da3083cbdad64a7221fdaa98 Signed-off-by: Dongwoo Lee --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca1de19..c722f06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,9 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(flash-manager C) +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE -O2") +SET(CMAKE_EXE_LINKER_FLAGS "-pie") + FIND_PACKAGE(Threads REQUIRED) ADD_EXECUTABLE(${PROJECT_NAME} src/main.c src/thor.c src/dfu.c src/net.c) @@ -9,6 +12,4 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) TARGET_LINK_LIBRARIES(flash-manager "${CMAKE_THREAD_LIBS_INIT}" blkid) -ADD_DEFINITIONS(-Wall -g -O2) - INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) -- 2.7.4 From 4162a2d539e6d3a52521c3cff9b0960db5a954ca Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Mon, 8 Jul 2019 16:07:45 +0900 Subject: [PATCH 11/16] dfu: Free resources on error This patch makes resources are freed on error case while scanning the type of filesystem with blkid APIs. This resource leakage was reported by static analystic tool. Change-Id: Ibeba4190316fb1db0bde02eaca0648c0db0bad2e Signed-off-by: Dongwoo Lee --- src/dfu.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/dfu.c b/src/dfu.c index 0131e42..4edf1a1 100644 --- a/src/dfu.c +++ b/src/dfu.c @@ -102,7 +102,7 @@ static char *get_partition_fstype(const char *devname) blkid_tag_iterate tag_iter; blkid_dev dev; blkid_cache cache = NULL; - const char *type, *value; + const char *type, *value, *fstype = NULL; int ret; ret = blkid_get_cache(&cache, NULL); @@ -113,29 +113,29 @@ static char *get_partition_fstype(const char *devname) dev = blkid_get_dev(cache, devname, 0); if (!dev) - return NULL; + goto err_put_cache; dev = blkid_verify(cache, dev); if (!dev) - return NULL; + goto err_put_cache; tag_iter = blkid_tag_iterate_begin(dev); while (blkid_tag_next(tag_iter, &type, &value) == 0) { if (!strncmp(type, "TYPE", 4)) { - char *fstype = strdup(value); - + fstype = strdup(value); if (!fstype) - return NULL; + fprintf(stderr, "failed to duplicate fs type string\n"); - blkid_tag_iterate_end(tag_iter); - blkid_put_cache(cache); - return fstype; + break; } } + blkid_tag_iterate_end(tag_iter); + +err_put_cache: blkid_put_cache(cache); - return NULL; + return fstype; } static int mount_dev(const char *dev) -- 2.7.4 From dc56768ae46d1076abe20e03c66fd3d99bf49dc2 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Fri, 3 Jan 2020 14:46:28 +0900 Subject: [PATCH 12/16] data: Add rpi4 dtb as a flashing entity To support tizen flash manager for rpi4, this adds a dtb file for bcm2711 into partition information file. Change-Id: I9b4a97c5d80f40c329d04f87d1eb1b29066d17f0 Signed-off-by: Dongwoo Lee --- data/partition_rpi3.info | 1 + 1 file changed, 1 insertion(+) diff --git a/data/partition_rpi3.info b/data/partition_rpi3.info index e22defc..ad1bb42 100644 --- a/data/partition_rpi3.info +++ b/data/partition_rpi3.info @@ -12,6 +12,7 @@ f:/dev/mmcblk0p1:bcm2710-rpi-cm3.dtb:/ f:/dev/mmcblk0p1:bcm2710-rpi-3-b.dtb:/ f:/dev/mmcblk0p1:bcm2837-rpi-3-b.dtb:/ f:/dev/mmcblk0p1:bcm2837-rpi-3-b-plus.dtb:/ +f:/dev/mmcblk0p1:bcm2711-rpi-4-b.dtb:/ f:/dev/mmcblk0p1:u-boot.bin:/ f:/dev/mmcblk0p1:uboot.env:/ f:/dev/mmcblk0p1:boot.scr.uimg:/ -- 2.7.4 From 2b507f419bfe606103e1f680af31b9838f8f919d Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Wed, 8 Jan 2020 17:53:40 +0900 Subject: [PATCH 13/16] Fix gcc9 build warnings This fixes build warnings on compiling with gcc9. Change-Id: I7ff58499fc2813931ff49c8f7d58e851b08ef5dc Signed-off-by: Dongwoo Lee --- src/dfu.c | 3 ++- src/thor.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/dfu.c b/src/dfu.c index 4edf1a1..ea548f5 100644 --- a/src/dfu.c +++ b/src/dfu.c @@ -102,7 +102,8 @@ static char *get_partition_fstype(const char *devname) blkid_tag_iterate tag_iter; blkid_dev dev; blkid_cache cache = NULL; - const char *type, *value, *fstype = NULL; + const char *type, *value; + char *fstype = NULL; int ret; ret = blkid_get_cache(&cache, NULL); diff --git a/src/thor.c b/src/thor.c index 1d131cf..d6dfa09 100644 --- a/src/thor.c +++ b/src/thor.c @@ -81,7 +81,7 @@ static int thor_process_rqt_info(struct tfm_context *ctx, struct rqt_pkt *rqt) case RQT_INFO_VER_KERNEL: case RQT_INFO_VER_PLATFORM: case RQT_INFO_VER_CSC: - strncpy(rsp.str_data[0], "Unknown", sizeof("Unknown")); + strncpy(rsp.str_data[0], "Unknown", 32); break; default: fprintf(stderr, "Not supported information request: %d\n", -- 2.7.4 From 7062cae242638f20b61cda27f10a67b54879e427 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Fri, 10 Jan 2020 15:10:49 +0900 Subject: [PATCH 14/16] dfu: do stringop with termination character Doing string operation with strlen() result, there is possibilty of omission of termination character. Do stringop with termination character with strlen() + 1. The destination buffer is allocated sum of all strlen() and 1, there is no overflow. Change-Id: I35627dbbb0ac72bc58398ccfffa43802729c5b85 Signed-off-by: Seung-Woo Kim --- src/dfu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dfu.c b/src/dfu.c index ea548f5..0a1b297 100644 --- a/src/dfu.c +++ b/src/dfu.c @@ -236,8 +236,8 @@ static int dfu_start_entity(struct tfm_context *ctx, int idx, unsigned long size } strncpy(file, DFU_MOUNT_PATH, path_prefix + 1); - strncat(file, info[DFU_INFO_PATH], path_suffix); - strncat(file, info[DFU_INFO_NAME], path_name); + strncat(file, info[DFU_INFO_PATH], path_suffix + 1); + strncat(file, info[DFU_INFO_NAME], path_name + 1); break; } default: -- 2.7.4 From 47fba2f480c071a3b308910dbd47e6aa2b49cb49 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Fri, 10 Jan 2020 15:29:42 +0900 Subject: [PATCH 15/16] fix use string after null check The result of strdup() can be null, so use it after null check. Change-Id: I61b5e5a4d4b631984eb19240b46afe0e94752043 Signed-off-by: Seung-Woo Kim --- src/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 194e2c8..80267db 100644 --- a/src/main.c +++ b/src/main.c @@ -39,7 +39,8 @@ int _main(int argc, char *argv[]) if (opt_table) free(opt_table); opt_table = strdup(optarg); - part_table = opt_table; + if (opt_table) + part_table = opt_table; } else { fprintf(stderr, "path should be specified with '-i'\n"); -- 2.7.4 From 737d065c7fa0dc71223f6eb83dcb938b640dbea4 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Mon, 10 Feb 2020 15:28:36 +0900 Subject: [PATCH 16/16] Fix to check memory allocation failure The strdup() can be failed and return NULL. Not to access wrong memory, explictly check memory allocation failure. Change-Id: I2917cf0cebd6488004b653c29137c0acbb56074e Signed-off-by: Seung-Woo Kim --- src/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 80267db..32c2473 100644 --- a/src/main.c +++ b/src/main.c @@ -39,8 +39,13 @@ int _main(int argc, char *argv[]) if (opt_table) free(opt_table); opt_table = strdup(optarg); - if (opt_table) + if (opt_table) { part_table = opt_table; + } else { + fprintf(stderr, "Out of memory\n"); + ret = -1; + goto out; + } } else { fprintf(stderr, "path should be specified with '-i'\n"); -- 2.7.4