/*
*
* eMMC maskrom mode : GPIO6_A7 (H:disable maskrom, L:enable maskrom)
*
*/
void rk3288_maskrom_ctrl(bool enable_emmc)
{
printf("%s: enable_emmc = %dn", __func__, enable_emmc);
if(enable_emmc == true)
gpio_direction_output(GPIO_BANK6|GPIO_A7, 1);
else
gpio_direction_output(GPIO_BANK6|GPIO_A7, 0);
mdelay(10);
}
void check_force_enter_ums_mode(void)
{
enum pcb_id pcbid;
enum project_id projectid;
// enable projectid pull down and set it to input
gpio_pull_updown(GPIO_BANK2|GPIO_A1, GPIOPullUp);
gpio_pull_updown(GPIO_BANK2|GPIO_A2, GPIOPullUp);
gpio_pull_updown(GPIO_BANK2|GPIO_A3, GPIOPullUp);
gpio_direction_input(GPIO_BANK2|GPIO_A1);
gpio_direction_input(GPIO_BANK2|GPIO_A2);
gpio_direction_input(GPIO_BANK2|GPIO_A3);
// set pcbid to input
gpio_direction_input(GPIO_BANK2|GPIO_B0);
// disable SDP pull up/down and set it to input
gpio_pull_updown(GPIO_BANK6|GPIO_A5, PullDisable);
gpio_direction_input(GPIO_BANK6|GPIO_A5);
mdelay(10);
// read project id
projectid = gpio_get_value(GPIO_BANK2|GPIO_A1) | gpio_get_value(GPIO_BANK2|GPIO_A2)<<1 | gpio_get_value(GPIO_BANK2|GPIO_A3)<<2;
// read pcbid
pcbid = gpio_get_value(GPIO_BANK2|GPIO_B0) | gpio_get_value(GPIO_BANK2|GPIO_B1)<<1 | gpio_get_value(GPIO_BANK2|GPIO_B2)<<2;
// only Tinker Board S and the PR stage PCB has this function
if(projectid!=TinkerBoard && pcbid >= ER){
printf("PC event = 0x%xn", gpio_get_value(GPIO_BANK6|GPIO_A5));
if(gpio_get_value(GPIO_BANK6|GPIO_A5) == 1){
// SDP detected, enable EMMC and unlock u*** current limit
printf("u*** connected to SDP, force enter ums moden");
force_ums = true;
// unlock u*** current limit and re-enable EMMC
u***_current_limit_ctrl(true);
rk3288_maskrom_ctrl(true);
mdelay(10);
}
}
}
static int xxx_device_i2c(void)
{
unsigned char a[1]={0x41};
int tmp;
i2c_set_bus_num(1);
i2c_init(100000, 0);
i2c_set_bus_speed(100000);
tmp = i2c_probe(0x30);
printf("nni2c_probe = %dnn", tmp);
printf("nn*****************read/write reg 16bit******************nn");
mdelay(10);
i2c_read_x(0x30, 0x1404, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
tmp = a[0] << 8;
mdelay(10);
i2c_read_x(0x30, 0x1405, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
tmp = tmp + a[0];
printf("nn========================T613 ID = 0x%x==================nn",tmp);
mdelay(10);
i2c_read_x(0x30, 0x2480, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
mdelay(10);
i2c_read_x(0x30, 0x2482, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
mdelay(10);
i2c_read_x(0x30, 0x2484, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
mdelay(10);
i2c_read_x(0x30, 0x2485, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
mdelay(10);
a[0] = 0x33;
i2c_write_x(0x30, 0x2480, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
mdelay(10);
a[0] = 0x99;
i2c_write_x(0x30, 0x2488, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
mdelay(10);
a[0] = 0x66;
i2c_write_x(0x30, 0x248A, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
printf("nn*****************read/write reg 8bit******************nn");
mdelay(100);
i2c_read_x(0x24, 0x84, 1, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
mdelay(10);
i2c_read_x(0x24, 0x85, 1, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
mdelay(10);
a[0] = 0x33;
i2c_write_x(0x24, 0x80, 1, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
return (0);
}
#ifdef CONFIG_BOARD_LATE_INIT
extern char bootloader_ver[24];
int board_late_init(void)
{
debug("board_late_initn");
board_init_adjust_env();
load_disk_partitions();
debug("rkimage_prepare_fdtn");
rkimage_prepare_fdt();
#ifdef CONFIG_RK_KEY
debug("key_initn");
key_init();
#endif
#ifdef CONFIG_RK_POWER
debug("fixed_initn");
fixed_regulator_init();
debug("pmic_initn");
pmic_init(0);
#if defined(CONFIG_POWER_PWM_REGULATOR)
debug("pwm_regulator_initn");
pwm_regulator_init();
#endif
debug("fg_initn");
fg_init(0); /*fuel gauge init*/
#endif /* CONFIG_RK_POWER */
#if defined(CONFIG_RK_DCF)
dram_freq_init();
#endif
#ifdef CONFIG_OPTEE_CLIENT
load_attestation_key();
#endif
debug("idb initn");
//TODO:set those buffers in a better way, and use malloc?
rkidb_setup_space(gd->arch.rk_global_buf_addr);
/* after setup space, get id block data first */
rkidb_get_idblk_data();
/* Secure boot check after idb data get */
SecureBootCheck();
if (rkidb_get_bootloader_ver() == 0) {
printf("n#Boot ver: %sn", bootloader_ver);
}
char tmp_buf[32];
/* rk sn size 30bytes, zero buff */
memset(tmp_buf, 0, 32);
if (rkidb_get_sn(tmp_buf)) {
setenv("fbt_sn#", tmp_buf);
}
debug("fbt prebootn");
board_fbt_preboot();
xxx_device_i2c_i2c();
return 0;
}
#endif
int board_modify_fdt(void)
{
#if defined(CONFIG_RKCHIP_RK3288) && defined(CONFIG_NORMAL_WORLD)
int ret;
/* RK3288W HDMI Revision ID is 0x1A */
if (readl(RKIO_HDMI_PHYS + 0x4) == 0x1A) {
ret = fdt_setprop_string((void *)gd->fdt_blob, 0,
"compatible", "rockchip,rk3288w");
if (ret) {
printf("fdt set compatible failed: %dn", ret);
return -1;
}
}
#endif
return 0;
}
#ifdef CONFIG_CMD_NET
/*
* Initializes on-chip ethernet controllers.
* to override, implement board_eth_init()
*/
int board_eth_init(bd_t *bis)
{
__maybe_unused int rc;
debug("board_eth_initn");
#ifdef CONFIG_RK_GMAC
char macaddr[6];
char ethaddr[20];
char *env_str = NULL;
memset(ethaddr, sizeof(ethaddr), 0);
env_str = getenv("ethaddr");
if (rkidb_get_mac_address(macaddr) == true) {
sprintf(ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
printf("mac address: %sn", ethaddr);
if (env_str == NULL)
setenv ((char *)"ethaddr", (char *)ethaddr);
else if (strncmp(env_str, ethaddr, strlen(ethaddr)) != 0)
setenv ((char *)"ethaddr", (char *)ethaddr);
} else {
uint16_t v;
v = (rand() & 0xfeff) | 0x0200;
macaddr[0] = (v >> 8) & 0xff;
macaddr[1] = v & 0xff;
v = rand();
macaddr[2] = (v >> 8) & 0xff;
macaddr[3] = v & 0xff;
v = rand();
macaddr[4] = (v >> 8) & 0xff;
macaddr[5] = v & 0xff;
sprintf(ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
if (env_str == NULL) {
printf("mac address: %sn", ethaddr);
setenv ((char *)"ethaddr", (char *)ethaddr);
} else {
printf("mac address: %sn", env_str);
}
}
rc = rk_gmac_initialize(bis);
if (rc < 0) {
printf("rockchip: failed to initialize gmacn");
return rc;
}
#endif /* CONFIG_RK_GMAC */
return 0;
}
#endif
#ifdef CONFIG_ROCKCHIP_DISPLAY
extern void rockchip_display_fixup(void *blob);
#endif
#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
void ft_board_setup(void *blob, bd_t * bd)
{
#ifdef CONFIG_ROCKCHIP_DISPLAY
rockchip_display_fixup(blob);
#endif
#ifdef CONFIG_ROCKCHIP
#if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
u64 start, size;
int offset;
if (!gd->uboot_logo)
return;
start = gd->fb_base;
offset = gd->fb_offset;
if (offset > 0)
size = CONFIG_RK_LCD_SIZE;
else
size = CONFIG_RK_FB_SIZE;
fdt_update_reserved_memory(blob, "rockchip,fb-logo", start, size);
#endif
#endif
}
#endif
7.改写完成后重新进行如下操作:
echo 对u-boot 进行重新编译,生成新的update.img
cd u-boot
make
cd ..
./mkimage.sh
cd RKTools/linux/Linux_Pack_Firmware/rockdev
./collectImages.sh && ./mkupdate.sh
echo 在windows 下打开 SpiImageTools.exe 加在update.img,会在当前文件夹下产生bin 档(该工具在源码目录下 RKToolswindows)
echo 打开Win32diskImager.exe 将bin 档烧写到SD卡中,然后上电启动RK3288
重新上电后,就会对slave device 进行init 操作。
/*
*
* eMMC maskrom mode : GPIO6_A7 (H:disable maskrom, L:enable maskrom)
*
*/
void rk3288_maskrom_ctrl(bool enable_emmc)
{
printf("%s: enable_emmc = %dn", __func__, enable_emmc);
if(enable_emmc == true)
gpio_direction_output(GPIO_BANK6|GPIO_A7, 1);
else
gpio_direction_output(GPIO_BANK6|GPIO_A7, 0);
mdelay(10);
}
void check_force_enter_ums_mode(void)
{
enum pcb_id pcbid;
enum project_id projectid;
// enable projectid pull down and set it to input
gpio_pull_updown(GPIO_BANK2|GPIO_A1, GPIOPullUp);
gpio_pull_updown(GPIO_BANK2|GPIO_A2, GPIOPullUp);
gpio_pull_updown(GPIO_BANK2|GPIO_A3, GPIOPullUp);
gpio_direction_input(GPIO_BANK2|GPIO_A1);
gpio_direction_input(GPIO_BANK2|GPIO_A2);
gpio_direction_input(GPIO_BANK2|GPIO_A3);
// set pcbid to input
gpio_direction_input(GPIO_BANK2|GPIO_B0);
// disable SDP pull up/down and set it to input
gpio_pull_updown(GPIO_BANK6|GPIO_A5, PullDisable);
gpio_direction_input(GPIO_BANK6|GPIO_A5);
mdelay(10);
// read project id
projectid = gpio_get_value(GPIO_BANK2|GPIO_A1) | gpio_get_value(GPIO_BANK2|GPIO_A2)<<1 | gpio_get_value(GPIO_BANK2|GPIO_A3)<<2;
// read pcbid
pcbid = gpio_get_value(GPIO_BANK2|GPIO_B0) | gpio_get_value(GPIO_BANK2|GPIO_B1)<<1 | gpio_get_value(GPIO_BANK2|GPIO_B2)<<2;
// only Tinker Board S and the PR stage PCB has this function
if(projectid!=TinkerBoard && pcbid >= ER){
printf("PC event = 0x%xn", gpio_get_value(GPIO_BANK6|GPIO_A5));
if(gpio_get_value(GPIO_BANK6|GPIO_A5) == 1){
// SDP detected, enable EMMC and unlock u*** current limit
printf("u*** connected to SDP, force enter ums moden");
force_ums = true;
// unlock u*** current limit and re-enable EMMC
u***_current_limit_ctrl(true);
rk3288_maskrom_ctrl(true);
mdelay(10);
}
}
}
static int xxx_device_i2c(void)
{
unsigned char a[1]={0x41};
int tmp;
i2c_set_bus_num(1);
i2c_init(100000, 0);
i2c_set_bus_speed(100000);
tmp = i2c_probe(0x30);
printf("nni2c_probe = %dnn", tmp);
printf("nn*****************read/write reg 16bit******************nn");
mdelay(10);
i2c_read_x(0x30, 0x1404, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
tmp = a[0] << 8;
mdelay(10);
i2c_read_x(0x30, 0x1405, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
tmp = tmp + a[0];
printf("nn========================T613 ID = 0x%x==================nn",tmp);
mdelay(10);
i2c_read_x(0x30, 0x2480, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
mdelay(10);
i2c_read_x(0x30, 0x2482, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
mdelay(10);
i2c_read_x(0x30, 0x2484, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
mdelay(10);
i2c_read_x(0x30, 0x2485, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
mdelay(10);
a[0] = 0x33;
i2c_write_x(0x30, 0x2480, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
mdelay(10);
a[0] = 0x99;
i2c_write_x(0x30, 0x2488, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
mdelay(10);
a[0] = 0x66;
i2c_write_x(0x30, 0x248A, 2, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
printf("nn*****************read/write reg 8bit******************nn");
mdelay(100);
i2c_read_x(0x24, 0x84, 1, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
mdelay(10);
i2c_read_x(0x24, 0x85, 1, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
mdelay(10);
a[0] = 0x33;
i2c_write_x(0x24, 0x80, 1, a, 1);
printf("nnt613_init = 0x%02xnn", a[0]);
return (0);
}
#ifdef CONFIG_BOARD_LATE_INIT
extern char bootloader_ver[24];
int board_late_init(void)
{
debug("board_late_initn");
board_init_adjust_env();
load_disk_partitions();
debug("rkimage_prepare_fdtn");
rkimage_prepare_fdt();
#ifdef CONFIG_RK_KEY
debug("key_initn");
key_init();
#endif
#ifdef CONFIG_RK_POWER
debug("fixed_initn");
fixed_regulator_init();
debug("pmic_initn");
pmic_init(0);
#if defined(CONFIG_POWER_PWM_REGULATOR)
debug("pwm_regulator_initn");
pwm_regulator_init();
#endif
debug("fg_initn");
fg_init(0); /*fuel gauge init*/
#endif /* CONFIG_RK_POWER */
#if defined(CONFIG_RK_DCF)
dram_freq_init();
#endif
#ifdef CONFIG_OPTEE_CLIENT
load_attestation_key();
#endif
debug("idb initn");
//TODO:set those buffers in a better way, and use malloc?
rkidb_setup_space(gd->arch.rk_global_buf_addr);
/* after setup space, get id block data first */
rkidb_get_idblk_data();
/* Secure boot check after idb data get */
SecureBootCheck();
if (rkidb_get_bootloader_ver() == 0) {
printf("n#Boot ver: %sn", bootloader_ver);
}
char tmp_buf[32];
/* rk sn size 30bytes, zero buff */
memset(tmp_buf, 0, 32);
if (rkidb_get_sn(tmp_buf)) {
setenv("fbt_sn#", tmp_buf);
}
debug("fbt prebootn");
board_fbt_preboot();
xxx_device_i2c_i2c();
return 0;
}
#endif
int board_modify_fdt(void)
{
#if defined(CONFIG_RKCHIP_RK3288) && defined(CONFIG_NORMAL_WORLD)
int ret;
/* RK3288W HDMI Revision ID is 0x1A */
if (readl(RKIO_HDMI_PHYS + 0x4) == 0x1A) {
ret = fdt_setprop_string((void *)gd->fdt_blob, 0,
"compatible", "rockchip,rk3288w");
if (ret) {
printf("fdt set compatible failed: %dn", ret);
return -1;
}
}
#endif
return 0;
}
#ifdef CONFIG_CMD_NET
/*
* Initializes on-chip ethernet controllers.
* to override, implement board_eth_init()
*/
int board_eth_init(bd_t *bis)
{
__maybe_unused int rc;
debug("board_eth_initn");
#ifdef CONFIG_RK_GMAC
char macaddr[6];
char ethaddr[20];
char *env_str = NULL;
memset(ethaddr, sizeof(ethaddr), 0);
env_str = getenv("ethaddr");
if (rkidb_get_mac_address(macaddr) == true) {
sprintf(ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
printf("mac address: %sn", ethaddr);
if (env_str == NULL)
setenv ((char *)"ethaddr", (char *)ethaddr);
else if (strncmp(env_str, ethaddr, strlen(ethaddr)) != 0)
setenv ((char *)"ethaddr", (char *)ethaddr);
} else {
uint16_t v;
v = (rand() & 0xfeff) | 0x0200;
macaddr[0] = (v >> 8) & 0xff;
macaddr[1] = v & 0xff;
v = rand();
macaddr[2] = (v >> 8) & 0xff;
macaddr[3] = v & 0xff;
v = rand();
macaddr[4] = (v >> 8) & 0xff;
macaddr[5] = v & 0xff;
sprintf(ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
if (env_str == NULL) {
printf("mac address: %sn", ethaddr);
setenv ((char *)"ethaddr", (char *)ethaddr);
} else {
printf("mac address: %sn", env_str);
}
}
rc = rk_gmac_initialize(bis);
if (rc < 0) {
printf("rockchip: failed to initialize gmacn");
return rc;
}
#endif /* CONFIG_RK_GMAC */
return 0;
}
#endif
#ifdef CONFIG_ROCKCHIP_DISPLAY
extern void rockchip_display_fixup(void *blob);
#endif
#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
void ft_board_setup(void *blob, bd_t * bd)
{
#ifdef CONFIG_ROCKCHIP_DISPLAY
rockchip_display_fixup(blob);
#endif
#ifdef CONFIG_ROCKCHIP
#if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
u64 start, size;
int offset;
if (!gd->uboot_logo)
return;
start = gd->fb_base;
offset = gd->fb_offset;
if (offset > 0)
size = CONFIG_RK_LCD_SIZE;
else
size = CONFIG_RK_FB_SIZE;
fdt_update_reserved_memory(blob, "rockchip,fb-logo", start, size);
#endif
#endif
}
#endif
7.改写完成后重新进行如下操作:
echo 对u-boot 进行重新编译,生成新的update.img
cd u-boot
make
cd ..
./mkimage.sh
cd RKTools/linux/Linux_Pack_Firmware/rockdev
./collectImages.sh && ./mkupdate.sh
echo 在windows 下打开 SpiImageTools.exe 加在update.img,会在当前文件夹下产生bin 档(该工具在源码目录下 RKToolswindows)
echo 打开Win32diskImager.exe 将bin 档烧写到SD卡中,然后上电启动RK3288
重新上电后,就会对slave device 进行init 操作。
举报