OP-TEE / build

Makefiles to use OP-TEE on various platforms
109 stars 218 forks source link

Fail to build OP-TEE 3.21.0 for Hikey 960 #652

Closed TaihuLight closed 1 year ago

TaihuLight commented 1 year ago

OP-TEE 3.20.0 can be built on my host PC successfully. But, OP-TEE 3.21.0 can not be built successfully on the same PC with the same environment. Errors shows as following:

/home/pelops2/hikey960/tee321/edk2/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c: In function ‘UsbIoBulkTransfer’:
/home/pelops2/hikey960/tee321/edk2/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c:259:12: error: ‘UsbHcBulkTransfer’ accessing 80 bytes in a region of size 8 [-Werror=stringop-overflow=]
  259 |   Status  = UsbHcBulkTransfer (
      |            ^~~~~~~~~~~~~~~~~~~~
  260 |               Dev->Bus,
      |               ~~~~~~~~~
  261 |               Dev->Address,
      |               ~~~~~~~~~~~~~
  262 |               Endpoint,
      |               ~~~~~~~~~
  263 |               Dev->Speed,
      |               ~~~~~~~~~~~
  264 |               EpDesc->Desc.MaxPacketSize,
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  265 |               BufNum,
      |               ~~~~~~~
  266 |               &Data,
      |               ~~~~~~
  267 |               DataLength,
      |               ~~~~~~~~~~~
  268 |               &Toggle,
      |               ~~~~~~~~
  269 |               Timeout,
      |               ~~~~~~~~
  270 |               &Dev->Translator,
      |               ~~~~~~~~~~~~~~~~~
  271 |               UsbStatus
      |               ~~~~~~~~~
  272 |               );
      |               ~
/home/pelops2/hikey960/tee321/edk2/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c:259:12: note: referencing argument 7 of type ‘void **’
In file included from /home/pelops2/hikey960/tee321/edk2/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h:46,
                 from /home/pelops2/hikey960/tee321/edk2/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c:16:
/home/pelops2/hikey960/tee321/edk2/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.h:200:1: note: in a call to function ‘UsbHcBulkTransfer’
  200 | UsbHcBulkTransfer (
      | ^~~~~~~~~~~~~~~~~
"echo" objcopy not needed for /home/pelops2/hikey960/tee321/edk2/Build/HiKey960/RELEASE_GCC49/AARCH64/MdeModulePkg/Bus/Sd/SdDxe/SdDxe/DEBUG/SdDxe.dll
objcopy not needed for /home/pelops2/hikey960/tee321/edk2/Build/HiKey960/RELEASE_GCC49/AARCH64/MdeModulePkg/Bus/Sd/SdDxe/SdDxe/DEBUG/SdDxe.dll
.....
cc1: all warnings being treated as errors
make[1]: *** [GNUmakefile:489: /home/pelops2/hikey960/tee321/edk2/Build/HiKey960/RELEASE_GCC49/AARCH64/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe/OUTPUT/UsbBus.obj] Error 1
make[1]: Leaving directory '/home/pelops2/hikey960/tee321/edk2/Build/HiKey960/RELEASE_GCC49/AARCH64/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe'

build.py...
 : error 7000: Failed to execute command
    make tbuild [/home/pelops2/hikey970/tee321/edk2/Build/HiKey960/RELEASE_GCC49/AARCH64/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe]

build.py...
 : error F002: Failed to build module
    /home/pelops2/hikey970/tee321/edk2/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf [AARCH64, GCC49, RELEASE]

- Failed -
Build end time: 08:56:56, May.20 2023
Build total time: 00:00:12

make: *** [Makefile:134: edk2] Error 1

@jforissier @jbech-linaro @jenswi-linaro

jforissier commented 1 year ago

Try this:

diff --git a/hikey960.mk b/hikey960.mk
index dbff5c2..af167b3 100644
--- a/hikey960.mk
+++ b/hikey960.mk
@@ -134,7 +134,7 @@ edk2:
        ln -s $(OPENPLATPKG_PATH)
    set -e && cd $(EDK2_PATH) && source edksetup.sh && \
        $(MAKE) -j1 -C $(EDK2_PATH)/BaseTools \
-           BUILD_CC="gcc $(call cc-option,gcc,-Wno-error=stringop-truncation,)" && \
+           BUILD_CC="gcc $(call cc-option,gcc,-Wno-error=stringop-truncation,) $(call cc-option,gcc,-Wno-error=stringop-overflow,)" && \
        $(call edk2-call)

 .PHONY: edk2-cleandiff --git a/hikey960.mk b/hikey960.mk

EDK2 for HiKey is unmaintained, so unless someone takes up this task it is likely that sooner or later we will have to drop it and use something else (U-Boot), or even remove HiKey in OP-TEE support entirely.

TaihuLight commented 1 year ago

@jforissier I will try to do it tomorrow, and reply you timely. please do not remove OP-TEE support for hikey960. It is important for reseachers.

jforissier commented 1 year ago

@jforissier I will try to do it tomorrow, and reply you timely. please do not remove OP-TEE support for hikey960. It is important for reseachers.

Don't worry, we will not remove anything unless there is a good reason and we will always discuss here first. I am glad to hear that people are still using HiKey, and I hope we can get patches to make it live longer! I personally used to use HiKey/HiKey960 a lot, but not so much so.

If my above suggestion works for you, please create a pull request so it can be merged (note that the hikey.mk file needs the same fix too I suppose). Thanks!

TaihuLight commented 1 year ago

@jforissier I am very sorry for that. The method https://github.com/OP-TEE/build/issues/652#issuecomment-1585681108 does not work. The same error occurred. This issue may arise from the default toolchain version 11.3 being too new, Because I could build OP-TEE for Hikey 960 with the old toolchain version 10.2 as following (also shown in #625)

$ cd build
$ make -j4 toolchains AARCH32_GCC_VERSION= gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf SRC_AARCH32_GCC= https://developer.arm.com/-/media/Files/downloads/gnu-a/10.2-2020.11/binrel/$(AARCH32_GCC_VERSION).tar.xz
AARCH64_GCC_VERSION= gcc-arm-10.2-2020.11-x86_64-aarch64-none-linux-gnu SRC_AARCH64_GCC = https://developer.arm.com/-/media/Files/downloads/gnu-a/10.2-2020.11/binrel/$(AARCH64_GCC_VERSION).tar.xz
$ make all -j6 PLATFORM=hikey-hikey960 CFG_DRAM_SIZE_GB=4 BR2_TOOLCHAIN_EXTERNAL_GCC_10=y BR2_TOOLCHAIN_EXTERNAL_INET_RPC=y

So, how to fix this issue for building OP-TEE 3.21.0 for Hikey 960 with the default GCC toolchain version 11.3?

jforissier commented 1 year ago

In fact, the C flags have to be modified in GCC_ALL_CC_FLAGS in edk2/BaseTools/Conf/tools_def.template like so:

diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
index 2b4fb47ec..8a58208e8 100755
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -4338,7 +4338,7 @@ DEBUG_*_*_OBJCOPY_ADDDEBUGFLAG     = --add-gnu-debuglink=$(DEBUG_DIR)/$(MODULE_N
 RELEASE_*_*_OBJCOPY_ADDDEBUGFLAG   =
 NOOPT_*_*_OBJCOPY_ADDDEBUGFLAG     = --add-gnu-debuglink=$(DEBUG_DIR)/$(MODULE_NAME).debug

-DEFINE GCC_ALL_CC_FLAGS            = -g -Os -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -include AutoGen.h -fno-common
+DEFINE GCC_ALL_CC_FLAGS            = -g -Os -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -Wno-stringop-overflow -include AutoGen.h -fno-common^M
 DEFINE GCC_IA32_CC_FLAGS           = DEF(GCC_ALL_CC_FLAGS) -m32 -malign-double -freorder-blocks -freorder-blocks-and-partition -O2 -mno-stack-arg-probe
 DEFINE GCC_X64_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -mno-red-zone -Wno-address -mno-stack-arg-probe
 DEFINE GCC_IPF_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -minline-int-divide-min-latency

Please refer to this Dockerfile, it worked for me: Dockerfile.txt

Perhaps we should add the sed command to hikey{,960}.mk.

TaihuLight commented 1 year ago

@jforissier Thank you very much. The suggestion https://github.com/OP-TEE/build/issues/652#issuecomment-1586324847 is work for me. I would like to test OP-TEE support for Hikey 960 and then report the results. This work may be complemented in later, because I must buy a new UART-USB for testing the result.

github-actions[bot] commented 1 year ago

This issue has been marked as a stale issue because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 5 days. Note, that you can always re-open a closed issue at any time.