Re: FreeBSD-13.0-CURRENT on Baikal-m(aarch64) SoC

From: Andrew Turner <andrew_at_fubar.geek.nz>
Date: Wed, 25 Aug 2021 10:51:14 UTC

> On 25 Aug 2021, at 09:34, Sleep Walker <s199p.wa1k9r@gmail.com> wrote:
> 
> Hi!
> 
> I am trying to add support for the new SoC Baikal-M in FreeBSD.
> https://www.baikalelectronics.com/products/338/
> https://www.cnx-software.com/2021/08/10/desktop-and-all-in-one-arm-linux-computers-launched-with-baikal-m-processor/
> 
> The system is already starting in multi-user mode, but only one core out of
> eight is detected.
> To find out the reason, I slightly changed the code by adding the output of
> the error code.
> sys/arm64/arm64/mp_machdep.c
> -------------------------------------------------------------------------------------------------------------------------
>        printf("Starting CPU %u (%lx)\n", cpuid, target_cpu);
>        pa = pmap_extract(kernel_pmap, (vm_offset_t)mpentry);
>        err = psci_cpu_on(target_cpu, pa, cpuid);
> 
>        if (err != PSCI_RETVAL_SUCCESS) {
>                printf("Starting CPU %u (%lx) psci_cpu_on return (%d)\n",
> cpuid, target_cpu, err);
>                /*
>                 * Panic here if INVARIANTS are enabled and PSCI failed to
>                 * start the requested CPU.  psci_cpu_on() returns
> PSCI_MISSING
>                 * to indicate we are unable to use it to start the given
> CPU.
>                 */
>                KASSERT(err == PSCI_MISSING ||
>                    (mp_quirks & MP_QUIRK_CPULIST) == MP_QUIRK_CPULIST,
>                    ("Failed to start CPU %u (%lx), error %d\n",
>                    cpuid, target_cpu, err));
>                pcpu_destroy(pcpup);
>                kmem_free((vm_offset_t)dpcpu[cpuid - 1], DPCPU_SIZE);
>                dpcpu[cpuid - 1] = NULL;
>                kmem_free((vm_offset_t)bootstacks[cpuid], PAGE_SIZE);
>                bootstacks[cpuid] = NULL;
>                mp_ncpus--;
>                return (false);
>        }
> --------------------------------------------------------------------------------------------------------------------------
> I got the following log
> ---------------------------------
> Starting CPU 1 (1)
> Starting psci_cpu_on(1, f22008c8, 1)
> Starting CPU 1 (1) psci_cpu_on return (-9)
> Starting CPU 1 (100)
> Starting psci_cpu_on(100, f22008c8, 1)
> Starting CPU 1 (100) psci_cpu_on return (-9)
> Starting CPU 1 (101)
> ......
> ----------------------------------

The firmware thinks this address is invalid. From the version of the Trusted Firmware-A I found it checks if the address is within one of the three DRAM banks and not within the secure region. These two checks should pass. It then tries to read the fdt memory node and check if the address is within one of the regions it provides. It can also file if it is unable to read this node, or the entry point is not within one of the memory regions the node describes.

Are you able to get a dump of the /memory@80000000 node from the firmware? e.g. from loader.efi the following commands should work (assuming it’s passed into loader by the firmware):

fdt cd /memory@80000000
fdt prop

Andrew