2013-04-03 08:12:11 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Marc Reilly <marc@cpdesign.com.au>
|
|
|
|
* Copyright (C) 2013 Marc Kleine-Budde <mkl@pengutronix.de>
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#include <bootsource.h>
|
|
|
|
#include <environment.h>
|
|
|
|
#include <magicvar.h>
|
2013-04-03 08:12:12 +00:00
|
|
|
#include <init.h>
|
2013-04-03 08:12:11 +00:00
|
|
|
|
|
|
|
static const char *bootsource_str[] = {
|
|
|
|
[BOOTSOURCE_UNKNOWN] = "unknown",
|
|
|
|
[BOOTSOURCE_NAND] = "nand",
|
|
|
|
[BOOTSOURCE_NOR] = "nor",
|
|
|
|
[BOOTSOURCE_MMC] = "mmc",
|
|
|
|
[BOOTSOURCE_I2C] = "i2c",
|
2013-04-03 08:12:14 +00:00
|
|
|
[BOOTSOURCE_I2C_EEPROM] = "i2c-eeprom",
|
2013-04-03 08:12:11 +00:00
|
|
|
[BOOTSOURCE_SPI] = "spi",
|
2013-04-03 08:12:14 +00:00
|
|
|
[BOOTSOURCE_SPI_EEPROM] = "spi-eeprom",
|
|
|
|
[BOOTSOURCE_SPI_NOR] = "spi-nor",
|
2013-04-03 08:12:11 +00:00
|
|
|
[BOOTSOURCE_SERIAL] = "serial",
|
|
|
|
[BOOTSOURCE_ONENAND] = "onenand",
|
|
|
|
[BOOTSOURCE_HD] = "harddisk",
|
2013-04-03 08:12:14 +00:00
|
|
|
[BOOTSOURCE_USB] = "usb",
|
2015-05-26 13:31:44 +00:00
|
|
|
[BOOTSOURCE_NET] = "net",
|
2013-04-03 08:12:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static enum bootsource bootsource = BOOTSOURCE_UNKNOWN;
|
2013-04-03 08:12:13 +00:00
|
|
|
static int bootsource_instance = BOOTSOURCE_INSTANCE_UNKNOWN;
|
2013-04-03 08:12:11 +00:00
|
|
|
|
|
|
|
void bootsource_set(enum bootsource src)
|
|
|
|
{
|
|
|
|
if (src >= ARRAY_SIZE(bootsource_str))
|
|
|
|
src = BOOTSOURCE_UNKNOWN;
|
|
|
|
|
|
|
|
bootsource = src;
|
|
|
|
|
|
|
|
setenv("bootsource", bootsource_str[src]);
|
|
|
|
}
|
|
|
|
|
2013-04-03 08:12:13 +00:00
|
|
|
void bootsource_set_instance(int instance)
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
|
|
|
|
bootsource_instance = instance;
|
|
|
|
|
|
|
|
if (instance < 0)
|
|
|
|
sprintf(buf, "unknown");
|
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "%d", instance);
|
|
|
|
|
|
|
|
setenv("bootsource_instance", buf);
|
|
|
|
}
|
|
|
|
|
2013-04-03 08:12:11 +00:00
|
|
|
enum bootsource bootsource_get(void)
|
|
|
|
{
|
|
|
|
return bootsource;
|
|
|
|
}
|
|
|
|
|
|
|
|
BAREBOX_MAGICVAR(bootsource, "The source barebox has been booted from");
|
2013-04-03 08:12:12 +00:00
|
|
|
|
2013-04-03 08:12:13 +00:00
|
|
|
int bootsource_get_instance(void)
|
|
|
|
{
|
|
|
|
return bootsource_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
BAREBOX_MAGICVAR(bootsource_instance, "The instance of the source barebox has been booted from");
|
|
|
|
|
2013-04-03 08:12:12 +00:00
|
|
|
static int bootsource_init(void)
|
|
|
|
{
|
|
|
|
bootsource_set(bootsource);
|
2013-04-03 08:12:13 +00:00
|
|
|
bootsource_set_instance(bootsource_instance);
|
2013-04-03 08:12:12 +00:00
|
|
|
export("bootsource");
|
2013-04-03 08:12:13 +00:00
|
|
|
export("bootsource_instance");
|
2013-04-03 08:12:12 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
coredevice_initcall(bootsource_init);
|