Skip to contentSkip to conversation

nand_fsl_nfc: get rid of local var

RFC PATCH New Heiko Schocher 2 participants 4 messages Jul 29, 2010 – Aug 3, 2010

lore
Share & tools
lore
#0 lore raw

RFC PATCH 14/19 nand_fsl_nfc: get rid of local var

If we have -fPIC enabled, this var leads in one entry in the GOT. The result of this is that the image size is > 0x800.

---
I tried to fix this in the u-boot.lds, but without success. If somebody knows, how to fix this without this patch, it would be great!

 nand_spl/nand_boot_fsl_nfc.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)
nand_spl/nand_boot_fsl_nfc.c +8 -6
index 9720f6a..0543512 100644
@@ -34,10 +34,9 @@
 #include <asm/io.h>
 #include <fsl_nfc.h>
 
-struct fsl_nfc_regs *nfc;
-
 static void nfc_wait_ready(void)
 {
+	struct fsl_nfc_regs *nfc = (void *)NFC_BASE_ADDR;
 	uint32_t tmp;
 
 	while (!(readw(&nfc->nand_flash_config2) & NFC_INT))
@@ -51,6 +50,7 @@ static void nfc_wait_ready(void)
 
 void nfc_nand_init(void)
 {
+	struct fsl_nfc_regs *nfc = (void *)NFC_BASE_ADDR;
 #if defined(MXC_NFC_V1_1)
 	int ecc_per_page  = CONFIG_SYS_NAND_PAGE_SIZE / 512;
 	int config1;
@@ -82,6 +82,7 @@ void nfc_nand_init(void)
 
 static void nfc_nand_command(unsigned short command)
 {
+	struct fsl_nfc_regs *nfc = (void *)NFC_BASE_ADDR;
 	writew(command, &nfc->flash_cmd);
 	writew(NFC_CMD, &nfc->nand_flash_config2);
 	nfc_wait_ready();
@@ -89,6 +90,7 @@ static void nfc_nand_command(unsigned short command)
 
 static void nfc_nand_page_address(unsigned int page_address)
 {
+	struct fsl_nfc_regs *nfc = (void *)NFC_BASE_ADDR;
 	unsigned int page_count;
 
 	writew(0x00, &nfc->flash_add);
@@ -122,6 +124,7 @@ static void nfc_nand_page_address(unsigned int page_address)
 
 static void nfc_nand_data_output(void)
 {
+	struct fsl_nfc_regs *nfc = (void *)NFC_BASE_ADDR;
 	int config1 = readw(&nfc->nand_flash_config1);
 #ifdef NAND_MXC_2K_MULTI_CYCLE
 	int i;
@@ -150,11 +153,13 @@ static void nfc_nand_data_output(void)
 
 static int nfc_nand_check_ecc(void)
 {
+	struct fsl_nfc_regs *nfc = (void *)NFC_BASE_ADDR;
 	return readw(&nfc->ecc_status_result);
 }
 
 static int nfc_read_page(unsigned int page_address, unsigned char *buf)
 {
+	struct fsl_nfc_regs *nfc = (void *)NFC_BASE_ADDR;
 	int i;
 	u32 *src;
 	u32 *dst;
@@ -186,6 +191,7 @@ static int nfc_read_page(unsigned int page_address, unsigned char *buf)
 
 static int is_badblock(int pagenumber)
 {
+	struct fsl_nfc_regs *nfc = (void *)NFC_BASE_ADDR;
 	int page = pagenumber;
 	u32 badblock;
 	u32 *src;
@@ -228,8 +234,6 @@ static int nand_load(unsigned int from, unsigned int size, unsigned char *buf)
 	unsigned int maxpages = CONFIG_SYS_NAND_SIZE /
 				CONFIG_SYS_NAND_PAGE_SIZE;
 
-	nfc = (void *)NFC_BASE_ADDR;
-
 	nfc_nand_init();
 
 	/* Convert to page number */
@@ -279,8 +283,6 @@ void nand_boot(void)
 {
 	__attribute__((noreturn)) void (*uboot)(void);
 
-	nfc = (void *)NFC_BASE_ADDR;
-
 	/*
 	 * CONFIG_SYS_NAND_U_BOOT_OFFS and CONFIG_SYS_NAND_U_BOOT_SIZE must
 	 * be aligned to full pages
Signature · 5 lines
1.6.2.5

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#1 lore raw

RFC PATCH 14/19 nand_fsl_nfc: get rid of local var

Quoted 4 lines · On Thu, 29 Jul 2010 12:45:03 +0200 Heiko Schocher <[email protected]> wrote:

If we have -fPIC enabled, this var leads in one entry in the GOT. The result of this is that the image size is > 0x800.

nand_spl/nand_boot_fsl_nfc.c line 39

Quoted 13 lines
nand_spl/nand_boot_fsl_nfc.c +1 -2
index 9720f6a..0543512 100644
@@ -34,10 +34,9 @@
 #include <asm/io.h>
 #include <fsl_nfc.h>
 
-struct fsl_nfc_regs *nfc;
-
 static void nfc_wait_ready(void)
 {
+	struct fsl_nfc_regs *nfc = (void *)NFC_BASE_ADDR;

Alternatively, would this work at file scope?

static struct fsl_nfc_regs *const nfc = (void *)NFC_BASE_ADDR;

-Scott

#2 lore raw

RFC PATCH 14/19 nand_fsl_nfc: get rid of local var

Hello Scott,

Quoted 26 lines · Scott Wood
Quoted 4 lines · On Thu, 29 Jul 2010 12:45:03 +0200 Heiko Schocher <[email protected]> wrote:

If we have -fPIC enabled, this var leads in one entry in the GOT. The result of this is that the image size is > 0x800.

nand_spl/nand_boot_fsl_nfc.c line 39

Quoted 13 lines
nand_spl/nand_boot_fsl_nfc.c +1 -2
index 9720f6a..0543512 100644
@@ -34,10 +34,9 @@
 #include <asm/io.h>
 #include <fsl_nfc.h>
 
-struct fsl_nfc_regs *nfc;
-
 static void nfc_wait_ready(void)
 {
+	struct fsl_nfc_regs *nfc = (void *)NFC_BASE_ADDR;

Alternatively, would this work at file scope?

Quoted 1 line

static struct fsl_nfc_regs *const nfc = (void *)NFC_BASE_ADDR;

Great tip! Thanks, this works also, I fix this in version 2

bye
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#3 lore raw

RFC PATCH v2 14/19 nand_fsl_nfc: get rid of local var

In reply to Scott Wood

If we have -fPIC enabled, this var leads in one entry in the GOT. The result of this is that the image size is > 0x800. So make it a "static const" and this brings the size again < 0x800

---

- changes since v1
add comment from Scott Wood:
- make the var nfc static const

 nand_spl/nand_boot_fsl_nfc.c |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)
nand_spl/nand_boot_fsl_nfc.c +1 -5
index 9720f6a..50d6ea9 100644
@@ -34,7 +34,7 @@
 #include <asm/io.h>
 #include <fsl_nfc.h>
 
-struct fsl_nfc_regs *nfc;
+static struct fsl_nfc_regs *const nfc = (void *)NFC_BASE_ADDR;
 
 static void nfc_wait_ready(void)
 {
@@ -228,8 +228,6 @@ static int nand_load(unsigned int from, unsigned int size, unsigned char *buf)
 	unsigned int maxpages = CONFIG_SYS_NAND_SIZE /
 				CONFIG_SYS_NAND_PAGE_SIZE;
 
-	nfc = (void *)NFC_BASE_ADDR;
-
 	nfc_nand_init();
 
 	/* Convert to page number */
@@ -279,8 +277,6 @@ void nand_boot(void)
 {
 	__attribute__((noreturn)) void (*uboot)(void);
 
-	nfc = (void *)NFC_BASE_ADDR;
-
 	/*
 	 * CONFIG_SYS_NAND_U_BOOT_OFFS and CONFIG_SYS_NAND_U_BOOT_SIZE must
 	 * be aligned to full pages
Signature · 5 lines
1.6.2.5

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany