Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98D93C433EF for ; Fri, 21 Jan 2022 03:16:54 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 62D3483845; Fri, 21 Jan 2022 04:16:52 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="gRhZr+aR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8F128837FB; Fri, 21 Jan 2022 04:16:50 +0100 (CET) Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D301883845 for ; Fri, 21 Jan 2022 04:16:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mr.bossman075@gmail.com Received: by mail-qv1-xf2e.google.com with SMTP id g11so2960609qvu.3 for ; Thu, 20 Jan 2022 19:16:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=bSd+BNUM5m9CXxAZXXVif5z46bxCgPCkILW3FRYh6u4=; b=gRhZr+aRS5shoTyOT/rleneMCrl+3dhFdKFm+7KntfV4RJSqGxQZhGFqpJUG8Zsc/E 6I3KJu/QmMl7vKSx/BStPlIIzpZkwtR5S58iCuEUw0DqUX3EHfTc9Sw296GzQ9PwIFNT fHQhpNa0+1GNmH/5rH7GXaOCsvdtdo+oeeTEF265cxvyykQ9SxsowNGBWwxIc2STOAF8 TKFMKO8Rd9cwP68xqGpsANd/Q+WNS4Rkf4C6+yQfbhTk0RDDB1h2DeSVlTn+WgFUEeRs oD3k4/+9m9Gb5t+zBIKEo+iRLn21JuouvaJsEenVUi8Ybk+eP8MxmwvjBcZDFjqHYslC HpMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=bSd+BNUM5m9CXxAZXXVif5z46bxCgPCkILW3FRYh6u4=; b=fg6i5UFiuZdl/HId9uMApcivUBD3AZf1Uqey6V6ZuBIkdvJU/LVgqrrKj/Sy5ahiHt 8fNDfn3Jg2Del+XDliLJ63NgH+69EALzmQjSQZX8DMkkRyEJQldj8foS4sfGNdheuudH Gt1rz+8flu8rEs7KzK8m6voX24JHBhFghu8Fllqe9EmET3yFwoS9jqXo9cJyziffXBpv 1kX3emHW5H94tbcY0OHz0azdri4NnH+E7fAjbT+jW/PWgXQ1f0gyMCv3htI6xKvBtUMN zFuD8q5fSvJYbqSBv9r5vw0Y46+57YMkdCMPZDS4aTdIlxwPtZ9e7BVWm0DnSgj8Fw/G dt1w== X-Gm-Message-State: AOAM531mWq8CXdZRquPPpRw4y3ANI9c2okUaE0zou9aX3YAdiMnIoxS4 7CuZq6dD9Bw59+3P92Np/3Y= X-Google-Smtp-Source: ABdhPJxWYt3imWftwxv5+8I4aYhr7pizSugodHFBoyd6TjcJMbPBSpKLVz1TrSXHmYNUO00Cl3AbPw== X-Received: by 2002:a05:6214:f25:: with SMTP id iw5mr2051562qvb.72.1642735004332; Thu, 20 Jan 2022 19:16:44 -0800 (PST) Received: from [10.4.10.38] (146-115-144-188.s4282.c3-0.nwt-cbr1.sbo-nwt.ma.cable.rcncustomer.com. [146.115.144.188]) by smtp.gmail.com with ESMTPSA id d11sm2330928qte.78.2022.01.20.19.16.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Jan 2022 19:16:44 -0800 (PST) Message-ID: <05738dea-c01c-63fa-fa4c-f697ae7f6093@gmail.com> Date: Thu, 20 Jan 2022 22:16:41 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH 02/11] arm: arm926ej-s: add sunxi code Content-Language: en-US To: Andre Przywara Cc: u-boot@lists.denx.de, jagan@amarulasolutions.com, hdegoede@redhat.com, sjg@chromium.org, icenowy@aosc.io, marek.behun@nic.cz, festevam@denx.de, narmstrong@baylibre.com, tharvey@gateworks.com, christianshewitt@gmail.com, pbrobinson@gmail.com, jernej.skrabec@gmail.com, hs@denx.de, samuel@sholland.org, arnaud.ferraris@gmail.com, giulio.benetti@benettiengineering.com, thirtythreeforty@gmail.com, Chris Morgan References: <20220105003508.1143140-1-Mr.Bossman075@gmail.com> <20220105003508.1143140-3-Mr.Bossman075@gmail.com> <20220121022518.3eef356e@slackpad.fritz.box> From: Jesse Taube In-Reply-To: <20220121022518.3eef356e@slackpad.fritz.box> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean On 1/20/22 21:25, Andre Przywara wrote: > On Tue, 4 Jan 2022 19:34:59 -0500 > Jesse Taube wrote: > > Hi, > >> From: Icenowy Zheng >> >> Some Allwinner SoCs use ARM926EJ-S core. >> >> Add Allwinner/sunXi specific code to ARM926EJ-S CPU dircetory. >> >> Signed-off-by: Icenowy Zheng >> Signed-off-by: Jesse Taube >> --- >> arch/arm/cpu/arm926ejs/Makefile | 1 + >> arch/arm/cpu/arm926ejs/sunxi/Makefile | 15 +++ >> arch/arm/cpu/arm926ejs/sunxi/config.mk | 6 + >> arch/arm/cpu/arm926ejs/sunxi/fel_utils.S | 37 ++++++ >> arch/arm/cpu/arm926ejs/sunxi/lowlevel_init.S | 67 +++++++++++ >> arch/arm/cpu/arm926ejs/sunxi/start.c | 1 + >> arch/arm/cpu/arm926ejs/sunxi/timer.c | 114 +++++++++++++++++++ >> arch/arm/cpu/arm926ejs/sunxi/u-boot-spl.lds | 62 ++++++++++ >> 8 files changed, 303 insertions(+) >> create mode 100644 arch/arm/cpu/arm926ejs/sunxi/Makefile >> create mode 100644 arch/arm/cpu/arm926ejs/sunxi/config.mk >> create mode 100644 arch/arm/cpu/arm926ejs/sunxi/fel_utils.S >> create mode 100644 arch/arm/cpu/arm926ejs/sunxi/lowlevel_init.S >> create mode 100644 arch/arm/cpu/arm926ejs/sunxi/start.c >> create mode 100644 arch/arm/cpu/arm926ejs/sunxi/timer.c >> create mode 100644 arch/arm/cpu/arm926ejs/sunxi/u-boot-spl.lds >> >> diff --git a/arch/arm/cpu/arm926ejs/Makefile b/arch/arm/cpu/arm926ejs/Makefile >> index b901b7c5c9..7f1436d76e 100644 >> --- a/arch/arm/cpu/arm926ejs/Makefile >> +++ b/arch/arm/cpu/arm926ejs/Makefile >> @@ -15,6 +15,7 @@ endif >> obj-$(CONFIG_MX27) += mx27/ >> obj-$(if $(filter mxs,$(SOC)),y) += mxs/ >> obj-$(if $(filter spear,$(SOC)),y) += spear/ >> +obj-$(CONFIG_ARCH_SUNXI) += sunxi/ >> >> # some files can only build in ARM or THUMB2, not THUMB1 >> >> diff --git a/arch/arm/cpu/arm926ejs/sunxi/Makefile b/arch/arm/cpu/arm926ejs/sunxi/Makefile >> new file mode 100644 >> index 0000000000..894c461c50 >> --- /dev/null >> +++ b/arch/arm/cpu/arm926ejs/sunxi/Makefile >> @@ -0,0 +1,15 @@ >> +# SPDX-License-Identifier: GPL-2.0+ >> +# >> +# (C) Copyright 2012 Henrik Nordstrom >> +# >> +# Based on some other Makefile >> +# (C) Copyright 2000-2003 >> +# Wolfgang Denk, DENX Software Engineering, wd@denx.de. > > Please remove this heritage. I appreciate the effort to give credit, > but for a trivial Makefile stub (which even differs significantly) this > is surely overkill. > Just one line with some current copyright should be enough. > Fixed. >> + >> +obj-y += timer.o >> +obj-y += lowlevel_init.o >> + >> +ifdef CONFIG_SPL_BUILD >> +obj-y += fel_utils.o >> +CFLAGS_fel_utils.o := -marm >> +endif >> diff --git a/arch/arm/cpu/arm926ejs/sunxi/config.mk b/arch/arm/cpu/arm926ejs/sunxi/config.mk >> new file mode 100644 >> index 0000000000..76ffec9df6 >> --- /dev/null >> +++ b/arch/arm/cpu/arm926ejs/sunxi/config.mk >> @@ -0,0 +1,6 @@ >> +# Build a combined spl + u-boot image >> +ifdef CONFIG_SPL >> +ifndef CONFIG_SPL_BUILD >> +ALL-y += u-boot-sunxi-with-spl.bin >> +endif >> +endif >> diff --git a/arch/arm/cpu/arm926ejs/sunxi/fel_utils.S b/arch/arm/cpu/arm926ejs/sunxi/fel_utils.S >> new file mode 100644 >> index 0000000000..0997a2dc65 >> --- /dev/null >> +++ b/arch/arm/cpu/arm926ejs/sunxi/fel_utils.S >> @@ -0,0 +1,37 @@ >> +/* SPDX-License-Identifier: GPL-2.0+ */ >> +/* >> + * Utility functions for FEL mode. >> + * >> + * Copyright (c) 2015 Google, Inc >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> + >> +ENTRY(save_boot_params) >> + ldr r0, =fel_stash >> + str sp, [r0, #0] >> + str lr, [r0, #4] >> + mrs lr, cpsr @ Read CPSR >> + str lr, [r0, #8] >> + mrc p15, 0, lr, c1, c0, 0 @ Read CP15 SCTLR Register >> + str lr, [r0, #12] >> + mrc p15, 0, lr, c1, c0, 0 @ Read CP15 Control Register >> + str lr, [r0, #16] > > This is the very same register twice, also written to the wrong offset. > Please remove the last two lines. > Yes, this is a bug in armv7/sunxi/fel_utils.S as well, I will send a > fix. Please CC me. > >> + b save_boot_params_ret >> +ENDPROC(save_boot_params) >> + >> +ENTRY(return_to_fel) >> + mov sp, r0 >> + mov lr, r1 >> + ldr r0, =fel_stash >> + ldr r1, [r0, #16] >> + mcr p15, 0, r1, c1, c0, 0 @ Write CP15 Control Register > > Same here, those two lines can be removed. > >> + ldr r1, [r0, #12] >> + mcr p15, 0, r1, c1, c0, 0 @ Write CP15 SCTLR Register >> + ldr r1, [r0, #8] >> + msr cpsr, r1 @ Write CPSR >> + bx lr >> +ENDPROC(return_to_fel) >> diff --git a/arch/arm/cpu/arm926ejs/sunxi/lowlevel_init.S b/arch/arm/cpu/arm926ejs/sunxi/lowlevel_init.S >> new file mode 100644 >> index 0000000000..db09bcc4d0 >> --- /dev/null >> +++ b/arch/arm/cpu/arm926ejs/sunxi/lowlevel_init.S >> @@ -0,0 +1,67 @@ >> +/* SPDX-License-Identifier: GPL-2.0+ */ >> +/* >> + * A lowlevel_init function that sets up the stack to call a C function to >> + * perform further init. >> + * >> + * Based on lowlevel_init.S in armv7 directory, which is: >> + * (C) Copyright 2010 Texas Instruments, >> + */ >> + >> +#include >> +#include >> +#include >> + >> +.pushsection .text.s_init, "ax" >> +WEAK(s_init) >> + bx lr >> +ENDPROC(s_init) >> +.popsection > > I would say we don't need this weak stub. In contrast to armv7, we are > the only user of this file, and s_init should be provided by > arch/arm/mach-sunxi/board.c. > > In general the toplevel README seems to deprecate lowlevel_init, but > this probably needs some fixing in the other sunxi code first. I removed it its defined in board like you said. >> + >> +.pushsection .text.lowlevel_init, "ax" >> +WEAK(lowlevel_init) >> + /* >> + * Setup a temporary stack. Global data is not available yet. >> + */ >> +#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK) >> + ldr sp, =CONFIG_SPL_STACK >> +#else >> + ldr sp, =CONFIG_SYS_INIT_SP_ADDR >> +#endif >> + bic sp, sp, #7 /* 8-byte alignment for ABI compliance */ >> +#ifdef CONFIG_SPL_DM >> + mov r9, #0 >> +#else > > We probably don't need this SPL_DM part? Hmmmmm you are right im assuiming this got copied from somewhere. I replaced the ifdef with `mov r9, #0`. > >> + /* >> + * Set up global data for boards that still need it. This will be >> + * removed soon. >> + */ >> +#ifdef CONFIG_SPL_BUILD >> + ldr r9, =gdata >> +#else >> + sub sp, sp, #GD_SIZE >> + bic sp, sp, #7 >> + mov r9, sp >> +#endif >> +#endif >> + /* >> + * Save the old lr(passed in ip) and the current lr to stack >> + */ >> + push {ip, lr} >> + >> + /* >> + * Call the very early init function. This should do only the >> + * absolute bare minimum to get started. It should not: >> + * >> + * - set up DRAM >> + * - use global_data >> + * - clear BSS >> + * - try to start a console >> + * >> + * For boards with SPL this should be empty since SPL can do all of >> + * this init in the SPL board_init_f() function which is called >> + * immediately after this. >> + */ > > Yeah, this (copied) comments seems to suggest we are somewhat off here. > But I think we rely on board.c:s_init() too much to easily remove this. > > So for the sake of not blocking this I am willing to keep this part for > now. Much apretiated! > >> + bl s_init >> + pop {ip, pc} >> +ENDPROC(lowlevel_init) >> +.popsection >> diff --git a/arch/arm/cpu/arm926ejs/sunxi/start.c b/arch/arm/cpu/arm926ejs/sunxi/start.c >> new file mode 100644 >> index 0000000000..6b392fa835 >> --- /dev/null >> +++ b/arch/arm/cpu/arm926ejs/sunxi/start.c >> @@ -0,0 +1 @@ >> +/* Intentionally empty. Only needed to get FEL SPL link line right */ >> diff --git a/arch/arm/cpu/arm926ejs/sunxi/timer.c b/arch/arm/cpu/arm926ejs/sunxi/timer.c >> new file mode 100644 >> index 0000000000..e624174581 >> --- /dev/null >> +++ b/arch/arm/cpu/arm926ejs/sunxi/timer.c > > I don't see immediately why the original file lives in > arch/arm/cpu/armv7/sunxi/timer.c. Can we move that to > arch/arm/mach-sunxi or board/sunxi, then just not compile it for arm64? > Because otherwise this looks identical to its donor, minus some smaller > (but good) cleanups. > So I'm curious if we can move and then reuse the original file. I will try thanks for the pointer. > >> @@ -0,0 +1,114 @@ >> +// SPDX-License-Identifier: (GPL-2.0+) >> +/* >> + * (C) Copyright 2007-2011 >> + * Allwinner Technology Co., Ltd. >> + * Tom Cubie >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> + >> +DECLARE_GLOBAL_DATA_PTR; >> + >> +#define TIMER_MODE (0x0 << 7) /* continuous mode */ >> +#define TIMER_DIV (0x0 << 4) /* pre scale 1 */ >> +#define TIMER_SRC (0x1 << 2) /* osc24m */ >> +#define TIMER_RELOAD (0x1 << 1) /* reload internal value */ >> +#define TIMER_EN (0x1 << 0) /* enable timer */ >> + >> +#define TIMER_CLOCK (24 * 1000 * 1000) >> +#define COUNT_TO_USEC(x) ((x) / 24) >> +#define USEC_TO_COUNT(x) ((x) * 24) >> +#define TICKS_PER_HZ (TIMER_CLOCK / CONFIG_SYS_HZ) >> +#define TICKS_TO_HZ(x) ((x) / TICKS_PER_HZ) >> + >> +#define TIMER_LOAD_VAL 0xffffffff >> + >> +#define TIMER_NUM 0 /* we use timer 0 */ >> + >> +/* read the 32-bit timer */ >> +static ulong read_timer(void) >> +{ >> + struct sunxi_timer_reg *timers = >> + (struct sunxi_timer_reg *)SUNXI_TIMER_BASE; >> + struct sunxi_timer *timer = &timers->timer[TIMER_NUM]; >> + >> + /* >> + * The hardware timer counts down, therefore we invert to >> + * produce an incrementing timer. >> + */ >> + return ~readl(&timer->val); >> +} >> + >> +/* init timer register */ >> +int timer_init(void) >> +{ >> + struct sunxi_timer_reg *timers = >> + (struct sunxi_timer_reg *)SUNXI_TIMER_BASE; >> + struct sunxi_timer *timer = &timers->timer[TIMER_NUM]; >> + >> + writel(TIMER_LOAD_VAL, &timer->inter); >> + writel(TIMER_MODE | TIMER_DIV | TIMER_SRC | TIMER_RELOAD | TIMER_EN, >> + &timer->ctl); >> + >> + return 0; >> +} >> + >> +ulong get_timer_masked(void) > > Any reason you lost the static here? No, presumibly becuse it got changed sence 2018. > >> +{ >> + /* current tick value */ >> + ulong now = TICKS_TO_HZ(read_timer()); >> + >> + if (now >= gd->arch.lastinc) { /* normal (non rollover) */ >> + gd->arch.tbl += (now - gd->arch.lastinc); >> + } else { >> + /* rollover */ >> + gd->arch.tbl += (TICKS_TO_HZ(TIMER_LOAD_VAL) >> + - gd->arch.lastinc) + now; >> + } >> + gd->arch.lastinc = now; >> + >> + return gd->arch.tbl; >> +} >> + >> +/* timer without interrupts */ >> +ulong get_timer(ulong base) >> +{ >> + return get_timer_masked() - base; >> +} >> + >> +/* delay x useconds */ >> +void __udelay(unsigned long usec) >> +{ >> + long tmo = USEC_TO_COUNT(usec); >> + ulong now, last = read_timer(); >> + >> + while (tmo > 0) { >> + now = read_timer(); >> + if (now > last) /* normal (non rollover) */ >> + tmo -= now - last; >> + else /* rollover */ >> + tmo -= TIMER_LOAD_VAL - last + now; >> + last = now; >> + } >> +} >> + >> +/* >> + * This function is derived from PowerPC code (read timebase as long long). >> + * On ARM it just returns the timer value. >> + */ >> +unsigned long long get_ticks(void) >> +{ >> + return get_timer(0); >> +} >> + >> +/* >> + * This function is derived from PowerPC code (timebase clock frequency). >> + * On ARM it returns the number of timer ticks per second. >> + */ >> +ulong get_tbclk(void) >> +{ >> + return CONFIG_SYS_HZ; >> +} >> diff --git a/arch/arm/cpu/arm926ejs/sunxi/u-boot-spl.lds b/arch/arm/cpu/arm926ejs/sunxi/u-boot-spl.lds >> new file mode 100644 >> index 0000000000..048aab788a >> --- /dev/null >> +++ b/arch/arm/cpu/arm926ejs/sunxi/u-boot-spl.lds >> @@ -0,0 +1,62 @@ >> +/* SPDX-License-Identifier: GPL-2.0+ */ >> +/* >> + * (C) Copyright 2018 >> + * Icenowy Zheng >> + * >> + * Based on arch/arm/cpu/armv7/sunxi/u-boot-spl.lds: >> + * >> + * (C) Copyright 2012 >> + * Allwinner Technology Co., Ltd. >> + * Tom Cubie >> + * > > I think that's enough history at this point ... LOL I'll fix this, I think Icenowy wanted to make licencing clear. > >> + * Based on omap-common/u-boot-spl.lds: >> + * >> + * (C) Copyright 2002 >> + * Gary Jennejohn, DENX Software Engineering, >> + * >> + * (C) Copyright 2010 >> + * Texas Instruments, >> + * Aneesh V >> + */ >> +MEMORY { .sram : ORIGIN = CONFIG_SPL_TEXT_BASE,\ >> + LENGTH = CONFIG_SPL_MAX_SIZE } >> +MEMORY { .sdram : ORIGIN = CONFIG_SPL_BSS_START_ADDR, \ >> + LENGTH = CONFIG_SPL_BSS_MAX_SIZE } >> + >> +OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") >> +OUTPUT_ARCH(arm) >> +ENTRY(_start) >> +SECTIONS >> +{ >> + .text : >> + { >> + __start = .; >> + *(.vectors) >> + arch/arm/cpu/arm926ejs/start.o (.text) > > Do we actually need this, if it's empty? Isn't that file just to > satisfy the needs of the generic linker scripts? > Nope I droped it and the file. I'm impresesd with how fast you reviewd this one thanks for the feedback. You don't have to review patch 6 unless its okay that dram isnt using device tree, I think it should use it so thats on my todo list. Thanks, Jesse Taube > Cheers, > Andre. > >> + *(.text*) >> + } > .sram >> + >> + . = ALIGN(4); >> + .rodata : { *(SORT_BY_ALIGNMENT(.rodata*)) } >.sram >> + >> + . = ALIGN(4); >> + .data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram >> + >> + . = ALIGN(4); >> + .u_boot_list : { >> + KEEP(*(SORT(.u_boot_list*))); >> + } > .sram >> + >> + . = ALIGN(4); >> + __image_copy_end = .; >> + _end = .; >> + >> + .bss : >> + { >> + . = ALIGN(4); >> + __bss_start = .; >> + *(.bss*) >> + . = ALIGN(4); >> + __bss_end = .; >> + } > .sdram >> +} >