summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcharles.park <charles.park@hardkernel.com>2017-08-03 12:43:44 +0300
committercharles.park <charles.park@hardkernel.com>2017-08-03 12:43:44 +0300
commit27d66ae9d4106df9ee9c75d5f57b057144d44d98 (patch)
tree550f95336fcd26f140a32d049597cd3bfbbb1d4e
parent314185a7872a47805119c1da33281c0a66bc99a4 (diff)
downloadu-boot-27d66ae9d4106df9ee9c75d5f57b057144d44d98.tar.xz
ODROID-XU4 : self-update logic added.
Change-Id: Ifa26263b40e5d79f2d06a647a7ae0502ca79802e
-rwxr-xr-xboard/samsung/common/odroid_misc.c127
-rwxr-xr-xcmd/mmc.c43
-rwxr-xr-xcmd/odroid_fastboot.c113
-rwxr-xr-xinclude/configs/odroid_xu4.h8
-rwxr-xr-xinclude/samsung/odroid_misc.h10
5 files changed, 261 insertions, 40 deletions
diff --git a/board/samsung/common/odroid_misc.c b/board/samsung/common/odroid_misc.c
index 171f59f8db..7cd92b3d36 100755
--- a/board/samsung/common/odroid_misc.c
+++ b/board/samsung/common/odroid_misc.c
@@ -197,7 +197,17 @@ void odroid_led_ctrl(int gpio, int status)
}
/*---------------------------------------------------------------------------*/
-static void odroid_pmic_deinit(void) {}
+static void odroid_pmic_deinit(void)
+{
+ struct udevice *dev;
+
+ if (pmic_get("s2mps11", &dev)) {
+ printf("%s : s2mps11 control error!\n", __func__);
+ return;
+ }
+ /* Master Reset Enable */
+ pmic_reg_write(dev, S2MPS11_REG_CTRL1, 0x0);
+}
/*---------------------------------------------------------------------------*/
static void odroid_pmic_init(void)
@@ -313,9 +323,112 @@ err:
}
/*---------------------------------------------------------------------------*/
+static int filecheck(const char *fname)
+{
+ char cmd[64];
+ unsigned long filesize = 0;
+
+ /* env variable init */
+ setenv("filesize", "0");
+
+ memset(cmd, 0x00, sizeof(cmd));
+ sprintf(cmd, "fatload mmc 0:1 40008000 update/%s", fname);
+ run_command(cmd, 0);
+
+ /* file size check */
+ if ((filesize = getenv_ulong("filesize", 16, 0)))
+ return 1;
+
+ printf("ERROR! update/%s File Not Found!! filesize = 0\n", fname);
+
+ /* error */
+ return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+static void update_image(const char *ptn)
+{
+ char cmd[64];
+
+ memset(cmd, 0x00, sizeof(cmd));
+ sprintf(cmd, "fastboot flash %s 40008000 0", ptn);
+ run_command(cmd, 0);
+}
+
+/*---------------------------------------------------------------------------*/
+static void update_raw_image(const char *ptn)
+{
+ struct exynos5_power *pmu =
+ (struct exynos5_power *)samsung_get_base_power;
+ int OmPin;
+
+ OmPin = pmu->inform3;
+
+ if (!strncmp(ptn, "kernel", sizeof("kernel")))
+ run_command("movi w k 0 40008000", 0);
+ else {
+ if ((OmPin == BOOT_EMMC_4_4) || (OmPin == BOOT_EMMC)) {
+ run_command("emmc open 0", 0);
+ if (!strncmp(ptn, "bootloader", sizeof("bootloader")))
+ run_command("movi w z u 0 40008000", 0);
+ if (!strncmp(ptn, "bl1", sizeof("bl1")))
+ run_command("movi w z f 0 40008000", 0);
+ if (!strncmp(ptn, "bl2", sizeof("bl2")))
+ run_command("movi w z b 0 40008000", 0);
+ if (!strncmp(ptn, "tzsw", sizeof("tzsw")))
+ run_command("movi w z t 0 40008000", 0);
+ run_command("emmc close 0", 0);
+ } else {
+ if (!strncmp(ptn, "bootloader", sizeof("bootloader")))
+ run_command("movi w u 0 40008000", 0);
+ if (!strncmp(ptn, "bl1", sizeof("bl1")))
+ run_command("movi w f 0 40008000", 0);
+ if (!strncmp(ptn, "bl2", sizeof("bl2")))
+ run_command("movi w b 0 40008000", 0);
+ if (!strncmp(ptn, "tzsw", sizeof("tzsw")))
+ run_command("movi w t 0 40008000", 0);
+ }
+ }
+}
+
+/*---------------------------------------------------------------------------*/
/* firmware update check */
static void odroid_fw_update(unsigned int option)
{
+ odroid_led_ctrl(GPIO_LED_B, 1);
+
+ if (filecheck("system.img"))
+ update_image("system");
+ if (filecheck("cache.img"))
+ update_image("cache");
+
+ if (option & OPTION_ERASE_USERDATA) {
+ if (filecheck("userdata.img"))
+ update_image("userdata");
+ }
+ if (filecheck("zImage"))
+ update_raw_image("kernel");
+ else if (filecheck("zImage-dtb"))
+ update_raw_image("kernel");
+
+ if (option & OPTION_UPDATE_UBOOT) {
+ if(filecheck("u-boot.bin"))
+ update_raw_image("bootloader");
+ if(filecheck("bl1.bin"))
+ update_raw_image("bl1");
+ if(filecheck("bl2.bin"))
+ update_raw_image("bl2");
+ if(filecheck("tzsw.bin"))
+ update_raw_image("tzsw");
+ }
+
+ if (option & OPTION_ERASE_ENV)
+ run_command(UBOOT_ENV_ERASE, 0);
+
+ if (option & OPTION_ERASE_FAT)
+ run_command("fatformat mmc 0:1", 0);
+
+ odroid_led_ctrl(GPIO_LED_B, 1);
}
/*---------------------------------------------------------------------------*/
@@ -372,4 +485,16 @@ void odroid_misc_deinit(void)
}
/*---------------------------------------------------------------------------*/
+void odroid_power_off(void)
+{
+ struct exynos5_power *power =
+ (struct exynos5_power *)samsung_get_base_power();
+
+ printf("%s\n", __func__);
+ odroid_misc_deinit();
+
+ power->ps_hold_control = 0x5200;
+}
+
+/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
diff --git a/cmd/mmc.c b/cmd/mmc.c
index ac6bb702ad..0db7d48bc5 100755
--- a/cmd/mmc.c
+++ b/cmd/mmc.c
@@ -1426,32 +1426,31 @@ static int get_partition_info(const char *ptn, struct partition_info *pinfo)
static int do_movi(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
- unsigned int dev_num, ret = -1, addr, offset = 0;
- char cmd[64] = {0, };
+ unsigned int dev_no, ret = -1, addr, offset = 0;
struct partition_info pinfo;
switch(argc) {
case 3:
if ('i' == argv[1][0]) {
- dev_num = simple_strtoul(argv[2], NULL, 10);
- if (dev_num)
+ dev_no = simple_strtoul(argv[2], NULL, 10);
+ if (dev_no)
ret = run_command("mmc dev 1", 0);
if (!ret)
run_command("mmc info", 0);
- if (dev_num && !ret)
+ if (dev_no && !ret)
run_command("mmc dev 0", 0);
return ret ? CMD_RET_FAILURE:CMD_RET_SUCCESS;
}
break;
case 5:
- dev_num = simple_strtoul(argv[3], NULL, 10);
- addr = simple_strtoul(argv[4], NULL, 10);
+ dev_no = simple_strtoul(argv[3], NULL, 10);
+ addr = simple_strtoul(argv[4], NULL, 16);
ret = get_partition_info(argv[2], &pinfo);
break;
case 6:
- dev_num = simple_strtoul(argv[4], NULL, 10);
- addr = simple_strtoul(argv[5], NULL, 10);
+ dev_no = simple_strtoul(argv[4], NULL, 10);
+ addr = simple_strtoul(argv[5], NULL, 16);
ret = get_partition_info(argv[3], &pinfo);
if ((argv[2][0] == 'z') && pinfo.raw_en)
offset = 1;
@@ -1460,15 +1459,29 @@ static int do_movi(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
break;
}
if (!ret) {
- sprintf(cmd, "mmc %s %d %x %x",
+ struct mmc *mmc;
+
+ mmc = find_mmc_device(dev_no);
+
+ printf("mmc block %s, dev %d, addr 0x%x, blk start %d, blk cnt %d\n",
(argv[1][0] == 'w') ? "write" : "read",
- addr,
- pinfo.blk_start - offset,
- pinfo.size / MOVI_BLK_SIZE);
- run_command(cmd, 0);
+ dev_no,
+ (unsigned int)addr,
+ (pinfo.blk_start - offset),
+ (pinfo.size / MOVI_BLK_SIZE));
+
+ if (argv[1][0] == 'w')
+ mmc->block_dev.block_write(&mmc->block_dev,
+ (pinfo.blk_start - offset),
+ (pinfo.size / MOVI_BLK_SIZE),
+ (int *)addr);
+ else
+ mmc->block_dev.block_read(&mmc->block_dev,
+ (pinfo.blk_start - offset),
+ (pinfo.size / MOVI_BLK_SIZE),
+ (void *)addr);
return CMD_RET_SUCCESS;
}
-usage:
return CMD_RET_USAGE;
}
diff --git a/cmd/odroid_fastboot.c b/cmd/odroid_fastboot.c
index 5b5255d3c0..e998d2800e 100755
--- a/cmd/odroid_fastboot.c
+++ b/cmd/odroid_fastboot.c
@@ -17,10 +17,13 @@
#include <samsung/odroid_misc.h>
#include <mmc.h>
+/*---------------------------------------------------------------------------*/
static unsigned int download_size;
static unsigned int download_bytes;
static unsigned int download_error;
static int rx_handler (const unsigned char *buffer, unsigned int buffer_size);
+
+/*---------------------------------------------------------------------------*/
static struct cmd_fastboot_interface interface =
{
.rx_handler = rx_handler,
@@ -32,6 +35,7 @@ static struct cmd_fastboot_interface interface =
.transfer_buffer_size = 0,
};
+/*---------------------------------------------------------------------------*/
static int flashing_raw_data(struct partition_info *pinfo,
unsigned int addr, unsigned int size, unsigned int dev_no)
{
@@ -48,11 +52,16 @@ static int flashing_raw_data(struct partition_info *pinfo,
run_command(cmd, 0);
blk_start = pinfo->blk_start -1;
}
- memset(cmd, 0x00, sizeof(cmd));
- sprintf(cmd, "mmc write %x %x %x",
- (unsigned int)addr, blk_start, blk_cnt);
- run_command(cmd, 0);
- printf("%s : %s\n", __func__, cmd);
+
+ mmc->block_dev.block_write(&mmc->block_dev,
+ blk_start,
+ blk_cnt,
+ (const void *)addr);
+ printf("mmc block write, dev %d, addr 0x%x, blk start %d, blk cnt %d\n",
+ dev_no,
+ (unsigned int)addr,
+ blk_start,
+ blk_cnt);
if (!IS_SD(mmc) && pinfo->raw_en) {
memset(cmd, 0x00, sizeof(cmd));
@@ -62,6 +71,7 @@ static int flashing_raw_data(struct partition_info *pinfo,
return 0;
}
+/*---------------------------------------------------------------------------*/
static void erase_partition(struct partition_info *pinfo, unsigned int dev_no)
{
#define BLOCK_ERASE_SIZE (512 * 1024)
@@ -99,6 +109,7 @@ static void erase_partition(struct partition_info *pinfo, unsigned int dev_no)
free(clrbuf);
}
+/*---------------------------------------------------------------------------*/
static int check_compress_ext4(char *img_base, unsigned long long parti_size) {
ext4_file_header *file_header;
@@ -141,6 +152,7 @@ static int check_compress_ext4(char *img_base, unsigned long long parti_size) {
return 0;
}
+/*---------------------------------------------------------------------------*/
static int write_compressed_ext4(char* img_base, unsigned int sector_base,
unsigned int dev_no)
{
@@ -194,7 +206,8 @@ static int write_compressed_ext4(char* img_base, unsigned int sector_base,
break;
}
total_chunks--;
- printf("mmc write blk = 0x%08x, size = 0x%08x, remain chunks = %d\n",
+ printf("mmc write dev %d, blk = 0x%08x, size = 0x%08x, remain chunks = %d\n",
+ dev_no,
sector_base,
sector_size,
total_chunks);
@@ -207,20 +220,21 @@ static int write_compressed_ext4(char* img_base, unsigned int sector_base,
return 0;
}
+/*---------------------------------------------------------------------------*/
static int flashing_data(struct partition_info *pinfo,
unsigned int addr, unsigned int size, unsigned int dev_no)
{
if (check_compress_ext4((char *)addr, pinfo->size))
- flashing_raw_data(pinfo, addr, size, dev_no);
+ flashing_raw_data(pinfo, addr, pinfo->size, dev_no);
else {
erase_partition(pinfo, dev_no);
write_compressed_ext4((char*)addr, pinfo->blk_start, dev_no);
}
- run_command("mmc dev 0", 0);
return 0;
}
+/*---------------------------------------------------------------------------*/
static int rx_handler (const unsigned char *buffer, unsigned int buffer_size)
{
int ret = 1;
@@ -421,7 +435,7 @@ static int rx_handler (const unsigned char *buffer, unsigned int buffer_size)
if (flashing_data(&pinfo,
(unsigned int)interface.transfer_buffer,
download_bytes, 0)) {
- sprintf(response, "FAILfailed to flash %s partition!",
+ sprintf(response, "FAILfailed to flash %s partition!",
cmdbuf + 6);
goto send_tx_status;
}
@@ -438,19 +452,77 @@ send_tx_status:
return ret;
}
+/*---------------------------------------------------------------------------*/
+static int fastboot_cmd_flash(int argc, char *const argv[])
+{
+ struct partition_info pinfo;
+ unsigned int addr, dev_no = 0;
+
+ if (odroid_get_partition_info(argv[2], &pinfo))
+ return 1;
+
+ addr = simple_strtoul(argv[3], NULL, 16);
+ if (argc == 5)
+ dev_no = simple_strtoul(argv[4], NULL, 16);
+
+ if ((dev_no != 0) && (dev_no != 1))
+ dev_no = 0;
+
+ flashing_data(&pinfo, addr, pinfo.size, dev_no);
+
+ if (dev_no)
+ run_command("mmc dev 0", 0);
+
+ return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+static int fastboot_cmd_parsing(int argc, char *const argv[], int *retval)
+{
+ int ret = 0;
+ *retval = CMD_RET_FAILURE;
+
+ switch(argc) {
+ case 2:
+ if (!strncmp(argv[1], "poweroff", sizeof("poweroff"))) {
+ odroid_power_off();
+ while(1);
+ }
+ *retval = CMD_RET_USAGE;
+ break;
+ case 5: case 6:
+ if (argv[4] != NULL)
+ ret = odroid_partition_setup(argv[4]);
+ else
+ ret = odroid_partition_setup("0");
+
+ if (!ret)
+ ret = fastboot_cmd_flash(argc, argv);
+
+ *retval = ret ? CMD_RET_FAILURE:CMD_RET_SUCCESS;
+ break;
+ default:
+ *retval = CMD_RET_USAGE;
+ break;
+ /* normal fastboot */
+ case 1:
+ ret = odroid_partition_setup("0");
+ *retval = ret ? CMD_RET_FAILURE:CMD_RET_SUCCESS;
+ return *retval;
+ }
+ return 1;
+}
+
+/*---------------------------------------------------------------------------*/
static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
- int continue_from_disconnect = 0, poll_status;
+ int continue_from_disconnect = 0, poll_status, retval;
int led_status = 0, led_blink_cnt = 0;
int ret = 1;
- if (argv[4] != NULL)
- ret = odroid_partition_setup(argv[4]);
- else
- ret = odroid_partition_setup("0");
- if (ret)
- return ret;
-
+ /* fastboot command parsing */
+ if (fastboot_cmd_parsing(argc, argv, &retval))
+ return retval;
do
{
continue_from_disconnect = 0;
@@ -509,6 +581,9 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
U_BOOT_CMD(
fastboot, 5, 1, do_fastboot,
"use USB Fastboot protocol",
- "<USB_controller>\n"
- " - run as a fastboot usb device"
+ "[ poweroff | flash [kernel|system|userdata|cache] [addr] [dev no] ]\n"
+ "[] - options for self update"
);
+
+/*---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
diff --git a/include/configs/odroid_xu4.h b/include/configs/odroid_xu4.h
index 319dc3e635..00c4a46cd7 100755
--- a/include/configs/odroid_xu4.h
+++ b/include/configs/odroid_xu4.h
@@ -157,10 +157,9 @@
#define EXYNOS_USB_LINK_BASE EXYNOS5_USBOTG_BASE
#if defined(CONFIG_FASTBOOT)
- #define CFG_FASTBOOT_TRANSFER_BUFFER (CONFIG_SYS_SDRAM_BASE + 0x8000000)
+ #define CFG_FASTBOOT_TRANSFER_BUFFER (0x50000000)
+
#define CFG_FASTBOOT_TRANSFER_BUFFER_SIZE (0x30000000) /* 768MB */
- #define CFG_FASTBOOT_ADDR_KERNEL (CONFIG_SYS_SDRAM_BASE + 0x8000)
- #define CFG_FASTBOOT_ADDR_RAMDISK (CONFIG_SYS_SDRAM_BASE + 0x1000000)
#define CFG_FASTBOOT_PAGESIZE (2048) // Page size of booting device
#define CFG_FASTBOOT_SDMMC_BLOCKSIZE (512) // Block size of sdmmc
#endif
@@ -168,7 +167,6 @@
/* cmd from kernel reboot */
#define FASTBOOT_MAGIC_REBOOT_CMD 0xFAB0
#define FASTBOOT_MAGIC_UPDATE_CMD 0xFADA
-
#endif /*#if defined(CONFIG_USB_DEVICE) */
/* FIXME: MUST BE REMOVED AFTER TMU IS TURNED ON */
@@ -241,6 +239,6 @@
"copy_uboot_emmc2sd="UBOOT_COPY_EMMC2SD
#undef CONFIG_BOOTCOMMAND
-#define CONFIG_BOOTCOMMAND "cfgload"
+#define CONFIG_BOOTCOMMAND "cfgload;movi r k 0 40008000;bootz 40008000"
#endif /* __CONFIG_H */
diff --git a/include/samsung/odroid_misc.h b/include/samsung/odroid_misc.h
index 1131dba91a..cfb0621e44 100755
--- a/include/samsung/odroid_misc.h
+++ b/include/samsung/odroid_misc.h
@@ -11,6 +11,15 @@
#define GPIO_FAN_CTL EXYNOS5420_GPIO_B20
#define GPIO_LCD_PWM EXYNOS5420_GPIO_B23
+#define BOOT_EMMC 0x6
+#define BOOT_EMMC_4_4 0x7
+
+/* Self update option */
+#define OPTION_ERASE_USERDATA 0x01
+#define OPTION_ERASE_FAT 0x02
+#define OPTION_ERASE_ENV 0x04
+#define OPTION_UPDATE_UBOOT 0x08
+
enum {
PART_FWBL1 = 0,
PART_BL2,
@@ -36,5 +45,6 @@ extern int odroid_partition_setup (char *dev_no);
extern void odroid_led_ctrl (int gpio, int status);
extern void odroid_misc_init (void);
+extern void odroid_power_off (void);
#endif /* __ODROID_MISC_H__ */