ramips: lzma-loader: Refactor loader
authorAntonio Vázquez <antoniovazquezblanco@gmail.com>
Sat, 21 Jan 2023 21:34:28 +0000 (22:34 +0100)
committerHauke Mehrtens <hauke@hauke-m.de>
Sat, 29 Apr 2023 20:32:27 +0000 (22:32 +0200)
* 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 <antoniovazquezblanco@gmail.com>
target/linux/ramips/image/Makefile
target/linux/ramips/image/lzma-loader/Makefile
target/linux/ramips/image/lzma-loader/src/Makefile
target/linux/ramips/image/lzma-loader/src/board-mt7621.c [deleted file]
target/linux/ramips/image/lzma-loader/src/board-ralink.c [deleted file]
target/linux/ramips/image/lzma-loader/src/board.c [new file with mode: 0644]
target/linux/ramips/image/lzma-loader/src/lantiq.mk [deleted file]
target/linux/ramips/image/lzma-loader/src/mt7621.mk [deleted file]
target/linux/ramips/image/lzma-loader/src/ralink.mk [deleted file]

index 275251ff6bf50d6b86d7abd9cb8733f0aa0f4973..baa930e684c63ebde8f14e60b104d50c16455b8f 100644 (file)
@@ -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
index 4cf700d8c6463b4f2e7094409b793f8a8f5a0b03..7b87941e0293024d5bb9c6b19411dc3fce0bd987 100644 (file)
@@ -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
index 97fd6dad47b27180499a71ea3a84a5037c84a729..478cf17f29cb9c52b9d3255d33d85bf1fba1d01d 100644 (file)
@@ -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 (file)
index b90b2ed..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Arch specific code for mt7621 based boards, based on code for Ralink boards
- *
- * Copyright (C) 2018 Tobias Schramm <tobleminer@gmail.com>
- *
- * 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 <stddef.h>
-#include <stdint.h>
-#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 (file)
index 7c947ec..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Arch specific code for Ralink based boards
- *
- * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
- *
- * 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 <stddef.h>
-#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 (file)
index 0000000..ae9da38
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Arch specific code for ramips based boards
+ *
+ * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
+ * Copyright (C) 2018 Tobias Schramm <tobleminer@gmail.com>
+ * Copyright (C) 2023 Antonio Vázquez <antoniovazquezblanco@gmail.com>
+ *
+ * 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 <stdint.h>
+
+#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 (file)
index 4137645..0000000
+++ /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 (file)
index 3ff5fdd..0000000
+++ /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 (file)
index 3ff5fdd..0000000
+++ /dev/null
@@ -1 +0,0 @@
-CACHE_FLAGS+=-DCONFIG_ICACHE_SIZE="(32 * 1024)" -DCONFIG_DCACHE_SIZE="(16 * 1024)" -DCONFIG_CACHELINE_SIZE=32