Commit dfc93db1 authored by Bernhard Nortmann's avatar Bernhard Nortmann
Browse files

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: default avatarBernhard Nortmann <bernhard.nortmann@web.de>
parent feccad13
...@@ -86,22 +86,10 @@ int get_image_type(const uint8_t *buf, size_t len) ...@@ -86,22 +86,10 @@ int get_image_type(const uint8_t *buf, size_t len)
void aw_fel_print_version(feldev_handle *dev) void aw_fel_print_version(feldev_handle *dev)
{ {
struct aw_fel_version buf = dev->soc_version; struct aw_fel_version buf = dev->soc_version;
const char *soc_name = dev->soc_name;
const char *soc_name="unknown"; if (soc_name[0] == '0') /* hexadecimal ID -> unknown SoC */
switch (buf.soc_id) { soc_name = "unknown";
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;
}
printf("%.8s soc=%08x(%s) %08x ver=%04x %02x %02x scratchpad=%08x %08x %08x\n", 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, buf.signature, buf.soc_id, soc_name, buf.unknown_0a,
...@@ -314,8 +302,8 @@ void aw_fel_print_sid(feldev_handle *dev) ...@@ -314,8 +302,8 @@ void aw_fel_print_sid(feldev_handle *dev)
for (i = 0; i <= 3; i++) for (i = 0; i <= 3; i++)
printf("%08x%c", key[i], i < 3 ? ':' : '\n'); printf("%08x%c", key[i], i < 3 ? ':' : '\n');
} else { } else {
printf("SID registers for your SoC (id=%04X) are unknown or inaccessible.\n", printf("SID registers for your SoC (%s) are unknown or inaccessible.\n",
soc_info->soc_id); dev->soc_name);
} }
} }
...@@ -894,8 +882,8 @@ void aw_rmr_request(feldev_handle *dev, uint32_t entry_point, bool aarch64) ...@@ -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; soc_info_t *soc_info = dev->soc_info;
if (!soc_info->rvbar_reg) { if (!soc_info->rvbar_reg) {
fprintf(stderr, "ERROR: Can't issue RMR request!\n" fprintf(stderr, "ERROR: Can't issue RMR request!\n"
"RVBAR is not supported or unknown for your SoC (id=%04X).\n", "RVBAR is not supported or unknown for your SoC (%s).\n",
soc_info->soc_id); dev->soc_name);
return; return;
} }
......
...@@ -516,6 +516,7 @@ feldev_handle *feldev_open(int busnum, int devnum, ...@@ -516,6 +516,7 @@ feldev_handle *feldev_open(int busnum, int devnum,
/* retrieve BROM version and SoC information */ /* retrieve BROM version and SoC information */
aw_fel_get_version(result, &result->soc_version); 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); result->soc_info = get_soc_info_from_version(&result->soc_version);
return result; return result;
......
...@@ -32,6 +32,7 @@ typedef struct _felusb_handle felusb_handle; /* opaque data type */ ...@@ -32,6 +32,7 @@ typedef struct _felusb_handle felusb_handle; /* opaque data type */
typedef struct { typedef struct {
felusb_handle *usb; felusb_handle *usb;
struct aw_fel_version soc_version; struct aw_fel_version soc_version;
soc_name_t soc_name;
soc_info_t *soc_info; soc_info_t *soc_info;
} feldev_handle; } feldev_handle;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "soc_info.h" #include "soc_info.h"
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
/* /*
...@@ -97,6 +98,7 @@ sram_swap_buffers a80_sram_swap_buffers[] = { ...@@ -97,6 +98,7 @@ sram_swap_buffers a80_sram_swap_buffers[] = {
soc_info_t soc_info_table[] = { soc_info_t soc_info_table[] = {
{ {
.soc_id = 0x1623, /* Allwinner A10 */ .soc_id = 0x1623, /* Allwinner A10 */
.name = "A10",
.scratch_addr = 0x1000, .scratch_addr = 0x1000,
.thunk_addr = 0xA200, .thunk_size = 0x200, .thunk_addr = 0xA200, .thunk_size = 0x200,
.swap_buffers = a10_a13_a20_sram_swap_buffers, .swap_buffers = a10_a13_a20_sram_swap_buffers,
...@@ -104,6 +106,7 @@ soc_info_t soc_info_table[] = { ...@@ -104,6 +106,7 @@ soc_info_t soc_info_table[] = {
.sid_addr = 0x01C23800, .sid_addr = 0x01C23800,
},{ },{
.soc_id = 0x1625, /* Allwinner A10s, A13, R8 */ .soc_id = 0x1625, /* Allwinner A10s, A13, R8 */
.name = "A13",
.scratch_addr = 0x1000, .scratch_addr = 0x1000,
.thunk_addr = 0xA200, .thunk_size = 0x200, .thunk_addr = 0xA200, .thunk_size = 0x200,
.swap_buffers = a10_a13_a20_sram_swap_buffers, .swap_buffers = a10_a13_a20_sram_swap_buffers,
...@@ -111,29 +114,34 @@ soc_info_t soc_info_table[] = { ...@@ -111,29 +114,34 @@ soc_info_t soc_info_table[] = {
.sid_addr = 0x01C23800, .sid_addr = 0x01C23800,
},{ },{
.soc_id = 0x1651, /* Allwinner A20 */ .soc_id = 0x1651, /* Allwinner A20 */
.name = "A20",
.scratch_addr = 0x1000, .scratch_addr = 0x1000,
.thunk_addr = 0xA200, .thunk_size = 0x200, .thunk_addr = 0xA200, .thunk_size = 0x200,
.swap_buffers = a10_a13_a20_sram_swap_buffers, .swap_buffers = a10_a13_a20_sram_swap_buffers,
.sid_addr = 0x01C23800, .sid_addr = 0x01C23800,
},{ },{
.soc_id = 0x1650, /* Allwinner A23 */ .soc_id = 0x1650, /* Allwinner A23 */
.name = "A23",
.scratch_addr = 0x1000, .scratch_addr = 0x1000,
.thunk_addr = 0x46E00, .thunk_size = 0x200, .thunk_addr = 0x46E00, .thunk_size = 0x200,
.swap_buffers = ar100_abusing_sram_swap_buffers, .swap_buffers = ar100_abusing_sram_swap_buffers,
.sid_addr = 0x01C23800, .sid_addr = 0x01C23800,
},{ },{
.soc_id = 0x1633, /* Allwinner A31 */ .soc_id = 0x1633, /* Allwinner A31 */
.name = "A31",
.scratch_addr = 0x1000, .scratch_addr = 0x1000,
.thunk_addr = 0x22E00, .thunk_size = 0x200, .thunk_addr = 0x22E00, .thunk_size = 0x200,
.swap_buffers = a31_sram_swap_buffers, .swap_buffers = a31_sram_swap_buffers,
},{ },{
.soc_id = 0x1667, /* Allwinner A33, R16 */ .soc_id = 0x1667, /* Allwinner A33, R16 */
.name = "A33",
.scratch_addr = 0x1000, .scratch_addr = 0x1000,
.thunk_addr = 0x46E00, .thunk_size = 0x200, .thunk_addr = 0x46E00, .thunk_size = 0x200,
.swap_buffers = ar100_abusing_sram_swap_buffers, .swap_buffers = ar100_abusing_sram_swap_buffers,
.sid_addr = 0x01C23800, .sid_addr = 0x01C23800,
},{ },{
.soc_id = 0x1689, /* Allwinner A64 */ .soc_id = 0x1689, /* Allwinner A64 */
.name = "A64",
.spl_addr = 0x10000, .spl_addr = 0x10000,
.scratch_addr = 0x11000, .scratch_addr = 0x11000,
.thunk_addr = 0x1A200, .thunk_size = 0x200, .thunk_addr = 0x1A200, .thunk_size = 0x200,
...@@ -142,6 +150,7 @@ soc_info_t soc_info_table[] = { ...@@ -142,6 +150,7 @@ soc_info_t soc_info_table[] = {
.rvbar_reg = 0x017000A0, .rvbar_reg = 0x017000A0,
},{ },{
.soc_id = 0x1639, /* Allwinner A80 */ .soc_id = 0x1639, /* Allwinner A80 */
.name = "A80",
.spl_addr = 0x10000, .spl_addr = 0x10000,
.scratch_addr = 0x11000, .scratch_addr = 0x11000,
.thunk_addr = 0x23400, .thunk_size = 0x200, .thunk_addr = 0x23400, .thunk_size = 0x200,
...@@ -149,12 +158,14 @@ soc_info_t soc_info_table[] = { ...@@ -149,12 +158,14 @@ soc_info_t soc_info_table[] = {
.sid_addr = 0x01c0e200, .sid_addr = 0x01c0e200,
},{ },{
.soc_id = 0x1673, /* Allwinner A83T */ .soc_id = 0x1673, /* Allwinner A83T */
.name = "A83T",
.scratch_addr = 0x1000, .scratch_addr = 0x1000,
.thunk_addr = 0x46E00, .thunk_size = 0x200, .thunk_addr = 0x46E00, .thunk_size = 0x200,
.swap_buffers = ar100_abusing_sram_swap_buffers, .swap_buffers = ar100_abusing_sram_swap_buffers,
.sid_addr = 0x01C14200, .sid_addr = 0x01C14200,
},{ },{
.soc_id = 0x1680, /* Allwinner H3, H2+ */ .soc_id = 0x1680, /* Allwinner H3, H2+ */
.name = "H3",
.scratch_addr = 0x1000, .scratch_addr = 0x1000,
.mmu_tt_addr = 0x8000, .mmu_tt_addr = 0x8000,
.thunk_addr = 0xA200, .thunk_size = 0x200, .thunk_addr = 0xA200, .thunk_size = 0x200,
...@@ -162,6 +173,7 @@ soc_info_t soc_info_table[] = { ...@@ -162,6 +173,7 @@ soc_info_t soc_info_table[] = {
.sid_addr = 0x01C14200, .sid_addr = 0x01C14200,
},{ },{
.soc_id = 0x1718, /* Allwinner H5 */ .soc_id = 0x1718, /* Allwinner H5 */
.name = "H5",
.spl_addr = 0x10000, .spl_addr = 0x10000,
.scratch_addr = 0x11000, .scratch_addr = 0x11000,
.thunk_addr = 0x1A200, .thunk_size = 0x200, .thunk_addr = 0x1A200, .thunk_size = 0x200,
...@@ -170,6 +182,7 @@ soc_info_t soc_info_table[] = { ...@@ -170,6 +182,7 @@ soc_info_t soc_info_table[] = {
.rvbar_reg = 0x017000A0, .rvbar_reg = 0x017000A0,
},{ },{
.soc_id = 0x1701, /* Allwinner R40 */ .soc_id = 0x1701, /* Allwinner R40 */
.name = "R40",
.scratch_addr = 0x1000, .scratch_addr = 0x1000,
.thunk_addr = 0xA200, .thunk_size = 0x200, .thunk_addr = 0xA200, .thunk_size = 0x200,
.swap_buffers = a10_a13_a20_sram_swap_buffers, .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) ...@@ -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); 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);
}
...@@ -33,6 +33,12 @@ struct aw_fel_version { ...@@ -33,6 +33,12 @@ struct aw_fel_version {
uint32_t pad[2]; /* unused */ uint32_t pad[2]; /* unused */
} __attribute__((packed)); } __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 * The 'sram_swap_buffers' structure is used to describe information about
* pairwise memory regions in SRAM, the content of which needs to be exchanged * pairwise memory regions in SRAM, the content of which needs to be exchanged
...@@ -69,6 +75,7 @@ typedef struct { ...@@ -69,6 +75,7 @@ typedef struct {
*/ */
typedef struct { typedef struct {
uint32_t soc_id; /* ID of the SoC */ 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 spl_addr; /* SPL load address */
uint32_t scratch_addr; /* A safe place to upload & run code */ uint32_t scratch_addr; /* A safe place to upload & run code */
uint32_t thunk_addr; /* Address of the thunk code */ uint32_t thunk_addr; /* Address of the thunk code */
...@@ -81,6 +88,7 @@ typedef struct { ...@@ -81,6 +88,7 @@ typedef struct {
} soc_info_t; } 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_id(uint32_t soc_id);
soc_info_t *get_soc_info_from_version(struct aw_fel_version *buf); soc_info_t *get_soc_info_from_version(struct aw_fel_version *buf);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment