Attempt for supporting uboot on hikey960


#1

Hi,

I found currently u-boot is not supported for hikey960.
So I am trying to support it from a limited open hardware details available.

When I checked, Peter Griffin’s work for Hikey620, I found,
most of his work is towards, device drivers of PMIC, USB, eMMC, pinmux, etc. Not much modifications in arm64 and also for common codes.
He uses, common board_init_f() and common borad_init_r().

Now I am trying to get atleast some debug prints via serial console and see upto where it can go. By skipping the things which are creating issues, I believe I can get a uboot prompt.

Atleast If I can make the external sdcard interface up, I can load my image to RAM and execute.

Now I am trying to enter to uboot entry point. (_start)
If I can get in to the entry point, I assume, I can use the printascii kind of debug printing until I can execute some C code.

My current bootloader is UEFI-GRUB2 and I have few query as given below.
1. I could not find where is the place of ATF in booting stage?
2. Who calls entry of UEFI?
3. Who/How to enter into GRUB2 entry point?
4. Where can be the possible place of uboot in the current booting steps.?
5. Who can load and jump to u-boot entry point?
6. How to get a combined bootloader image with other bootloader components.

Any help in this topic would be really appreciated.

Thanks in advance,
Sreenad.


#2

@sreenad UEFI is loaded by ATF as BL33 image. You can use u-boot as BL33 image instead of UEFI. BL33 image entry-point is called from ATF.
To create combined boot-loader image (fip.bin) with UEFI as BL33 image refer to: https://github.com/ARM-software/arm-trusted-firmware/blob/master/docs/plat/hikey960.rst

AFAIK u-boot is compiled with fixed base address and you need to set BL33_BASE in ATF accordingly.

Regarding GRUB2, its an “.efi” application launched by UEFI.


#3

Thanks Sumit for your reply.

I have tried to build bootloader from source, referring, [https://github.com/ARM-software/arm-trusted-firmware/blob/master/docs/plat/hikey960.rst].

But I am getting build error

/home/sreenad/hikey960_bootloader/edk2/OpenPlatformPkg/Platforms/Hisilicon/HiKey960/Library/HiKey960Lib/HiKey960Mem.c:82: undefined reference to __stack_chk_guard' /home/sreenad/hikey960_bootloader/edk2/OpenPlatformPkg/Platforms/Hisilicon/HiKey960/Library/HiKey960Lib/HiKey960Mem.c:256: undefined reference to__stack_chk_guard’
/home/sreenad/hikey960_bootloader/edk2/OpenPlatformPkg/Platforms/Hisilicon/HiKey960/Library/HiKey960Lib/HiKey960Mem.c:256: undefined reference to __stack_chk_guard' /home/sreenad/hikey960_bootloader/edk2/OpenPlatformPkg/Platforms/Hisilicon/HiKey960/Library/HiKey960Lib/HiKey960Mem.c:256: undefined reference to__stack_chk_fail’
collect2: error: ld returned 1 exit status
make: *** [/home/sreenad/hikey960_bootloader/edk2/Build/HiKey960/DEBUG_GCC5/AARCH64/ArmPlatformPkg/PrePi/PeiUniCore/DEBUG/ArmPlatformPrePiUniCore.dll] Error 1

build.py…
: error 7000: Failed to execute command
make tbuild [/home/sreenad/hikey960_bootloader/edk2/Build/HiKey960/DEBUG_GCC5/AARCH64/ArmPlatformPkg/PrePi/PeiUniCore]

build.py…
: error F002: Failed to build module
/home/sreenad/hikey960_bootloader/edk2/ArmPlatformPkg/PrePi/PeiUniCore.inf [AARCH64, GCC5, DEBUG]

  • Failed -
    Build end time: 23:03:35, Jun.05 2018
    Build total time: 00:00:06

                                     Hikey960 DEBUG fail

pass 0
fail 1

A lot of undefined reference to __stack_chk_guard

I tried installing clang package but same errors even after that.
I think I am missing some package or some environment issue here.

I have tried both aarch64 5.4 and 7.2 compiler. No difference.

Any clue on this?

Regards,
Sreenad.


#4

I have changed my toolchain to 7.2 from linaro and did a clean build (from beginning).
After that compilation works.

aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (Linaro GCC 7.2-2017.11) 7.2.1 20171011
Copyright © 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


#5

@sreenad Nice to hear that compilation worked at your end.


#6

I just wanted to try flashing release images using recovery mode and also using fastboot mode, before flashing my own compiled binaries.
So first I erased UFS from linux using,
dd if=/dev/zero of=/dev/sdd bs=10M count=20 (first 200M MB where I believe bootloader and boot images and partition table are flashed)

Followed a full debian OS installation document from
[https://www.96boards.org/documentation/consumer/hikey960/downloads/Debian.md.html]
Base firmware flashing in recovery mode is done using
[https://github.com/96boards-hikey/tools-images-hikey960]

sudo ./recovery-flash.sh /dev/ttyUSB1 (it is successfull)

After that, put board in to fastboot mode and did the following

$ sudo fastboot flash ptable prm_ptable.img
$ sudo fastboot flash fastboot l-loader.bin
$ sudo fastboot flash fip fip.bin
$ sudo fastboot reboot-bootloader

After reboot, it is not giving a fastboot
In serial console, I am getting,

C1R,V0x00000030 e:66
C2R,V0x00000030 e:66
C3R,V0x00000030 e:65
1244M
1866M
C0R,V0x00000016 e:66
C2R,V0x00000016 e:66
C3R,V0x00000016 e:66
C0R,V0x00000017 e:66
C1R,V0x00000017 e:66
C2R,V0x00000017 e:66
C3R,V0x00000017 e:66
iomcu_subsys_init
boot_c0 PROFILE 4
slave0 irq0:0x00000004
slave1 irq0:0x00000004
NOTICE: BL2: v1.5(release):v1.5-149-gda9d1d59
NOTICE: BL2: Built : 13:29:43, May 14 2018
ERROR: BL2: Failed to load image (-2)

Any idea what is wrong here?


#7

Hi @sreenad,

You should use recovery-uefi.sh for flashing the base firmwares. Alternatively you can take a look at the ATF doc for most up to date instructions:

Thanks,
Mani


#8

Thanks, @Mani

I compiled fip, l-loader and prm_ptable from source and after that target board is recoverd fully
Started using the following binaries after building from source.

prm_ptable.img (compiled) (before I was using prebuilt found in tools-images-hikey960)
l-loader.bin (compiled) (before I was using prebuilt obtained from debian OS installation page)
recovery.bin (compiled) (no such binary before)
fip.bin (compiled) (before I was using prebuilt obtained from debian OS installation page)

hisi-sec_xloader.img (prebuilt binary found in tools-images-hikey960)
boot-linaro-stretch-developer-hikey-20180521-18.img (prebuilt debian boot image)
rootfs-linaro-stretch-developer-hikey-20180521-18.img (prebuilt debian rootfs image)

I have one question,
if recovery-flash.sh is not needed, the below firmwares are no longer needed?

fastboot flash nvme ${IMG_FOLDER}/hisi-nvme.img
fastboot flash fw_lpm3 ${IMG_FOLDER}/hisi-lpm3.img
fastboot flash trustfirmware ${IMG_FOLDER}/hisi-bl31.bin

Regards,
Sreenad.


#9

Now I am going to compile a fip image by changing BL33= path/uboot.bin while compiling ATF.
Lets see what happens.

I think now I have to consider modifying the BL33_BASE @sumit.garg had mentioned.


#10

Hi,

I am not using an optee as mentioned in hikey960.rst
Still board boots and works fine.

Some where I read it is optional.

What is it used for?
I am curious to know.

Regards,
Sreenad.


#11

OP-TEE is Secure OS providing Trusted Execution Environment based on ARM TrustZone. Yes it is optional in boot sequence. For more info on OP-TEE please refer to https://www.op-tee.org/index.html.


#12

Were you able to port uboot for hikey960? I am happy to help as I have a similar ongoing project.


#13

@wizofe,

I was able to create a combined fip image with uboot binary and other BL binaries.

uboot binary used was same as that of hikey620’s. Atleast for a try to jump to uboot entry point i thought this was enough.

I had to switch to a high priority task in between. So now, it has been suspened from my end.

But i am very much interested to do this.
I shall also contribute if i can do something on this based on my free time.

I shall share the fip image creation steps here tomorrow, once I am in office.


How to calculate entry point (PRELOADED_BL33_BASE) address for u-boot
#14

That sounds very exciting @sreenad ! Let me know tomorow about the fip image if you are able to upload and let’s keep in touch!


#15

Hi @wizofe

Current fip building script.
File: l-loader/build_uefi.sh

    # Build ARM Trusted Firmware
    cd ${BUILD_PATH}/arm-trusted-firmware
    BL32=../optee_os/out/arm-plat-hikey/core/tee-pager.bin
    BL33=${EDK2_OUTPUT_DIR}/FV/BL33_AP_UEFI.fd
    CROSS_COMPILE=aarch64-linux-gnu- make ${TC_FLAGS} PLAT=${PLATFORM} SCP_BL2=${SCP_BL2} SPD=opteed BL32=${BL32} BL33=${BL33} DEBUG=${BUILD_DEBUG} all fip
    if [ $? != 0 ]; then
            echo "Fail to build ARM Trusted Firmware ($?)"
            exit
    fi

Taking this as reference I wrote a small script which can be executed inside ATF source directory.

BL33=/home/sreenad/u-boot-hikey/u-boot.bin
BUILD_DEBUG=1
SCP_BL2=…/OpenPlatformPkg/Platforms/Hisilicon/HiKey960/Binary/lpm3.img

make CROSS_COMPILE=aarch64-linux-gnu- PRELOADED_BL33_BASE=0x35000000 PLAT=hikey960 SCP_BL2=${SCP_BL2} BL33=${BL33} DEBUG=${BUILD_DEBUG} all fip

PRELOADED_BL33_BASE=0x35000000 is not correct.
I have not calculated the value for hikey960.
Anyways this image did not boot.

I think by properly setting the UART base address, alteast printascii wourd work.
Load uboot to memory, Jump to BL33 base is the current thing I am looking at.

Currently I am not getting time for that.
If you are getting any progress in entering to uboot startup code, please let me know.

Regards,
Sreenad.


#16

Hi,

Followed all the @sreenad steps. Able to compile ATF and create fip.bin
Not getting how to calculate entry point for u-boot.

Any ideas ?

Thanks in advance !

Thanks,
Ramappa


#17

AFAIK, u-boot is compiled with fixed base address defined by CONFIG_SYS_TEXT_BASE which should be the starting point of u-boot. You need to build ATF with PRELOADED_BL33_BASE=CONFIG_SYS_TEXT_BASE of u-boot.


#18

Hi @Ramappa @sreenad

In addition to what @sumit.garg said, you can use the address 0x1AC98000 as the base address of U-Boot (CONFIG_SYS_TEXT_BASE). This comes from NS_BL1U_BASE defined in ATF [1].

Hope this helps! Let us know how the porting goes :slight_smile:

Thanks,
Mani

[1] https://github.com/ARM-software/arm-trusted-firmware/blob/master/plat/hisilicon/hikey960/hikey960_bl2_mem_params_desc.c#L156


#19

Hi @Mani @sumit.garg

Thanks for yor reply.
I can verify these changes only after initializing UART0.

To initialize UART, following below steps

  • Need to configure master cpu (providing vin and clk).
  • Initialize the LDO for 40 pin connector
  • PinMux for UART and initialize

I assume, main CPU will be A53, need to give input voltage with BUCKs similar to Hikey620. We can use same driver 'pmic_hi6553.c" for initialization. Is it right ?

I didn’t got any proper pointers/tutors for Pinmux, please provide me if you have any docs and links.

Thanks in advance.

Thanks,
Ramappa


#20

@Ramappa,

I think, debug console UART is already initialized by the previous boot loader stages.
May be u have to find the UART TX register address for hi3660 from the linux kernel source and set it appropriately in uboot code.

Also u can verify whether jumping happens to uboot startup code by printascii kind of debugging.

At uboot entry point, in assembly, write a simple loop to send an ascii character to uart TX register.
if you are able to jump to uboot entry code u will get some prints in console.

Once you are sure that u are in uboot u can now play with it.

If you find some progress, don’t hesitate to share in community.

Regards,
Sreenad.