From nobody Sat Dec 24 00:48:57 2022 X-Original-To: freebsd-arm@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Nf55z2b1Zz1H2bX for ; Sat, 24 Dec 2022 00:49:11 +0000 (UTC) (envelope-from hiroo.ono@gmail.com) Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Nf55y1Yq4z3Gk6 for ; Sat, 24 Dec 2022 00:49:10 +0000 (UTC) (envelope-from hiroo.ono@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20210112 header.b=aiSOop0M; spf=pass (mx1.freebsd.org: domain of hiroo.ono@gmail.com designates 2607:f8b0:4864:20::102e as permitted sender) smtp.mailfrom=hiroo.ono@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pj1-x102e.google.com with SMTP id c8-20020a17090a4d0800b00225c3614161so2953345pjg.5 for ; Fri, 23 Dec 2022 16:49:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=m4sbKfepo/kRXQdeXYMf6i9Mn5unKF7LMqiWThnvW9E=; b=aiSOop0MgmK0NPDpvMSBt2U2LXCK9SP7sPvtzwEXYHIP4jJ+ynAa6W1Jh3uMNLyXvu KTQEzn28n57ZHbRbJ/4DQrox5MDCh6Nx6SkPW/SGhm/It/4w/F/lWcmkIBDvBBmnZRS5 CUd6YjaeQKVmz9qd95pQd2EzOiKstiO+Z3bkArypqq9Ffa4UN5GHPxXGZzL3gaAihExR S8fDKNJmqVw8vBg/lUV+ZGXvPFRR0rZkvdZPzxIZu+RB3mXCQmZwWH10xxVdRd7zwP06 bIfiAZ1rQnRwSE+56kAcTlYjr+7BLqwUv292oKBwV4N17rfN5VtVJAYt4mvgzSXLw5Jx TFDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=m4sbKfepo/kRXQdeXYMf6i9Mn5unKF7LMqiWThnvW9E=; b=Nv6AqY6HnGw+So1ytIcp8ORdGHkh++nEH8rrqA8+/U868JiKbNLzpDxJZpKLnspuTp Iywkcs1DOu7nGaIKUIa/bNQPsd8GiG+HXDvIIgtwgyAVWP/M5SriY6RjQYGhUhVe/pLp 87lE2wrnv0KiYKt1jQU+Oyo/pf/oeLHJE/nbj53TwrP0MHwB2l2RkYSNoNpFYhF2M91n Rg/R5YLNZg0MPp2tpnHrk1LgeSe6XBr3JAfhHSTO19v7Oiid0Cs8448kwvRI+486j2UF uUJUWGkbT3LFs7szG7kTrylZzV4zSfoS/zKwc2eqQVAH0YNIm6ueDS6OI/tYaxEo67vA adoQ== X-Gm-Message-State: AFqh2krPvB/hrAjlwJNjqFs8zVwNecAKTYk/uvZ7qYUpKeZ9iy0gzgnf ZGv+8tWHUSQuE0g1x9tDPPAJ/kfC7Ji4/H7x+fk= X-Google-Smtp-Source: AMrXdXv/LXD2XaqOE0HyAaUdH6UysPyKJx1qhR8bZnZ4xER5l5WQ1EfiH8428of84NSoMo6M/qVFTlGZ72caRSt7qfs= X-Received: by 2002:a17:90a:d50c:b0:219:8b1b:bcfa with SMTP id t12-20020a17090ad50c00b002198b1bbcfamr1063077pju.235.1671842948623; Fri, 23 Dec 2022 16:49:08 -0800 (PST) List-Id: Porting FreeBSD to ARM processors List-Archive: https://lists.freebsd.org/archives/freebsd-arm List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-arm@freebsd.org MIME-Version: 1.0 References: In-Reply-To: Reply-To: hiroo.ono+freebsd@gmail.com From: =?UTF-8?B?SGlyb28gT25vICjlsI/ph47lr5vnlJ8p?= Date: Sat, 24 Dec 2022 09:48:57 +0900 Message-ID: Subject: Re: Still did not succeed to boot on Lenovo Yoga C630 To: Warner Losh Cc: Mark Millard , freebsd-arm@freebsd.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-3.74 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.996]; NEURAL_HAM_LONG(-0.75)[-0.748]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20210112]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; MIME_GOOD(-0.10)[text/plain]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; HAS_REPLYTO(0.00)[hiroo.ono+freebsd@gmail.com]; FREEMAIL_REPLYTO(0.00)[gmail.com]; MLMMJ_DEST(0.00)[freebsd-arm@freebsd.org]; PREVIOUSLY_DELIVERED(0.00)[freebsd-arm@freebsd.org]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::102e:from]; TO_MATCH_ENVRCPT_SOME(0.00)[]; ARC_NA(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; RCVD_COUNT_TWO(0.00)[2]; REPLYTO_ADDR_EQ_FROM(0.00)[]; MID_RHS_MATCH_FROMTLD(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[]; RCVD_TLS_LAST(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; MIME_TRACE(0.00)[0:+]; TAGGED_FROM(0.00)[freebsd]; FROM_EQ_ENVFROM(0.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FREEMAIL_ENVFROM(0.00)[gmail.com]; FREEMAIL_CC(0.00)[yahoo.com,freebsd.org] X-Rspamd-Queue-Id: 4Nf55y1Yq4z3Gk6 X-Spamd-Bar: --- X-ThisMailContainsUnwantedMimeParts: N The current status of FreeBSD 14-current on Lenovo Yoga C630 is as follows: 1) Merging from OpenBSD's loader code made the loader boot apart from 3 points (#2 to 4 ). 2) when comconsole->c_init() runs the 2nd time, it seems to freeze. (might be C630 specific) 3) SetVirtualAddressMap() in efi_do_vmap() freezes. (might also affect other snapdragon systems like Microsoft Arm Developer Kit) 4) The kernel is kicked but does not start. 1) is quite straightforward. What needs to be changed is stand/efi/loader/arch/arm64/start.S. For 2), I do not know what to do. Currently, I commented out comconsole from struct console *consoles[] in stand/efi/loader/conf.c as a workaround. Maybe, I should write a fault handler that helps returning from the fault. 3), I dumped each memory map's VirtualStart and PhysicalStart. All VirtualStart were 0. So overwriting VirutalStart by the value of PhysicalStart and running SetVirtualAddressMap should work. But in reality, it doesn't. OpenBSD does not use SetVirtualAddress for arm64 and Linux seems to have abandoned it for arm64 in 2019. https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id= =3D4e46c2a956215482418d7b315749fb1b6c6bc224 Maybe, we also can avoid SetVirtualAddressMap (by efi_disable_vmap=3D"YES"). In this case, (as you wrote) I should change the kernel to treat VA=3D=3DPA if VirtualStart is 0. (OpenBSD seems to do so). About 4), I am completely confused. In elf64_exec in stand/efi/loader/arch/arm64/exec.c, the memory address that the kernel was loaded is calculated as: entry =3D efi_translate(ehdr->e_entry); // which becomes 0xb340000 and later kicked as: (*entry)(modulep); I wrote that this calculation is doubtful, but it was right. I dumped the data at the address 0xb340000 and compared it with the output of objdump -D loader_lua.syms. It turned out that it matched with the kernel's _start code in locore.S. Putting some code that jumps to loader's ImageBase address at the start of kernel's _start did not change anything, so I judged that the kernel is not started at all. The excerpt of the loader's memmap command output is as follows: Type Physical Virtual #Pages Attr LoaderData 0000b33ea000 000000000000 00000000 UC WC WT WB WP RP XP LoaderCode 0000bb909000 000000000000 000000d1 UC WC WT WB WP RP XP >From this output, I wonder if the memory attributes on Yoga C630 is properly implemented, but as XP (exec protect) bit is on, I tried to set it off by DXE services' SetMemoryAttributes() (with a lot of transcription from the standards...).It succeeded, but the kernel still did not run. >From this tweet: https://twitter.com/canadianbryan/status/1598053941270679552 and its replies, the Microsoft Arm Developer Kit seems to have similar problem, so if somebody succeeded to run FreeBSD on it, please share the information how to do it. 2022=E5=B9=B412=E6=9C=8819=E6=97=A5(=E6=9C=88) 5:33 Warner Losh : > > > > On Sun, Dec 18, 2022 at 4:31 AM Hiroo Ono (=E5=B0=8F=E9=87=8E=E5=AF=9B=E7= =94=9F) wrote: >> >> Hello, >> >> I investigated a little more. >> I thought it was the kernel that did not run, but still it did not get >> through the loader. > > > Keep at it... > >> >> The loader freezed in efi_do_vmap(), so I needed to add >> efi_disable_vmap=3D"YES" in loader.conf. > > > No. The code for this needs to be fixed... More on that in a second... > >> >> At last, in elf64_exec, it tried to run (*entry)(modulep) where the >> address entry is calculated from ehdr->e_entry by efi_translate() in >> stand/efi/loader/copy.c. There, >> ehdr->e_entry was 0xffff000000020000 (should be 0xffff000000000800, >> but I modified a little) and >> stage_offset was 0x10000b33e0000. >> The sum of two which efi_translate() returns is 0x100000000b3400000. >> It overflows uint64_t and becomes 0xb3400000. > > > Yea, I think this is wrong. > >> >> Currently, I do not understand well what the functions in >> stand/efi/loader/copy.c do, and do not know how to workaround this >> problem. > > > So there's two things going on here. First is that on arm64 we should *NE= VER* copy the > kernel. It loads at a specific address and we jump to where it loaded in = RAM (in your case, > I think it should be stage_offset + (ehdr->e_entry - KERNBASE). Kernbase = is 0xffff000000000000 > so we should jump to 0x10000brre0000 + 0x20000 (or maybe 0x800 is you sug= gest). The kernel > code that's there should do some tricks to find out where it was loaded, = turn on the MMU and > then jump to the VA to continue starting up the kernel. The arm64 kernel = is linked with a VA. Old amd64 > kernels expected to start at a fixed physical address, but the UEFI spec = allows memory to be mapped anywhere > which means it was recently switched to create a page table in the boot l= oader, then jump to the right > VA, and use the page table to find what PA that is and use that to bootst= rap the pmap. This works great on > amd64, but sometimes goes astray on arm64 (though the way it does for you= doesn't make sense > to me). The amd64 code used to start at a PA, and that's what the 'copy' = routine is supposed to do: > copy the kernel down that fixed address and jump to it. I don't think we'= ll ever want that on arm64, though, > and that might also be getting in your way (thought I'm doing this from m= emory w/o careful study of > the code because it's fresh in my mind due to getting arm64 working with = linuxboot). > > Also, vmap *MUST* be called in the boot loader. The trouble is, it assume= s VA =3D=3D PA, but that's not > strictly true. If you boot via LinuxBoot, for example, it has a memory ma= pping that's not VA =3D=3D PA so > at least some parts of the kernel fail their VA =3D=3D PA asserts. the vm= ap code in the loader currently > blindly assumes VA =3D=3D PA, but it should, IMHO, only do that if the VA= from entry from the table from > the get memory map call is 0. Today it blindly overwrites it. You might t= ry changing that, and removing > the bit in the kernel that checks for VA =3D=3D PA and bails out if there= 's a mismatch. Here's the patch I'm > temporarily using until I have the time to do more than a quick, superfic= ial analysis of the issue: > > diff --git a/sys/arm64/arm64/efirt_machdep.c b/sys/arm64/arm64/efirt_mach= dep.c > index 727c9c37f94d..075174d164d8 100644 > --- a/sys/arm64/arm64/efirt_machdep.c > +++ b/sys/arm64/arm64/efirt_machdep.c > @@ -193,8 +193,8 @@ efi_create_1t1_map(struct efi_md *map, int ndesc, int= descsz) > continue; > if (p->md_virt !=3D 0 && p->md_virt !=3D p->md_phys) { > if (bootverbose) > - printf("EFI Runtime entry %d is mapped\n"= , i); > - goto fail; > + printf("EFI Runtime entry %d is mapped PA= %#lx VA %#lx\n", i, p->md_phys, p->md_virt); > +// goto fail; > } > if ((p->md_phys & EFI_PAGE_MASK) !=3D 0) { > if (bootverbose) > > clearly, not suitable for upstreaming, eh? And I have about 2 dozen commi= ts in my queue ahead of that > one that need refinement, review and upstreaming before I jump into this = issue. It will be after the first > of the year at least before I'll look at it since I just started my year-= end vacation... > > Warner > >> >> 2022=E5=B9=B412=E6=9C=889=E6=97=A5(=E9=87=91) 9:25 Hiroo Ono (=E5=B0=8F= =E9=87=8E=E5=AF=9B=E7=94=9F) : >> > >> > 2022=E5=B9=B412=E6=9C=889=E6=97=A5(=E9=87=91) 3:19 Warner Losh : >> > > >> > > >> > > >> > > On Wed, Dec 7, 2022 at 4:21 PM Hiroo Ono (=E5=B0=8F=E9=87=8E=E5=AF= =9B=E7=94=9F) wrote: >> > >> >> > >> 2022=E5=B9=B412=E6=9C=887=E6=97=A5(=E6=B0=B4) 1:18 Warner Losh : >> > >> > >> > >> > >> > >> > >> > >> > On Tue, Dec 6, 2022 at 7:59 AM Hiroo Ono (=E5=B0=8F=E9=87=8E=E5= =AF=9B=E7=94=9F) wrote: >> > >> >> > >> >> OK, I (and the subject) was wrong. The loader boots, and show >> > >> >> following log at last: >> > >> >> >> > >> >> Loading kernel... >> > >> >> /boot/kernel/kernel text=3D0x2a8 text=3D0x8bcbf0 text=3D0x1f97ac >> > >> >> data=3D0x1a6ac0 data=3D0x0+0x381000 syms=3D[0x8+0x11f6a0+0x8+0x1= 439ea] >> > >> >> Loading configured modules... >> > >> >> can't find '/boot/entropy' >> > >> >> can't find '/etc/hostid' >> > >> >> No valid device tree blob found! >> > >> >> WARNING! Trying to fire up the kernel, but no device tree blob f= ound! >> > >> >> EFI framebuffer information >> > >> >> addr, size 0x80400000, 0x7e9000 >> > >> >> dimensions 1920 x 1080 >> > >> >> stride 1920 >> > >> >> masks 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 >> > >> >> >> > >> >> and it stops here. No "<>" line is displayed. >> > >> >> So, it seems that the kernel is loaded but could not be started. >> > >> > >> > >> > >> > >> > There are several causes of this. >> > >> > >> > >> > Most likely is that the console is setup to go somewhere else. Th= ough if you are on the video display and getting that framebuffer output, i= t won't not go there w/o some setting to override (say to force serial). >> > >> >> > >> In the loader, when comconsole->c_init() is called for the second >> > >> time, the function does not return. (I commented out comconsole to >> > >> make the loader work, but it is rather brutal and is not a proper >> > >> solution). >> > >> But the function parse_uefi_con_out() in stand/efi/loader/main.c >> > >> always returns RB_SERIAL, so the loader tries to use the serial >> > >> console. >> > > >> > > >> > > I wonder why that is. Is this -current or -stable? I have a rather l= arge backlog of MFC-able loader changes. If it is with stable, then it make= s sense: I fixed a bug where parse_uefi_con_out would return serial if '8be= 4df61-93ca-11d2-aa0d-00e098032b8c-ConOut' was unset. Is it set? Now we ret= urn Video console if we fine evidence there's a video console. >> > >> > It is stable/13. >> > I tried 14-current, and the same change to loader was needed (merging >> > OpenBSD's start.S and ldscript.arm64, and commenting out comconsole). >> > Even with these change, the console defaults to serial, so I changed >> > parse_uefi_con_out() to always return 0. >> > Still, it stops at the same point. The kernel does not seem to boot. >> > >> > Running efi-show from the loader prompt did not show >> > '8be4df61-93ca-11d2-aa0d-00e098032b8c-ConOut' >> > The variable name containing 'ConOut' were: >> > >> > global NV,BS,RS ConOut =3D >> > VenHw(9042A9DE-23DC-4A38-96FB-7ADED080516A),/VenHw(857A8741-0EEC-43BD-= 0482-27D14ED47D72)/Uart(115200,8,N,1) >> > global NV,BS,RS ConOutDev =3D >> > VenHw(9042A9DE-23DC-4A38-96FB-7ADED080516A),/VenHw(857A8741-0EEC-43BD-= 0482-27D14ED47D72)/Uart(115200,8,N,1) >> > >> > > Now, why it fails the second time, I don't know. >> > > >> > >> >> > >> If a similar thing happens with the kernel, it may be stopping at >> > >> serial console initialization. >> > > >> > > >> > > The kernel doesn't use the EFI routines to initialize the serial con= sole. But if the kernel is being told the wrong console, then it could also= be booting just fine or almost fine and hitting some bug later. >> > > >> > >> >> > >> > Next most likely is that FreeBSD doesn't cope well with having bo= th FDT and ACPI information available. But since not DTB is being passed in= (per that message) that's not likely at play here. >> > >> >> > >> I managed to load the dtb file and the boot process stopped at the >> > >> same point. The problem is not here? >> > > >> > > >> > > Yea, I don't think so. >> > > >> > > Warner >> > > >> > >> >> > >> > Finally, the loader passes a large number of tables, etc to the k= ernel. It's quite possible that, for reasons still unknown, that data is wr= ong or if standard conforming not expected by the kernel. this leads to a c= rash before we've setup the console in the kernel which looks a lot like a = hang. >> > >> > >> > >> > Warner >> > >> > >> > >> > >> > >> >> >> > >> >> > . . . >> > >> >> > >> > >> >> > Such also happens for stable/13, releng/13.* based installatio= ns >> > >> >> > as well --and likely others too. >> > >> >> > >> > >> >> > ACPI booting does not use Device Tree information but the mess= ages >> > >> >> > are output anyway about the lack. Only if you know that the co= ntext >> > >> >> > is a Device Tree style of boot are the messages actually repor= ting >> > >> >> > a problem. >> > >> >> > >> > >> >> > >> > >> >> > =3D=3D=3D >> > >> >> > Mark Millard >> > >> >> > marklmi at yahoo.com >> > >> >> > >> > >> >>