diff mbox series

[1/3] ramips: lzma-loader: make FLASH_START configurable

Message ID 20200902062231.2238353-2-gch981213@gmail.com
State Accepted
Delegated to: Chuanhong Guo
Headers show
Series ramips: fix OKLI lzma-loader | expand

Commit Message

Chuanhong Guo Sept. 2, 2020, 6:22 a.m. UTC
FLASH_START is supposed to point at the memory area where NOR flash are
mapped. We currently have an incorrect FLASH_START copied from ar71xx
back then and the loader doesn't work under OKLI mode.
On ramips, mt7621 has it's flash mapped to 0x1fc00000 and other SoCs
uses 0x1c000000. This commit makes FLASH_START a configurable value to
handle both cases.

Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
---
 target/linux/ramips/image/lzma-loader/Makefile     | 2 ++
 target/linux/ramips/image/lzma-loader/src/Makefile | 5 +++++
 target/linux/ramips/image/lzma-loader/src/loader.c | 5 +----
 3 files changed, 8 insertions(+), 4 deletions(-)

Comments

Adrian Schmutzler Sept. 2, 2020, 5:03 p.m. UTC | #1
Hi,

> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-bounces@lists.openwrt.org]
> On Behalf Of Chuanhong Guo
> Sent: Mittwoch, 2. September 2020 08:22
> To: openwrt-devel@lists.openwrt.org
> Cc: Chuanhong Guo <gch981213@gmail.com>
> Subject: [PATCH 1/3] ramips: lzma-loader: make FLASH_START configurable
> 
> FLASH_START is supposed to point at the memory area where NOR flash are
> mapped. We currently have an incorrect FLASH_START copied from ar71xx
> back then and the loader doesn't work under OKLI mode.
> On ramips, mt7621 has it's flash mapped to 0x1fc00000 and other SoCs uses
> 0x1c000000. This commit makes FLASH_START a configurable value to handle
> both cases.
> 
> Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
> ---
>  target/linux/ramips/image/lzma-loader/Makefile     | 2 ++
>  target/linux/ramips/image/lzma-loader/src/Makefile | 5 +++++
> target/linux/ramips/image/lzma-loader/src/loader.c | 5 +----
>  3 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/target/linux/ramips/image/lzma-loader/Makefile
> b/target/linux/ramips/image/lzma-loader/Makefile
> index f22151c9d7..4cf700d8c6 100644
> --- a/target/linux/ramips/image/lzma-loader/Makefile
> +++ b/target/linux/ramips/image/lzma-loader/Makefile
> @@ -13,6 +13,7 @@ LOADER		:= loader.bin
>  LOADER_NAME	:= $(basename $(notdir $(LOADER)))
>  LOADER_DATA 	:=
>  TARGET_DIR	:=
> +FLASH_START	:=
>  FLASH_OFFS	:=
>  FLASH_MAX	:=
>  BOARD		:=
> @@ -40,6 +41,7 @@ loader-compile: $(PKG_BUILD_DIR)/.prepared
>  	$(MAKE) -C $(PKG_BUILD_DIR)
> CROSS_COMPILE="$(TARGET_CROSS)" \
>  		LZMA_TEXT_START=$(LZMA_TEXT_START) \
>  		LOADER_DATA=$(LOADER_DATA) \
> +		FLASH_START=$(FLASH_START) \
>  		FLASH_OFFS=$(FLASH_OFFS) \
>  		FLASH_MAX=$(FLASH_MAX) \
>  		BOARD="$(BOARD)" \
> diff --git a/target/linux/ramips/image/lzma-loader/src/Makefile
> b/target/linux/ramips/image/lzma-loader/src/Makefile
> index d20cd77346..97fd6dad47 100644
> --- a/target/linux/ramips/image/lzma-loader/src/Makefile
> +++ b/target/linux/ramips/image/lzma-loader/src/Makefile
> @@ -19,6 +19,7 @@ LOADADDR	:=
>  LZMA_TEXT_START	:= 0x80a00000
>  LOADER_DATA	:=
>  BOARD		:=
> +FLASH_START	:=
>  FLASH_OFFS	:=
>  FLASH_MAX	:=
>  PLATFORM	:=
> @@ -64,6 +65,10 @@ ifneq ($(strip $(KERNEL_CMDLINE)),)
>  CFLAGS		+= -
> DCONFIG_KERNEL_CMDLINE='"$(KERNEL_CMDLINE)"'
>  endif
> 
> +ifneq ($(strip $(FLASH_START)),)
> +CFLAGS		+= -DCONFIG_FLASH_START=$(FLASH_START)
> +endif
> +
>  ifneq ($(strip $(FLASH_OFFS)),)
>  CFLAGS		+= -DCONFIG_FLASH_OFFS=$(FLASH_OFFS)
>  endif
> diff --git a/target/linux/ramips/image/lzma-loader/src/loader.c
> b/target/linux/ramips/image/lzma-loader/src/loader.c
> index c73b60b351..a3513eccf1 100644
> --- a/target/linux/ramips/image/lzma-loader/src/loader.c
> +++ b/target/linux/ramips/image/lzma-loader/src/loader.c
> @@ -28,9 +28,6 @@
>  #include "printf.h"
>  #include "LzmaDecode.h"
> 
> -#define AR71XX_FLASH_START	0x1f000000
> -#define AR71XX_FLASH_END	0x1fe00000
> -

Am I understanding this right, that if FLASH_START is not defined and set in ramips/image/Makefile, then compilation will fail here as the CONFIG_FLASH_START symbol is not defined?

Best

Adrian

>  #define KSEG0			0x80000000
>  #define KSEG1			0xa0000000
> 
> @@ -178,7 +175,7 @@ static void lzma_init_data(void)
>  	unsigned long kernel_ofs;
>  	unsigned long kernel_size;
> 
> -	flash_base = (unsigned char *) KSEG1ADDR(AR71XX_FLASH_START);
> +	flash_base = (unsigned char *) KSEG1ADDR(CONFIG_FLASH_START);
> 
>  	printf("Looking for OpenWrt image... ");
> 
> --
> 2.26.2
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Chuanhong Guo Sept. 3, 2020, 1:22 a.m. UTC | #2
Hi!

On Thu, Sep 3, 2020 at 1:03 AM Adrian Schmutzler
<mail@adrianschmutzler.de> wrote:
> > --- a/target/linux/ramips/image/lzma-loader/src/loader.c
> > +++ b/target/linux/ramips/image/lzma-loader/src/loader.c
> > @@ -28,9 +28,6 @@
> >  #include "printf.h"
> >  #include "LzmaDecode.h"
> >
> > -#define AR71XX_FLASH_START   0x1f000000
> > -#define AR71XX_FLASH_END     0x1fe00000
> > -
>
> Am I understanding this right, that if FLASH_START is not defined and set in ramips/image/Makefile, then compilation will fail here as the CONFIG_FLASH_START symbol is not defined?

That's my intention. It'll actually fail...

> >  #define KSEG0                        0x80000000
> >  #define KSEG1                        0xa0000000
> >
> > @@ -178,7 +175,7 @@ static void lzma_init_data(void)
> >       unsigned long kernel_ofs;
> >       unsigned long kernel_size;
> >
> > -     flash_base = (unsigned char *) KSEG1ADDR(AR71XX_FLASH_START);
> > +     flash_base = (unsigned char *) KSEG1ADDR(CONFIG_FLASH_START);

...here. It'll fail if CONFIG_FLASH_START isn't defined and no lzma
blob is provided.
diff mbox series

Patch

diff --git a/target/linux/ramips/image/lzma-loader/Makefile b/target/linux/ramips/image/lzma-loader/Makefile
index f22151c9d7..4cf700d8c6 100644
--- a/target/linux/ramips/image/lzma-loader/Makefile
+++ b/target/linux/ramips/image/lzma-loader/Makefile
@@ -13,6 +13,7 @@  LOADER		:= loader.bin
 LOADER_NAME	:= $(basename $(notdir $(LOADER)))
 LOADER_DATA 	:=
 TARGET_DIR	:=
+FLASH_START	:=
 FLASH_OFFS	:=
 FLASH_MAX	:=
 BOARD		:=
@@ -40,6 +41,7 @@  loader-compile: $(PKG_BUILD_DIR)/.prepared
 	$(MAKE) -C $(PKG_BUILD_DIR) CROSS_COMPILE="$(TARGET_CROSS)" \
 		LZMA_TEXT_START=$(LZMA_TEXT_START) \
 		LOADER_DATA=$(LOADER_DATA) \
+		FLASH_START=$(FLASH_START) \
 		FLASH_OFFS=$(FLASH_OFFS) \
 		FLASH_MAX=$(FLASH_MAX) \
 		BOARD="$(BOARD)" \
diff --git a/target/linux/ramips/image/lzma-loader/src/Makefile b/target/linux/ramips/image/lzma-loader/src/Makefile
index d20cd77346..97fd6dad47 100644
--- a/target/linux/ramips/image/lzma-loader/src/Makefile
+++ b/target/linux/ramips/image/lzma-loader/src/Makefile
@@ -19,6 +19,7 @@  LOADADDR	:=
 LZMA_TEXT_START	:= 0x80a00000
 LOADER_DATA	:=
 BOARD		:=
+FLASH_START	:=
 FLASH_OFFS	:=
 FLASH_MAX	:=
 PLATFORM	:=
@@ -64,6 +65,10 @@  ifneq ($(strip $(KERNEL_CMDLINE)),)
 CFLAGS		+= -DCONFIG_KERNEL_CMDLINE='"$(KERNEL_CMDLINE)"'
 endif
 
+ifneq ($(strip $(FLASH_START)),)
+CFLAGS		+= -DCONFIG_FLASH_START=$(FLASH_START)
+endif
+
 ifneq ($(strip $(FLASH_OFFS)),)
 CFLAGS		+= -DCONFIG_FLASH_OFFS=$(FLASH_OFFS)
 endif
diff --git a/target/linux/ramips/image/lzma-loader/src/loader.c b/target/linux/ramips/image/lzma-loader/src/loader.c
index c73b60b351..a3513eccf1 100644
--- a/target/linux/ramips/image/lzma-loader/src/loader.c
+++ b/target/linux/ramips/image/lzma-loader/src/loader.c
@@ -28,9 +28,6 @@ 
 #include "printf.h"
 #include "LzmaDecode.h"
 
-#define AR71XX_FLASH_START	0x1f000000
-#define AR71XX_FLASH_END	0x1fe00000
-
 #define KSEG0			0x80000000
 #define KSEG1			0xa0000000
 
@@ -178,7 +175,7 @@  static void lzma_init_data(void)
 	unsigned long kernel_ofs;
 	unsigned long kernel_size;
 
-	flash_base = (unsigned char *) KSEG1ADDR(AR71XX_FLASH_START);
+	flash_base = (unsigned char *) KSEG1ADDR(CONFIG_FLASH_START);
 
 	printf("Looking for OpenWrt image... ");