Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Initial Platform support for Altera Cyclonev SoC #7266

Closed
wants to merge 1 commit into from

Conversation

rajeshrah22
Copy link

Modified code from Zynq7k platform port.

ARM Cortex A9 armv7.

OP-TEE successfully initializes and jumps to NS world.

Summary of changes:

  • Changed UART driver to a compatible one.
  • Removed writes to SLCR_TZ registers, which don't exist on cyclonev.
  • Initally unlocked all security rules in the L3 interconnect TrustZone Firewall.
  • Override init_sec_mon to provide dt blob address and linux jump address in respective registers. (Hardcoded for now).

Problems:

  • does not work with CFG_WITH_PAGER yet.
  • Have not tried to enable dual core (boot secondary).

Boot flow:
SPL --> U-boot --> optee -> Linux

Integrating with Linux:

  • Kernel panics with what we think is an un-handled page fault when initializing optee driver.
    This occurs when allocating a memory pool (Probably for the shared memory region). We will need to go over the
    device tree modifications that added optee firmware node and reserved memory nodes.
  • Linux sometimes does not boot (no console logs) after jump from NS world for a reason we are still investigating.

Any guiding questions regarding the issues above would be appreciated. Would love feedback on the plat-cyclonev code as well.

thanks,
Rahul

Modified code from Zynq7k platform.

ARM Cortex A9 armv7.

Summary of changes:
- Changed UART driver to a compatible one.
- Removed writes to SLCR_TZ registers, which don't exist on cyclonev.
- Initally unlocked all security rules in the L3 interconnect TrustZone
  Firewall.
- Override init_sec_mon to provide dt blob address and linux jump
  address in respective registers.

Signed-off-by: Rahul Rajesh <rajeshrah22@gmail.com>
* TA_RAM : all what is left (at least 2MByte !)
*/

#define TZDRAM_BASE 0x3fd00000
Copy link
Author

@rajeshrah22 rajeshrah22 Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes for the platform_config.h file are at the bottom when CFG_WITH_PAGER is disabled. I have changed the TZDRAM_BASE only compared to the zynq7k code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that TZDRAM_BASE + TEE_RAM_PH_SIZE + TA_RAM_SIZE + TEE_SHMEM_START in this configuration would go over physical address 0x40000000, which is over the total RAM on the system. Need to fix this.

@rajeshrah22 rajeshrah22 changed the title Initial Platform support for Altera Cyclonev SoC [RFC] Initial Platform support for Altera Cyclonev SoC Feb 6, 2025
@jenswi-linaro
Copy link
Contributor

Paging in emulated SRAM is only needed to test the pager on hardware to ensure it works with platforms that use real SRAM. So, unless you plan to use real SRAM with the pager, you can remove that part to save some work.

You could try $(call force,CFG_CORE_RESERVED_SHM,n) to disable the reserved shared memory pool and rely on dynamic shared memory only.

@rajeshrah22
Copy link
Author

Paging in emulated SRAM is only needed to test the pager on hardware to ensure it works with platforms that use real SRAM. So, unless you plan to use real SRAM with the pager, you can remove that part to save some work.

So, in other words, I don't need the CFG_WITH_PAGER config if I don't intend to use SRAM?

@rajeshrah22
Copy link
Author

You could try $(call force,CFG_CORE_RESERVED_SHM,n) to disable the reserved shared memory pool and rely on dynamic shared memory only.

This seemed to have let the driver initalize:

[    3.197548] optee: probing for conduit method.
I/TC: Reserved shared memory is disabled
I/TC: Dynamic shared memory is enabled
I/TC: Normal World virtualization support is disabled
I/TC: Asynchronous notifications are disabled
[    3.202071] optee: revision 4.5 (a9dfe07f)
[    3.219208] optee: dynamic shared memory is enabled
D/TC:0 0 alloc_l2_table:336 L2 tables used 3
D/TC:? 0 tee_ta_init_pseudo_ta_session:303 Lookup pseudo TA 7011a688-ddde-4053-a5a9-7b3c4ddf13b8
D/TC:? 0 tee_ta_init_pseudo_ta_session:315 Open device.pta
D/TC:? 0 tee_ta_init_pseudo_ta_session:330 device.pta : 7011a688-ddde-4053-a5a9-7b3c4ddf13b8
D/TC:? 0 tee_ta_close_session:460 csess 0x3fc78150 id 1
D/TC:? 0 tee_ta_close_session:479 Destroy session
[    3.265318] optee: initialized driver

@rajeshrah22
Copy link
Author

I just got this exception. This might be an issue with us turning off SMP with nosmp kernel command line arg.

[    3.369584] Loading compiled-in X.509 certificates
[    3.380221]  mmcblk0: p1 p2 p3
[    3.383521] zswap: loaded using pool lzo/zbud
[   28.012815] watchdog: BUG: soft lockup - CPU#0 stuck for 26s! [migration/0:15]
[   28.020041] Modules linked in:
[   28.023102] CPU: 0 PID: 15 Comm: migration/0 Not tainted 6.2.11-ARCH #2
[   28.029703] Hardware name: Altera SOCFPGA
[   28.033702] Stopper: multi_cpu_stop+0x0/0x128 <- stop_machine_cpuslocked+0x10c/0x174
[   28.041458] PC is at rcu_preempt_need_deferred_qs+0x30/0x4c
[   28.047047] LR is at rcu_preempt_need_deferred_qs+0x14/0x4c
[   28.052615] pc : [<c03c8524>]    lr : [<c03c8508>]    psr: 60000013
[   28.058861] sp : f0869f08  ip : f0869f08  fp : 20000013
[   28.064069] r10: 00000000  r9 : 00000001  r8 : c1c0b058
[   28.069276] r7 : 00000001  r6 : f0831e24  r5 : 00000001  r4 : c20c5e80
[   28.075778] r3 : 00000000  r2 : 2dbcf000  r1 : c181194c  r0 : 00000000
[   28.082282] Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment none
[   28.089396] Control: 10c5787d  Table: 0020404a  DAC: 00000051
[   28.095129]  rcu_preempt_need_deferred_qs from rcu_momentary_dyntick_idle+0x68/0xbc
[   28.102786]  rcu_momentary_dyntick_idle from multi_cpu_stop+0xe0/0x128
[   28.109312]  multi_cpu_stop from cpu_stopper_thread+0x80/0x120
[   28.115144]  cpu_stopper_thread from smpboot_thread_fn+0x164/0x23c
[   28.121341]  smpboot_thread_fn from kthread+0xe8/0x118
[   28.126483]  kthread from ret_from_fork+0x14/0x2c
[   28.131182] Exception stack(0xf0869fb0 to 0xf0869ff8)
[   28.136222] 9fa0:                                     00000000 00000000 00000000 00000000
[   28.144372] 9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[   28.152519] 9fe0: 00000000 00000000 00000000 00000000 00000013 00000000

@rajeshrah22
Copy link
Author

This issue we were having with the kernel hanging after jumping out of OP-TEE to NS world was that it was stuck at cpu_v7_do_idle after initial call to the scheduler on kernel_init.

So, I thought it might have something to do with timer interrupts not being recieved, which could have been an issue with GIC being configured incorrectly.

In the above run, I also changed to

register_phys_mem_pgdir(MEM_AREA_IO_NSEC, GIC_BASE, SMALL_PAGE_SIZE);

from MEM_AREA_IO_SEC. Not sure if this was the correct move, and I am unsure what exactly register_phys_mem_pgdir does.

@rajeshrah22
Copy link
Author

I changed it back to

register_phys_mem_pgdir(MEM_AREA_IO_SEC, GIC_BASE, SMALL_PAGE_SIZE);

We still need to investigate the reason for linux being stuck in idle sometimes. This time it worked.

Log:

[    3.374103] Loading compiled-in X.509 certificates
[    3.384831]  mmcblk0: p1 p2 p3
[    3.388013] zswap: loaded using pool lzo/zbud
[    3.407645] Key type .fscrypt registered
[    3.411677] Key type fscrypt-provisioning registered
[    3.424967] Btrfs loaded, crc32c=crc32c-generic, zoned=yes, fsverity=yes
[    3.456428] dma-pl330 ffe01000.pdma: Loaded driver for PL330 DMAC-341330
[    3.463196] dma-pl330 ffe01000.pdma:         DBUFF-512x8bytes Num_Chans-8 Num_Peri-32 Num_Events-8
[    3.478110] input: gpio-keys as /devices/platform/gpio-keys/input/input0
[    3.485996] ALSA device list:
[    3.488980]   No soundcards found.
[    3.492727] dw-apb-uart ffc02000.serial: forbid DMA for kernel console
[    3.514902] EXT4-fs (mmcblk0p2): mounted filesystem 8506577b-d36a-422c-933e-9acbd5f1b217 with ordered data mode. Quota mode: none.
[    3.527081] usb 1-1: New USB device found, idVendor=0424, idProduct=2512, bcdDevice= b.b3
[    3.535349] usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[    3.542639] VFS: Mounted root (ext4 filesystem) on device 179:2.
[    3.549771] hub 1-1:1.0: USB hub found
[    3.554049] hub 1-1:1.0: 2 ports detected
[    3.559532] devtmpfs: mounted
[    3.565581] Freeing unused kernel image (initmem) memory: 2048K
[    3.572612] Run /sbin/init as init process
[    4.197688] systemd[1]: System time before build time, advancing clock.
[    4.336544] systemd[1]: systemd 253-1-arch running in system mode (+PAM +AUDIT -SELINUX -APPARMOR -IMA +SMACK +SECCOMP +GCRYPT +GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBFDISK +PCRE2 -PWQUALITY +P11KIT -QRENCODE +TPM2 +BZIP2 +LZ4 +XZ +ZLIB +ZSTD +BPF_FRAMEWORK +XKBCOMMON +UTMP -SYSVINIT default-hierarchy=unified)
[    4.368961] systemd[1]: Detected architecture arm.

Welcome to Arch Linux ARM!

@jenswi-linaro
Copy link
Contributor

Paging in emulated SRAM is only needed to test the pager on hardware to ensure it works with platforms that use real SRAM. So, unless you plan to use real SRAM with the pager, you can remove that part to save some work.

So, in other words, I don't need the CFG_WITH_PAGER config if I don't intend to use SRAM?

Correct.

Copy link

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

@github-actions github-actions bot added the Stale label Mar 13, 2025
@github-actions github-actions bot closed this Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants