Commit 1e284547 authored by hmz007's avatar hmz007

[u-boot] merge commit 'd4a47fad474d..ec031c85e905'

Signed-off-by: 's avatarhmz007 <hmz007@gmail.com>
parent a1eaab7f
......@@ -649,6 +649,10 @@ int rkimage_handleDownload(unsigned char *buffer,
#define FDT_PATH "rk-kernel.dtb"
static const char* get_fdt_name(void)
{
char *name = getenv("dtb_name");
if (name)
return name;
if (!gBootInfo.fdt_name[0]) {
return FDT_PATH;
}
......
......@@ -11,12 +11,18 @@
#include <fdtdec.h>
#include <fdt_support.h>
#include <power/pmic.h>
#include <u-boot/sha256.h>
#include <hash.h>
#include <asm/io.h>
#include <asm/arch/rkplat.h>
#include "../common/config.h"
#ifndef BIT
#define BIT(nr) (1UL << (nr))
#endif
DECLARE_GLOBAL_DATA_PTR;
int __weak rkclk_set_apll_high(void)
......@@ -78,6 +84,15 @@ u32 get_board_rev(void)
return pcb_rev;
}
static void set_dtb_name(void)
{
char info[64] = {0, };
snprintf(info, ARRAY_SIZE(info),
"rk3399-nanopi4-rev%02x.dtb", get_board_rev());
setenv("dtb_name", info);
}
/* PWM0/GPIO4_C2 */
static int panel_pwm_status = 0;
......@@ -117,6 +132,145 @@ char *board_get_panel_name(void)
}
/* RK3399 eFuse */
#define RK3399_A_SHIFT 16
#define RK3399_A_MASK 0x3ff
#define RK3399_NFUSES 32
#define RK3399_BYTES_PER_FUSE 4
#define RK3399_STROBSFTSEL BIT(9)
#define RK3399_RSB BIT(7)
#define RK3399_PD BIT(5)
#define RK3399_PGENB BIT(3)
#define RK3399_LOAD BIT(2)
#define RK3399_STROBE BIT(1)
#define RK3399_CSB BIT(0)
#define RK3399_CPUID_OFF 0x7
#define RK3399_CPUID_LEN 0x10
static int rk3399_efuse_read(unsigned long base, int offset,
void *buf, int size)
{
void *ctrl_reg = (uint32 *)base;
void *dout_reg = (uint32 *)(base + 4);
unsigned int addr_start, addr_end, addr_offset;
u32 addr;
u32 out_value;
u8 bytes[RK3399_NFUSES * RK3399_BYTES_PER_FUSE];
int i = 0;
addr_start = offset / RK3399_BYTES_PER_FUSE;
addr_offset = offset % RK3399_BYTES_PER_FUSE;
addr_end = DIV_ROUND_UP(offset + size, RK3399_BYTES_PER_FUSE);
/* cap to the size of the efuse block */
if (addr_end > RK3399_NFUSES)
addr_end = RK3399_NFUSES;
writel(RK3399_LOAD | RK3399_PGENB | RK3399_STROBSFTSEL | RK3399_RSB,
ctrl_reg);
udelay(1);
for (addr = addr_start; addr < addr_end; addr++) {
setbits_le32(ctrl_reg,
RK3399_STROBE | (addr << RK3399_A_SHIFT));
udelay(1);
out_value = readl(dout_reg);
clrbits_le32(ctrl_reg, RK3399_STROBE);
udelay(1);
memcpy(&bytes[i], &out_value, RK3399_BYTES_PER_FUSE);
i += RK3399_BYTES_PER_FUSE;
}
/* Switch to standby mode */
writel(RK3399_PD | RK3399_CSB, ctrl_reg);
memcpy(buf, bytes + addr_offset, size);
return 0;
}
static void setup_serial(void)
{
u8 cpuid[RK3399_CPUID_LEN];
u8 low[RK3399_CPUID_LEN/2], high[RK3399_CPUID_LEN/2];
char cpuid_str[RK3399_CPUID_LEN * 2 + 1];
u64 serialno;
char serialno_str[16];
char *env_cpuid, *env_serial;
int i;
env_cpuid = getenv("cpuid#");
env_serial = getenv("serial#");
if (env_cpuid && env_serial)
return;
rk3399_efuse_read(RKIO_FTEFUSE_BASE, RK3399_CPUID_OFF, cpuid, sizeof(cpuid));
memset(cpuid_str, 0, sizeof(cpuid_str));
for (i = 0; i < 16; i++)
sprintf(&cpuid_str[i * 2], "%02x", cpuid[i]);
/*
* Mix the cpuid bytes using the same rules as in
* ${linux}/drivers/soc/rockchip/rockchip-cpuinfo.c
*/
for (i = 0; i < 8; i++) {
low[i] = cpuid[1 + (i << 1)];
high[i] = cpuid[i << 1];
}
serialno = crc32_no_comp(0, low, 8);
serialno |= (u64)crc32_no_comp(serialno, high, 8) << 32;
snprintf(serialno_str, sizeof(serialno_str), "%llx", serialno);
setenv("cpuid#", cpuid_str);
if (!env_serial)
setenv("serial#", serialno_str);
saveenv();
}
static void setup_macaddr(void)
{
int ret;
const char *cpuid = getenv("cpuid#");
u8 hash[SHA256_SUM_LEN];
int size = sizeof(hash);
uchar mac_addr[6];
char buf[18];
int i, n;
/* Only generate a MAC address, if none is set in the environment */
if (getenv("ethaddr"))
return;
if (!cpuid) {
debug("%s: could not retrieve 'cpuid#'\n", __func__);
return;
}
ret = hash_block("sha256", (void *)cpuid, strlen(cpuid), hash, &size);
if (ret) {
debug("%s: failed to calculate SHA256\n", __func__);
return;
}
/* Copy 6 bytes of the hash to base the MAC address on */
memcpy(mac_addr, hash, 6);
/* Make this a valid MAC address and set it */
mac_addr[0] &= 0xfe; /* clear multicast bit */
mac_addr[0] |= 0x02; /* set local assignment bit (IEEE802) */
for (i = 0, n = 0; i < sizeof(mac_addr); i++)
n += sprintf(buf + n, "%02x:", mac_addr[i]);
buf[17] = '\0';
setenv("ethaddr", buf);
}
/*****************************************
* Routine: board_init
* Description: Early hardware init.
......@@ -234,6 +388,13 @@ int board_late_init(void)
board_init_adjust_env();
bd_hwrev_init();
panel_pwm_status_init();
set_dtb_name();
setup_serial();
setup_macaddr();
load_disk_partitions();
#ifdef CONFIG_RK_PWM_REMOTE
......@@ -247,9 +408,6 @@ int board_late_init(void)
key_init();
#endif
bd_hwrev_init();
panel_pwm_status_init();
#ifdef CONFIG_RK_POWER
debug("fixed_init\n");
fixed_regulator_init();
......
......@@ -501,6 +501,23 @@ static void rk_commandline_setenv(const char *boot_name, rk_boot_img_hdr *hdr, b
hdr->ramdisk_addr, hdr->ramdisk_size,
!strcmp(boot_name, RECOVERY_NAME));
#ifdef CONFIG_RK_SDCARD_BOOT_EN
if (StorageSDCardBootMode()) {
/* Remove `mtdparts=[^ ]*' for SDCard boot */
char *mtd_start, *mtd_end;
mtd_start = strstr(command_line, "mtdparts=");
if (mtd_start) {
mtd_end = strstr(mtd_start, " ");
if (mtd_end)
strcpy(mtd_start, mtd_end + 1);
else
while (--mtd_start >= command_line && *mtd_start == ' ')
*mtd_start = '\0';
}
}
#endif
char *panel = board_get_panel_name();
if (panel) {
snprintf(command_line, sizeof(command_line),
......
......@@ -11,6 +11,7 @@
static const char* PROG = NULL;
static resource_ptn_header header;
static bool just_print = false;
static bool keep_dtbname = false;
char image_path[MAX_INDEX_ENTRY_PATH_LEN] = "\0";
char root_path[MAX_INDEX_ENTRY_PATH_LEN] = "\0";
......@@ -75,6 +76,8 @@ int main(int argc, char** argv) {
return 0;
} else if (!strcmp(OPT_PRINT, arg)) {
just_print = true;
} else if (!strcmp(OPT_DTBNAME, arg)) {
keep_dtbname = true;
} else if (!strcmp(OPT_PACK, arg)) {
action = ACTION_PACK;
} else if (!strcmp(OPT_UNPACK, arg)) {
......@@ -233,16 +236,16 @@ done:
end:
if (out_file)
fclose(out_file);
if (pos)
fseek(file, pos, SEEK_SET);
return ret;
if (pos)
fseek(file, pos, SEEK_SET);
return ret;
}
static int unpack_image(const char* dir) {
bool ret = false;
char unpack_dir[MAX_INDEX_ENTRY_PATH_LEN];
if (just_print)
dir = ".";
if (just_print)
dir = ".";
snprintf(unpack_dir, sizeof(unpack_dir), "%s", dir);
if (!strlen(unpack_dir)) {
goto end;
......@@ -412,23 +415,35 @@ static bool write_index_tbl(const int file_num, const char** files) {
fix_entry(&entry);
memset(entry.path, 0, sizeof(entry.path));
const char* path = files[i];
if (root_path[0]) {
if (!strncmp(path, root_path, strlen(root_path))) {
path += strlen(root_path);
if (path[0] == '/')
path++;
}
}
path = fix_path(path);
if (!strcmp(files[i] + strlen(files[i]) - strlen(DTD_SUBFIX),
DTD_SUBFIX)) {
if (!foundFdt) {
//use default path.
LOGD("mod fdt path:%s -> %s...", files[i], FDT_PATH);
path = FDT_PATH;
foundFdt = true;
if (strstr(path, ".dtb") && keep_dtbname) {
path = rindex(path, '/');
if (!path)
path = files[i];
else
path++;
LOGD("using dtb name: %s", path);
} else {
if (root_path[0]) {
if (!strncmp(path, root_path, strlen(root_path))) {
path += strlen(root_path);
if (path[0] == '/')
path++;
}
}
path = fix_path(path);
if (!strcmp(files[i] + strlen(files[i]) - strlen(DTD_SUBFIX),
DTD_SUBFIX)) {
if (!foundFdt) {
//use default path.
LOGD("mod fdt path:%s -> %s...", files[i], FDT_PATH);
path = FDT_PATH;
foundFdt = true;
}
}
}
snprintf(entry.path, sizeof(entry.path), "%s", path);
offset += fix_blocks(file_size);
if (!write_data(header.header_size + i * header.tbl_entry_size,
......
......@@ -52,7 +52,8 @@ typedef struct {
#define OPT_TEST_CHARGE "--test_charge"
#define OPT_IMAGE "--image="
#define OPT_ROOT "--root="
#define OPT_DTBNAME "--dtbname"
#define VERSION "2014-5-31 14:43:42"
#define VERSION "2018-6-22 18:51:18"
#endif //RESOURCE_TOOL_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment