2013-04-02 12:48:06 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2013 Teresa Gámez, Phytec Messtechnik GmbH
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
2013-04-15 12:03:58 +00:00
|
|
|
#include <bootsource.h>
|
2013-04-02 12:48:06 +00:00
|
|
|
#include <envfs.h>
|
2016-07-20 06:04:11 +00:00
|
|
|
#include <bootm.h>
|
2013-04-02 12:48:06 +00:00
|
|
|
#include <init.h>
|
|
|
|
#include <io.h>
|
|
|
|
#include <fs.h>
|
2013-08-24 10:48:50 +00:00
|
|
|
#include <malloc.h>
|
2014-07-30 08:43:51 +00:00
|
|
|
#include <libfile.h>
|
2013-04-02 12:48:06 +00:00
|
|
|
#include <linux/stat.h>
|
2013-11-22 13:27:43 +00:00
|
|
|
#include <mach/gpmc.h>
|
2013-09-25 10:30:18 +00:00
|
|
|
#include <mach/generic.h>
|
2013-09-25 10:30:58 +00:00
|
|
|
#include <mach/am33xx-silicon.h>
|
|
|
|
#include <mach/omap3-silicon.h>
|
|
|
|
#include <mach/omap4-silicon.h>
|
2013-11-21 14:04:35 +00:00
|
|
|
#include <mach/am33xx-generic.h>
|
|
|
|
#include <mach/omap3-generic.h>
|
|
|
|
#include <mach/omap4-generic.h>
|
2013-09-25 10:30:58 +00:00
|
|
|
|
2013-11-22 13:27:43 +00:00
|
|
|
void __iomem *omap_gpmc_base;
|
|
|
|
|
2013-11-21 14:25:37 +00:00
|
|
|
unsigned int __omap_cpu_type;
|
|
|
|
|
2013-09-25 10:30:58 +00:00
|
|
|
static void *omap_sram_start(void)
|
|
|
|
{
|
|
|
|
if (cpu_is_am33xx())
|
|
|
|
return (void *)AM33XX_SRAM0_START;
|
2013-11-21 14:25:37 +00:00
|
|
|
if (cpu_is_omap3())
|
2013-09-25 10:30:58 +00:00
|
|
|
return (void *)OMAP3_SRAM_BASE;
|
2013-11-21 14:25:37 +00:00
|
|
|
if (cpu_is_omap4())
|
2013-09-25 10:30:58 +00:00
|
|
|
return (void *)OMAP44XX_SRAM_BASE;
|
2013-11-21 14:25:37 +00:00
|
|
|
return NULL;
|
2013-09-25 10:30:58 +00:00
|
|
|
}
|
|
|
|
|
2013-11-26 08:53:34 +00:00
|
|
|
static void *omap_scratch_space_start(void)
|
|
|
|
{
|
|
|
|
if (cpu_is_am33xx())
|
|
|
|
return (void *)AM33XX_SRAM_SCRATCH_SPACE;
|
|
|
|
if (cpu_is_omap3())
|
|
|
|
return (void *)OMAP3_SRAM_SCRATCH_SPACE;
|
|
|
|
if (cpu_is_omap4())
|
|
|
|
return (void *)OMAP44XX_SRAM_SCRATCH_SPACE;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-09-25 10:30:58 +00:00
|
|
|
void __noreturn omap_start_barebox(void *barebox)
|
|
|
|
{
|
|
|
|
int (*func)(void *) = barebox;
|
|
|
|
void *sramadr = omap_sram_start();
|
2013-11-26 08:53:34 +00:00
|
|
|
void *scratch = omap_scratch_space_start();
|
2013-09-25 10:30:58 +00:00
|
|
|
|
2013-11-26 08:53:34 +00:00
|
|
|
memcpy(sramadr, scratch, sizeof(uint32_t) * 3);
|
2013-09-25 10:30:58 +00:00
|
|
|
|
|
|
|
shutdown_barebox();
|
|
|
|
func(sramadr);
|
|
|
|
hang();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_BOOTM
|
|
|
|
static int do_bootm_omap_barebox(struct image_data *data)
|
|
|
|
{
|
|
|
|
void (*barebox)(uint32_t);
|
|
|
|
|
|
|
|
barebox = read_file(data->os_file, NULL);
|
|
|
|
if (!barebox)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-01-15 08:05:37 +00:00
|
|
|
if (data->dryrun) {
|
|
|
|
free(barebox);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-09-25 10:30:58 +00:00
|
|
|
omap_start_barebox(barebox);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct image_handler omap_barebox_handler = {
|
|
|
|
.name = "OMAP barebox",
|
|
|
|
.bootm = do_bootm_omap_barebox,
|
|
|
|
.filetype = filetype_arm_barebox,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int omap_bootm_barebox(void)
|
|
|
|
{
|
|
|
|
return register_image_handler(&omap_barebox_handler);
|
|
|
|
}
|
|
|
|
device_initcall(omap_bootm_barebox);
|
|
|
|
#endif
|
2013-04-02 12:48:07 +00:00
|
|
|
|
2013-09-25 10:30:18 +00:00
|
|
|
const static char *omap_bootmmc_dev;
|
2013-08-24 10:48:50 +00:00
|
|
|
|
2013-09-25 10:30:18 +00:00
|
|
|
void omap_set_bootmmc_devname(const char *devname)
|
2013-08-24 10:48:50 +00:00
|
|
|
{
|
|
|
|
omap_bootmmc_dev = devname;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *omap_get_bootmmc_devname(void)
|
|
|
|
{
|
|
|
|
return omap_bootmmc_dev;
|
|
|
|
}
|
|
|
|
|
2015-11-04 21:10:20 +00:00
|
|
|
#if defined(CONFIG_ENV_HANDLING)
|
|
|
|
#define ENV_PATH "/boot/barebox.env"
|
2013-04-02 12:48:07 +00:00
|
|
|
static int omap_env_init(void)
|
|
|
|
{
|
2013-09-25 10:30:18 +00:00
|
|
|
char *partname;
|
|
|
|
const char *diskdev;
|
2013-04-02 12:48:07 +00:00
|
|
|
int ret;
|
|
|
|
|
2013-04-15 12:03:58 +00:00
|
|
|
if (bootsource_get() != BOOTSOURCE_MMC)
|
2013-04-02 12:48:07 +00:00
|
|
|
return 0;
|
|
|
|
|
2013-08-24 10:48:50 +00:00
|
|
|
if (omap_bootmmc_dev)
|
|
|
|
diskdev = omap_bootmmc_dev;
|
|
|
|
else
|
|
|
|
diskdev = "disk0";
|
|
|
|
|
|
|
|
device_detect_by_name(diskdev);
|
|
|
|
|
2016-04-11 14:52:10 +00:00
|
|
|
partname = basprintf("/dev/%s.0", diskdev);
|
2013-08-24 10:48:50 +00:00
|
|
|
|
2013-04-02 12:48:07 +00:00
|
|
|
mkdir("/boot", 0666);
|
2015-11-10 07:58:16 +00:00
|
|
|
ret = mount(partname, "fat", "/boot", NULL);
|
2013-04-02 12:48:07 +00:00
|
|
|
if (ret) {
|
2015-11-10 07:58:16 +00:00
|
|
|
pr_err("Failed to load environment: mount %s failed (%d)\n", partname, ret);
|
|
|
|
goto out;
|
2013-04-02 12:48:07 +00:00
|
|
|
}
|
|
|
|
|
2015-11-10 07:58:16 +00:00
|
|
|
pr_debug("Loading default env from %s on device %s\n", ENV_PATH, partname);
|
2015-11-04 21:10:20 +00:00
|
|
|
default_environment_path_set(ENV_PATH);
|
2013-04-02 12:48:07 +00:00
|
|
|
|
2015-11-10 07:58:16 +00:00
|
|
|
out:
|
|
|
|
free(partname);
|
|
|
|
|
2013-04-02 12:48:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
late_initcall(omap_env_init);
|
|
|
|
#endif
|
2013-11-21 14:04:35 +00:00
|
|
|
|
2013-11-22 13:27:43 +00:00
|
|
|
static int omap_soc_from_dt(void)
|
|
|
|
{
|
|
|
|
if (of_machine_is_compatible("ti,am33xx"))
|
|
|
|
return OMAP_CPU_AM33XX;
|
|
|
|
if (of_machine_is_compatible("ti,omap4"))
|
|
|
|
return OMAP_CPU_OMAP4;
|
|
|
|
if (of_machine_is_compatible("ti,omap3"))
|
|
|
|
return OMAP_CPU_OMAP3;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omap_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct device_node *root;
|
|
|
|
|
|
|
|
root = of_get_root_node();
|
|
|
|
if (root) {
|
|
|
|
__omap_cpu_type = omap_soc_from_dt();
|
|
|
|
if (!__omap_cpu_type)
|
|
|
|
hang();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpu_is_omap3())
|
|
|
|
ret = omap3_init();
|
|
|
|
else if (cpu_is_omap4())
|
|
|
|
ret = omap4_init();
|
|
|
|
else if (cpu_is_am33xx())
|
|
|
|
ret = am33xx_init();
|
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (root)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (cpu_is_omap3())
|
|
|
|
ret = omap3_devices_init();
|
|
|
|
else if (cpu_is_omap4())
|
|
|
|
ret = omap4_devices_init();
|
|
|
|
else if (cpu_is_am33xx())
|
|
|
|
ret = am33xx_devices_init();
|
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
postcore_initcall(omap_init);
|