From: Marek Vasut Date: Thu, 15 Nov 2018 15:42:03 +0100 Subject: [U-Boot] confusion about CONFIG_SYS_TEXT_BASE and gd->relocaddr In-Reply-To: <20181115093345.7C6F94D8@webmail.sinamail.sina.com.cn> References: <20181115093345.7C6F94D8@webmail.sinamail.sina.com.cn> Message-ID: <0e6b37b3-9f5a-5a85-08c8-41e9dc216d0d@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit To: u-boot@lists.denx.de On 11/15/2018 10:33 AM, tamzikin at sina.com wrote: > Hi Marek, Hi, CC the list next time. >     I am Kin, nice to meet you, I know you because I saw your u-boot > video on Youtube. >     I am a learner of u-boot, and I have a big confusion on it, so I > would like to find answer from you. >      >     For compiling, some platform have CONFIG_SYS_TEXT_BASE set to some > value, and CONFIG_SYS_TEXT_BASE will be used when linking all sections > into one u-boot, so it can be said that the address of the first > instruction in u-boot will be bound to address CONFIG_SYS_TEXT_BASE, and > every variable and function will also be bound to address based on > CONFIG_SYS_TEXT_BASE. Yes, that's the link address. >     Before relocation, gd->relocaddr is calculated, and if gd->relocaddr > doesn't equal to CONFIG_SYS_TEXT_BASE, u-boot is relocated to > gd->relocaddr but not CONFIG_SYS_TEXT_BASE. Right, U-Boot gets relocated to the end of RAM , so it's out of the way. >     Since all the functions and variables are bound to address based on > CONFIG_SYS_TEXT_BASE during compilation, so if we don't locate u-boot to > CONFIG_SYS_TEXT_BASE, u-boot cannot reach functions and variable correctly. Take a look at relocate_code function and search for R_ARM_REL32 for example, it should give you an idea how that relocation stuff works and how the function pointers get adjusted to match the binary location. >     But this is actually how u-boot is designed, so I am confused, could > you give me any hint for that? >     Thanks. > -- Best regards, Marek Vasut