From c31319b66934f554f6c337b4cfa888b1fb74faa4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Antonio=20V=C3=A1zquez?= Date: Sat, 21 Jan 2023 22:34:28 +0100 Subject: [PATCH] ramips: lzma-loader: Refactor loader MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Delete unused lantiq makefile * Delete redundant makefiles and unify them into the main makefile * Refactor and unify board code into a single file * Add support and review subtarget specific board support Signed-off-by: Antonio Vázquez --- target/linux/ramips/image/Makefile | 1 + .../linux/ramips/image/lzma-loader/Makefile | 4 ++ .../ramips/image/lzma-loader/src/Makefile | 25 ++++++++-- .../image/lzma-loader/src/board-mt7621.c | 39 --------------- .../image/lzma-loader/src/board-ralink.c | 42 ---------------- .../ramips/image/lzma-loader/src/board.c | 48 +++++++++++++++++++ .../ramips/image/lzma-loader/src/lantiq.mk | 1 - .../ramips/image/lzma-loader/src/mt7621.mk | 1 - .../ramips/image/lzma-loader/src/ralink.mk | 1 - 9 files changed, 75 insertions(+), 87 deletions(-) delete mode 100644 target/linux/ramips/image/lzma-loader/src/board-mt7621.c delete mode 100644 target/linux/ramips/image/lzma-loader/src/board-ralink.c create mode 100644 target/linux/ramips/image/lzma-loader/src/board.c delete mode 100644 target/linux/ramips/image/lzma-loader/src/lantiq.mk delete mode 100644 target/linux/ramips/image/lzma-loader/src/mt7621.mk delete mode 100644 target/linux/ramips/image/lzma-loader/src/ralink.mk diff --git a/target/linux/ramips/image/Makefile b/target/linux/ramips/image/Makefile index 275251ff6bf5..baa930e684c6 100644 --- a/target/linux/ramips/image/Makefile +++ b/target/linux/ramips/image/Makefile @@ -43,6 +43,7 @@ define Build/loader-common BOARD="$(BOARDNAME)" PLATFORM="$(LOADER_PLATFORM)" \ LZMA_TEXT_START=$(LZMA_TEXT_START) \ LOADADDR=$(LOADADDR) \ + SUBTARGET=$(SUBTARGET) \ $(1) compile loader.$(LOADER_TYPE) mv "$@.$(LOADER_TYPE)" "$@" rm -rf $@.src diff --git a/target/linux/ramips/image/lzma-loader/Makefile b/target/linux/ramips/image/lzma-loader/Makefile index 4cf700d8c646..7b87941e0293 100644 --- a/target/linux/ramips/image/lzma-loader/Makefile +++ b/target/linux/ramips/image/lzma-loader/Makefile @@ -18,6 +18,8 @@ FLASH_OFFS := FLASH_MAX := BOARD := PLATFORM := +SUBTARGET := +CACHE_FLAGS := -DCONFIG_CACHELINE_SIZE=32 ifeq ($(TARGET_DIR),) TARGET_DIR := $(KDIR) @@ -46,6 +48,8 @@ loader-compile: $(PKG_BUILD_DIR)/.prepared FLASH_MAX=$(FLASH_MAX) \ BOARD="$(BOARD)" \ PLATFORM="$(PLATFORM)" \ + SUBTARGET="$(SUBTARGET)" \ + CACHE_FLAGS="$(CACHE_FLAGS)" \ clean all loader.gz: $(PKG_BUILD_DIR)/loader.bin diff --git a/target/linux/ramips/image/lzma-loader/src/Makefile b/target/linux/ramips/image/lzma-loader/src/Makefile index 97fd6dad47b2..478cf17f29cb 100644 --- a/target/linux/ramips/image/lzma-loader/src/Makefile +++ b/target/linux/ramips/image/lzma-loader/src/Makefile @@ -23,6 +23,7 @@ FLASH_START := FLASH_OFFS := FLASH_MAX := PLATFORM := +SUBTARGET := CACHE_FLAGS := CC := $(CROSS_COMPILE)gcc @@ -31,8 +32,6 @@ OBJCOPY := $(CROSS_COMPILE)objcopy OBJDUMP := $(CROSS_COMPILE)objdump -include $(PLATFORM).mk - BIN_FLAGS := -O binary -R .reginfo -R .note -R .comment -R .mdebug \ -R .MIPS.abiflags -S @@ -54,7 +53,27 @@ LDFLAGS += -flto -fwhole-program -Wl,-z,max-page-size=4096 O_FORMAT = $(shell $(OBJDUMP) -i | head -2 | grep elf32) -OBJECTS := head.o loader.o cache.o board-$(PLATFORM).o printf.o LzmaDecode.o +OBJECTS := head.o loader.o cache.o board.o printf.o LzmaDecode.o + +ifeq ($(strip $(SUBTARGET)),) +$(error "Please specify a SUBTARGET!") +endif + +ifeq ($(strip $(SUBTARGET)),mt7620) +CFLAGS += -DSOC_MT7620 +endif + +ifeq ($(strip $(SUBTARGET)),mt7621) +CFLAGS += -DSOC_MT7621 +endif + +ifeq ($(strip $(SUBTARGET)),rt305x) +CFLAGS += -DSOC_RT305X +endif + +ifeq ($(strip $(SUBTARGET)),rt3883) +CFLAGS += -DSOC_RT3883 +endif ifneq ($(strip $(LOADER_DATA)),) OBJECTS += data.o diff --git a/target/linux/ramips/image/lzma-loader/src/board-mt7621.c b/target/linux/ramips/image/lzma-loader/src/board-mt7621.c deleted file mode 100644 index b90b2ed89fcf..000000000000 --- a/target/linux/ramips/image/lzma-loader/src/board-mt7621.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Arch specific code for mt7621 based boards, based on code for Ralink boards - * - * Copyright (C) 2018 Tobias Schramm - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation. - */ - -#include -#include -#include "config.h" - -#define READREG(r) *(volatile uint32_t *)(r) -#define WRITEREG(r,v) *(volatile uint32_t *)(r) = v - -#define KSEG1ADDR(_x) (((_x) & 0x1fffffff) | 0xa0000000) - -#define UART_BASE 0xBE000C00 - -#define UART_TBR_OFFSET 0x00 -#define UART_LSR_OFFSET 0x14 - -#define UART_LSR_TEMT (1 << 6) - -#define UART_READ(r) READREG(UART_BASE + (r)) -#define UART_WRITE(r,v) WRITEREG(UART_BASE + (r), (v)) - -void board_putc(int ch) -{ - while (((UART_READ(UART_LSR_OFFSET)) & UART_LSR_TEMT) == 0); - UART_WRITE(UART_TBR_OFFSET, ch); - while (((UART_READ(UART_LSR_OFFSET)) & UART_LSR_TEMT) == 0); -} - -void board_init(void) -{ -} diff --git a/target/linux/ramips/image/lzma-loader/src/board-ralink.c b/target/linux/ramips/image/lzma-loader/src/board-ralink.c deleted file mode 100644 index 7c947ec6ebe2..000000000000 --- a/target/linux/ramips/image/lzma-loader/src/board-ralink.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Arch specific code for Ralink based boards - * - * Copyright (C) 2013 John Crispin - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation. - */ - -#include -#include "config.h" - -#define READREG(r) *(volatile unsigned int *)(r) -#define WRITEREG(r,v) *(volatile unsigned int *)(r) = v - -#define KSEG1ADDR(_x) (((_x) & 0x1fffffff) | 0xa0000000) - -#ifdef CONFIG_SOC_RT288X -#define UART_BASE 0xb0300c00 -#else -#define UART_BASE 0xb0000c00 -#endif - -#define UART_TX 1 -#define UART_LSR 7 - -#define UART_LSR_THRE 0x20 - -#define UART_READ(r) READREG(UART_BASE + 4 * (r)) -#define UART_WRITE(r,v) WRITEREG(UART_BASE + 4 * (r), (v)) - -void board_putc(int ch) -{ - while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0); - UART_WRITE(UART_TX, ch); - while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0); -} - -void board_init(void) -{ -} diff --git a/target/linux/ramips/image/lzma-loader/src/board.c b/target/linux/ramips/image/lzma-loader/src/board.c new file mode 100644 index 000000000000..ae9da380738b --- /dev/null +++ b/target/linux/ramips/image/lzma-loader/src/board.c @@ -0,0 +1,48 @@ +/* + * Arch specific code for ramips based boards + * + * Copyright (C) 2013 John Crispin + * Copyright (C) 2018 Tobias Schramm + * Copyright (C) 2023 Antonio Vázquez + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + */ + +#include + +#if defined(SOC_MT7620) || defined(SOC_RT3883) +#define UART_BASE 0xb0000c00 +#define UART_THR (UART_BASE + 0x04) +#define UART_LSR (UART_BASE + 0x1c) +#define UART_LSR_THRE_MASK 0x40 +#elif defined(SOC_MT7621) +#define UART_BASE 0xbe000c00 +#define UART_THR (UART_BASE + 0x00) +#define UART_LSR (UART_BASE + 0x14) +#define UART_LSR_THRE_MASK 0x20 +#elif defined(SOC_RT305X) +#define UART_BASE 0x10000500 +#define UART_THR (UART_BASE + 0x04) +#define UART_LSR (UART_BASE + 0x1c) +#define UART_LSR_THRE_MASK 0x20 +#else +#error "Unsupported SOC..." +#endif + +// Helper functions +#define READREG(r) (*(volatile uint32_t *)(r)) +#define WRITEREG(r,v) (*(volatile uint32_t *)(r)) = v + + +void board_init(void) +{ +} + +void board_putc(int ch) +{ + while ((READREG(UART_LSR) & UART_LSR_THRE_MASK) == 0); + WRITEREG(UART_THR, ch); + while ((READREG(UART_LSR) & UART_LSR_THRE_MASK) == 0); +} diff --git a/target/linux/ramips/image/lzma-loader/src/lantiq.mk b/target/linux/ramips/image/lzma-loader/src/lantiq.mk deleted file mode 100644 index 413764593b48..000000000000 --- a/target/linux/ramips/image/lzma-loader/src/lantiq.mk +++ /dev/null @@ -1 +0,0 @@ -CACHE_FLAGS+=-DCONFIG_ICACHE_SIZE="(32 * 1024)" -DCONFIG_DCACHE_SIZE="(32 * 1024)" -DCONFIG_CACHELINE_SIZE=32 diff --git a/target/linux/ramips/image/lzma-loader/src/mt7621.mk b/target/linux/ramips/image/lzma-loader/src/mt7621.mk deleted file mode 100644 index 3ff5fddf980e..000000000000 --- a/target/linux/ramips/image/lzma-loader/src/mt7621.mk +++ /dev/null @@ -1 +0,0 @@ -CACHE_FLAGS+=-DCONFIG_ICACHE_SIZE="(32 * 1024)" -DCONFIG_DCACHE_SIZE="(16 * 1024)" -DCONFIG_CACHELINE_SIZE=32 diff --git a/target/linux/ramips/image/lzma-loader/src/ralink.mk b/target/linux/ramips/image/lzma-loader/src/ralink.mk deleted file mode 100644 index 3ff5fddf980e..000000000000 --- a/target/linux/ramips/image/lzma-loader/src/ralink.mk +++ /dev/null @@ -1 +0,0 @@ -CACHE_FLAGS+=-DCONFIG_ICACHE_SIZE="(32 * 1024)" -DCONFIG_DCACHE_SIZE="(16 * 1024)" -DCONFIG_CACHELINE_SIZE=32 -- 2.30.2