summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/date.c18
-rw-r--r--common/environment.c19
-rw-r--r--common/partitions.c20
-rw-r--r--common/partitions/Kconfig1
-rw-r--r--common/partitions/efi.c1
-rw-r--r--common/startup.c5
-rw-r--r--common/state.c25
7 files changed, 64 insertions, 25 deletions
diff --git a/common/date.c b/common/date.c
index 6b6b7ab495..129192e232 100644
--- a/common/date.c
+++ b/common/date.c
@@ -148,3 +148,21 @@ mktime (unsigned int year, unsigned int mon,
)*60 + min /* now have minutes */
)*60 + sec; /* finally seconds */
}
+
+const char *time_str(struct rtc_time *tm)
+{
+ const char *weekdays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
+ const char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
+ "Sep", "Oct", "Nov", "Dec" };
+ static char buf[128];
+
+ sprintf(buf, "%s %02d %s %4d %02d:%02d:%02d",
+ weekdays[tm->tm_wday],
+ tm->tm_mday,
+ months[tm->tm_mon],
+ tm->tm_year + 1900,
+ tm->tm_hour,
+ tm->tm_min,
+ tm->tm_sec);
+ return buf;
+}
diff --git a/common/environment.c b/common/environment.c
index f412e62258..9cf44a0f06 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -23,7 +23,6 @@
* the default environment when building the barebox binary. So
* do not add any new barebox related functions here!
*/
-
#ifdef __BAREBOX__
#include <common.h>
#include <command.h>
@@ -417,6 +416,7 @@ static int envfs_load_data(struct envfs_super *super, void *buf, size_t size,
int headerlen_full;
/* for envfs < 1.0 */
struct envfs_inode_end inode_end_dummy;
+ struct stat s;
inode_end_dummy.mode = ENVFS_32(S_IRWXU | S_IRWXG | S_IRWXO);
inode_end_dummy.magic = ENVFS_32(ENVFS_INODE_END_MAGIC);
@@ -460,11 +460,20 @@ static int envfs_load_data(struct envfs_super *super, void *buf, size_t size,
make_directory(dirname(tmp));
free(tmp);
+ ret = stat(str, &s);
+ if (!ret && (flags & ENV_FLAG_NO_OVERWRITE)) {
+ printf("skip %s\n", str);
+ goto skip;
+ }
+
if (S_ISLNK(ENVFS_32(inode_end->mode))) {
debug("symlink: %s -> %s\n", str, (char*)buf);
if (!strcmp(buf, basename(str))) {
unlink(str);
} else {
+ if (!ret)
+ unlink(str);
+
ret = symlink(buf, str);
if (ret < 0)
printf("symlink: %s -> %s : %s\n",
@@ -472,14 +481,6 @@ static int envfs_load_data(struct envfs_super *super, void *buf, size_t size,
}
free(str);
} else {
- struct stat s;
-
- if (flags & ENV_FLAG_NO_OVERWRITE &&
- !stat(str, &s)) {
- printf("skip %s\n", str);
- goto skip;
- }
-
fd = open(str, O_WRONLY | O_CREAT | O_TRUNC, 0644);
free(str);
if (fd < 0) {
diff --git a/common/partitions.c b/common/partitions.c
index 4f50bfeff1..82ec508e64 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -71,20 +71,14 @@ static int register_one_partition(struct block_device *blk,
if (!part->name[0])
return 0;
- partition_name = asprintf("%s.%s", blk->cdev.name, part->name);
- if (!partition_name)
- return -ENOMEM;
-
- dev_dbg(blk->dev, "Registering partition %s on drive %s\n",
- partition_name, blk->cdev.name);
- cdev = devfs_add_partition(blk->cdev.name,
- start, size, 0, partition_name);
-
- if (IS_ERR(cdev))
- dev_warn(blk->dev, "Registering partition %s on drive %s failed\n",
- partition_name, blk->cdev.name);
+ partition_name = xasprintf("%s.%s", blk->cdev.name, part->name);
+ ret = devfs_create_link(cdev, partition_name);
+ if (ret)
+ dev_warn(blk->dev, "Failed to create link from %s to %s\n",
+ partition_name, blk->cdev.name);
+ free(partition_name);
- ret = 0;
+ return 0;
out:
free(partition_name);
return ret;
diff --git a/common/partitions/Kconfig b/common/partitions/Kconfig
index 90238ad382..be9405a649 100644
--- a/common/partitions/Kconfig
+++ b/common/partitions/Kconfig
@@ -16,6 +16,7 @@ config PARTITION_DISK_DOS
config PARTITION_DISK_EFI
depends on PARTITION_DISK
select CRC32
+ select PRINTF_UUID
bool "EFI: GPT partition support"
help
Add support to handle partitions in GUID Partition Table style.
diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 61abf00050..a9945dd9eb 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -457,6 +457,7 @@ static void efi_partition(void *buf, struct block_device *blk,
pentry->size = le64_to_cpu(ptes[i].ending_lba) - pentry->first_sec;
pentry->size++;
part_set_efi_name(&ptes[i], pentry->name);
+ snprintf(pentry->partuuid, sizeof(pentry->partuuid), "%pUl", &ptes[i].unique_partition_guid);
pd->used_entries++;
}
diff --git a/common/startup.c b/common/startup.c
index 4a303b297a..093a23ba08 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -60,6 +60,11 @@ static int mount_root(void)
mount("none", "efivarfs", "/efivars", NULL);
}
+ if (IS_ENABLED(CONFIG_FS_PSTORE)) {
+ mkdir("/pstore", 0);
+ mount("none", "pstore", "/pstore", NULL);
+ }
+
return 0;
}
fs_initcall(mount_root);
diff --git a/common/state.c b/common/state.c
index ec72dbd9a0..d1fa47ffa3 100644
--- a/common/state.c
+++ b/common/state.c
@@ -66,6 +66,7 @@ enum state_variable_type {
STATE_TYPE_ENUM,
STATE_TYPE_U8,
STATE_TYPE_U32,
+ STATE_TYPE_S32,
STATE_TYPE_MAC,
STATE_TYPE_STRING,
};
@@ -209,8 +210,8 @@ static struct state_variable *state_uint8_create(struct state *state,
return &su32->var;
}
-static struct state_variable *state_uint32_create(struct state *state,
- const char *name, struct device_node *node)
+static struct state_variable *state_int32_create(struct state *state,
+ const char *name, struct device_node *node, const char *format)
{
struct state_uint32 *su32;
struct param_d *param;
@@ -218,7 +219,7 @@ static struct state_variable *state_uint32_create(struct state *state,
su32 = xzalloc(sizeof(*su32));
param = dev_add_param_int(&state->dev, name, state_set_dirty,
- NULL, &su32->value, "%u", state);
+ NULL, &su32->value, format, state);
if (IS_ERR(param)) {
free(su32);
return ERR_CAST(param);
@@ -231,6 +232,18 @@ static struct state_variable *state_uint32_create(struct state *state,
return &su32->var;
}
+static struct state_variable *state_uint32_create(struct state *state,
+ const char *name, struct device_node *node)
+{
+ return state_int32_create(state, name, node, "%u");
+}
+
+static struct state_variable *state_sint32_create(struct state *state,
+ const char *name, struct device_node *node)
+{
+ return state_int32_create(state, name, node, "%d");
+}
+
/*
* enum32
*/
@@ -605,6 +618,12 @@ static struct variable_type types[] = {
.export = state_string_export,
.import = state_string_import,
.create = state_string_create,
+ }, {
+ .type = STATE_TYPE_S32,
+ .type_name = "int32",
+ .export = state_uint32_export,
+ .import = state_uint32_import,
+ .create = state_sint32_create,
},
};