From dfc93db131830fa50ebdd1f102c0f74b4cad1380 Mon Sep 17 00:00:00 2001 From: Bernhard Nortmann Date: Sun, 20 Nov 2016 21:29:11 +0100 Subject: [PATCH] fel_lib: Add a human-readable SoC name field to the device handle open_fel_device() will automatically provide this member field, based on the SoC ID from FEL/BROM version data. The field will either receive a human-readable identifier, or the ID in 4-digit hexadecimal representation (for unknown SoCs). Signed-off-by: Bernhard Nortmann --- fel.c | 26 +++++++------------------- fel_lib.c | 1 + fel_lib.h | 1 + soc_info.c | 28 ++++++++++++++++++++++++++++ soc_info.h | 8 ++++++++ 5 files changed, 45 insertions(+), 19 deletions(-) diff --git a/fel.c b/fel.c index 8877066..63d6745 100644 --- a/fel.c +++ b/fel.c @@ -86,22 +86,10 @@ int get_image_type(const uint8_t *buf, size_t len) void aw_fel_print_version(feldev_handle *dev) { struct aw_fel_version buf = dev->soc_version; + const char *soc_name = dev->soc_name; - const char *soc_name="unknown"; - switch (buf.soc_id) { - case 0x1623: soc_name="A10"; break; - case 0x1625: soc_name="A13"; break; - case 0x1633: soc_name="A31"; break; - case 0x1651: soc_name="A20"; break; - case 0x1650: soc_name="A23"; break; - case 0x1689: soc_name="A64"; break; - case 0x1639: soc_name="A80"; break; - case 0x1667: soc_name="A33"; break; - case 0x1673: soc_name="A83T"; break; - case 0x1680: soc_name="H3"; break; - case 0x1701: soc_name="R40"; break; - case 0x1718: soc_name="H5"; break; - } + if (soc_name[0] == '0') /* hexadecimal ID -> unknown SoC */ + soc_name = "unknown"; printf("%.8s soc=%08x(%s) %08x ver=%04x %02x %02x scratchpad=%08x %08x %08x\n", buf.signature, buf.soc_id, soc_name, buf.unknown_0a, @@ -314,8 +302,8 @@ void aw_fel_print_sid(feldev_handle *dev) for (i = 0; i <= 3; i++) printf("%08x%c", key[i], i < 3 ? ':' : '\n'); } else { - printf("SID registers for your SoC (id=%04X) are unknown or inaccessible.\n", - soc_info->soc_id); + printf("SID registers for your SoC (%s) are unknown or inaccessible.\n", + dev->soc_name); } } @@ -894,8 +882,8 @@ void aw_rmr_request(feldev_handle *dev, uint32_t entry_point, bool aarch64) soc_info_t *soc_info = dev->soc_info; if (!soc_info->rvbar_reg) { fprintf(stderr, "ERROR: Can't issue RMR request!\n" - "RVBAR is not supported or unknown for your SoC (id=%04X).\n", - soc_info->soc_id); + "RVBAR is not supported or unknown for your SoC (%s).\n", + dev->soc_name); return; } diff --git a/fel_lib.c b/fel_lib.c index 0c1b371..142242c 100644 --- a/fel_lib.c +++ b/fel_lib.c @@ -516,6 +516,7 @@ feldev_handle *feldev_open(int busnum, int devnum, /* retrieve BROM version and SoC information */ aw_fel_get_version(result, &result->soc_version); + get_soc_name_from_id(result->soc_name, result->soc_version.soc_id); result->soc_info = get_soc_info_from_version(&result->soc_version); return result; diff --git a/fel_lib.h b/fel_lib.h index 4ca0d96..894eb6d 100644 --- a/fel_lib.h +++ b/fel_lib.h @@ -32,6 +32,7 @@ typedef struct _felusb_handle felusb_handle; /* opaque data type */ typedef struct { felusb_handle *usb; struct aw_fel_version soc_version; + soc_name_t soc_name; soc_info_t *soc_info; } feldev_handle; diff --git a/soc_info.c b/soc_info.c index 80199eb..13f9884 100644 --- a/soc_info.c +++ b/soc_info.c @@ -23,6 +23,7 @@ #include "soc_info.h" #include +#include #include /* @@ -97,6 +98,7 @@ sram_swap_buffers a80_sram_swap_buffers[] = { soc_info_t soc_info_table[] = { { .soc_id = 0x1623, /* Allwinner A10 */ + .name = "A10", .scratch_addr = 0x1000, .thunk_addr = 0xA200, .thunk_size = 0x200, .swap_buffers = a10_a13_a20_sram_swap_buffers, @@ -104,6 +106,7 @@ soc_info_t soc_info_table[] = { .sid_addr = 0x01C23800, },{ .soc_id = 0x1625, /* Allwinner A10s, A13, R8 */ + .name = "A13", .scratch_addr = 0x1000, .thunk_addr = 0xA200, .thunk_size = 0x200, .swap_buffers = a10_a13_a20_sram_swap_buffers, @@ -111,29 +114,34 @@ soc_info_t soc_info_table[] = { .sid_addr = 0x01C23800, },{ .soc_id = 0x1651, /* Allwinner A20 */ + .name = "A20", .scratch_addr = 0x1000, .thunk_addr = 0xA200, .thunk_size = 0x200, .swap_buffers = a10_a13_a20_sram_swap_buffers, .sid_addr = 0x01C23800, },{ .soc_id = 0x1650, /* Allwinner A23 */ + .name = "A23", .scratch_addr = 0x1000, .thunk_addr = 0x46E00, .thunk_size = 0x200, .swap_buffers = ar100_abusing_sram_swap_buffers, .sid_addr = 0x01C23800, },{ .soc_id = 0x1633, /* Allwinner A31 */ + .name = "A31", .scratch_addr = 0x1000, .thunk_addr = 0x22E00, .thunk_size = 0x200, .swap_buffers = a31_sram_swap_buffers, },{ .soc_id = 0x1667, /* Allwinner A33, R16 */ + .name = "A33", .scratch_addr = 0x1000, .thunk_addr = 0x46E00, .thunk_size = 0x200, .swap_buffers = ar100_abusing_sram_swap_buffers, .sid_addr = 0x01C23800, },{ .soc_id = 0x1689, /* Allwinner A64 */ + .name = "A64", .spl_addr = 0x10000, .scratch_addr = 0x11000, .thunk_addr = 0x1A200, .thunk_size = 0x200, @@ -142,6 +150,7 @@ soc_info_t soc_info_table[] = { .rvbar_reg = 0x017000A0, },{ .soc_id = 0x1639, /* Allwinner A80 */ + .name = "A80", .spl_addr = 0x10000, .scratch_addr = 0x11000, .thunk_addr = 0x23400, .thunk_size = 0x200, @@ -149,12 +158,14 @@ soc_info_t soc_info_table[] = { .sid_addr = 0x01c0e200, },{ .soc_id = 0x1673, /* Allwinner A83T */ + .name = "A83T", .scratch_addr = 0x1000, .thunk_addr = 0x46E00, .thunk_size = 0x200, .swap_buffers = ar100_abusing_sram_swap_buffers, .sid_addr = 0x01C14200, },{ .soc_id = 0x1680, /* Allwinner H3, H2+ */ + .name = "H3", .scratch_addr = 0x1000, .mmu_tt_addr = 0x8000, .thunk_addr = 0xA200, .thunk_size = 0x200, @@ -162,6 +173,7 @@ soc_info_t soc_info_table[] = { .sid_addr = 0x01C14200, },{ .soc_id = 0x1718, /* Allwinner H5 */ + .name = "H5", .spl_addr = 0x10000, .scratch_addr = 0x11000, .thunk_addr = 0x1A200, .thunk_size = 0x200, @@ -170,6 +182,7 @@ soc_info_t soc_info_table[] = { .rvbar_reg = 0x017000A0, },{ .soc_id = 0x1701, /* Allwinner R40 */ + .name = "R40", .scratch_addr = 0x1000, .thunk_addr = 0xA200, .thunk_size = 0x200, .swap_buffers = a10_a13_a20_sram_swap_buffers, @@ -225,3 +238,18 @@ soc_info_t *get_soc_info_from_version(struct aw_fel_version *buf) { return get_soc_info_from_id(buf->soc_id); } + +void get_soc_name_from_id(soc_name_t buffer, uint32_t soc_id) +{ + int i; + for (i = 0; soc_info_table[i].swap_buffers; i++) + if (soc_info_table[i].soc_id == soc_id + && soc_info_table[i].name != NULL) { + strncpy(buffer, soc_info_table[i].name, + sizeof(soc_name_t) - 1); + return; + } + + /* unknown SoC (or name string missing), use the hexadecimal ID */ + snprintf(buffer, sizeof(soc_name_t) - 1, "0x%04X", soc_id); +} diff --git a/soc_info.h b/soc_info.h index 99a4ce5..e602bd9 100644 --- a/soc_info.h +++ b/soc_info.h @@ -33,6 +33,12 @@ struct aw_fel_version { uint32_t pad[2]; /* unused */ } __attribute__((packed)); +/* + * Buffer for a SoC name string. We want at least 6 + 1 characters, to store + * the hexadecimal ID "0xABCD" for unknown SoCs, plus the terminating NUL. + */ +typedef char soc_name_t[8]; + /* * The 'sram_swap_buffers' structure is used to describe information about * pairwise memory regions in SRAM, the content of which needs to be exchanged @@ -69,6 +75,7 @@ typedef struct { */ typedef struct { uint32_t soc_id; /* ID of the SoC */ + const char *name; /* human-readable SoC name string */ uint32_t spl_addr; /* SPL load address */ uint32_t scratch_addr; /* A safe place to upload & run code */ uint32_t thunk_addr; /* Address of the thunk code */ @@ -81,6 +88,7 @@ typedef struct { } soc_info_t; +void get_soc_name_from_id(soc_name_t buffer, uint32_t soc_id); soc_info_t *get_soc_info_from_id(uint32_t soc_id); soc_info_t *get_soc_info_from_version(struct aw_fel_version *buf);