From efb6bc76553ca8c425a3c6683fbf2790d030064e Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Mon, 4 Nov 2013 11:24:30 -0800 Subject: Pad jump tags to 4 bytes inside the system module That way all the users of jump tags don't need to know about the padding requirements. BUG=chrome-os-partner:23851 BRANCH=none TEST=enable CONFIG_CMD_JUMPTAGS, then 'jumptags'. Output should be something like this: 20007fbc: 0x5550 UP.1 2 20007fc4: 0x4b42 KB.2 3 20007fcc: 0x4c50 LP.1 12 20007fdc: 0x4d54 MT.1 8 All the addresses in the first column should be word-aligned. The sizes in the last column don't need to be a multiple of 4. Change-Id: I91f9c29701a007ef8a56b5b7e0ea09930dfbea31 Signed-off-by: Randall Spangler Reviewed-on: https://chromium-review.googlesource.com/175591 Reviewed-by: Bill Richardson --- common/fan.c | 1 - common/keyboard_8042.c | 1 - common/pwm_kblight.c | 1 - common/system.c | 47 +++++++++++++++++++++++++++++++++++++------ common/usb_port_power_dumb.c | 1 - common/usb_port_power_smart.c | 2 -- include/config.h | 1 + include/system.h | 5 ++--- 8 files changed, 44 insertions(+), 15 deletions(-) diff --git a/common/fan.c b/common/fan.c index b080253944..9d9c0f68fc 100644 --- a/common/fan.c +++ b/common/fan.c @@ -339,7 +339,6 @@ BUILD_ASSERT(CONFIG_FANS <= EC_FAN_SPEED_ENTRIES); struct pwm_fan_state { uint16_t fan_rpm; uint8_t fan_en; - char pad; /* Pad to multiple of 4 bytes. */ }; static void pwm_fan_init(void) diff --git a/common/keyboard_8042.c b/common/keyboard_8042.c index 566864e958..c3791e0068 100644 --- a/common/keyboard_8042.c +++ b/common/keyboard_8042.c @@ -148,7 +148,6 @@ struct kb_state { uint8_t codeset; uint8_t ctlram; uint8_t keystroke_enabled; - uint8_t pad; /* Pad to 4 bytes for system_add_jump_tag(). */ }; /* The standard Chrome OS keyboard matrix table. */ diff --git a/common/pwm_kblight.c b/common/pwm_kblight.c index 41448ce7e8..5f84dd66af 100644 --- a/common/pwm_kblight.c +++ b/common/pwm_kblight.c @@ -21,7 +21,6 @@ struct pwm_kbd_state { uint8_t kblight_en; uint8_t kblight_percent; - uint8_t pad0, pad1; /* Pad to multiple of 4 bytes. */ }; /*****************************************************************************/ diff --git a/common/system.c b/common/system.c index db91d1a6b6..b09d804891 100644 --- a/common/system.c +++ b/common/system.c @@ -27,10 +27,16 @@ #define CPUTS(outstr) cputs(CC_SYSTEM, outstr) #define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args) +/* Round up to a multiple of 4 */ +#define ROUNDUP4(x) (((x) + 3) & ~3) + +/* Data for an individual jump tag */ struct jump_tag { - uint16_t tag; - uint8_t data_size; - uint8_t data_version; + uint16_t tag; /* Tag ID */ + uint8_t data_size; /* Size of data which follows */ + uint8_t data_version; /* Data version */ + + /* Followed by data_size bytes of data */ }; /* @@ -171,9 +177,9 @@ int system_add_jump_tag(uint16_t tag, int version, int size, const void *data) return EC_ERROR_UNKNOWN; /* Make room for the new tag */ - if (size > 255 || (size & 3)) + if (size > 255) return EC_ERROR_INVAL; - jdata->jump_tag_total += size + sizeof(struct jump_tag); + jdata->jump_tag_total += ROUNDUP4(size) + sizeof(struct jump_tag); t = (struct jump_tag *)system_usable_ram_end(); t->tag = tag; @@ -197,7 +203,7 @@ const uint8_t *system_get_jump_tag(uint16_t tag, int *version, int *size) while (used < jdata->jump_tag_total) { /* Check the next tag */ t = (const struct jump_tag *)(system_usable_ram_end() + used); - used += sizeof(struct jump_tag) + t->data_size; + used += sizeof(struct jump_tag) + ROUNDUP4(t->data_size); if (t->tag != tag) continue; @@ -814,6 +820,35 @@ DECLARE_CONSOLE_COMMAND(sleepmask, command_sleepmask, NULL); #endif +#ifdef CONFIG_CMD_JUMPTAGS +static int command_jumptags(int argc, char **argv) +{ + const struct jump_tag *t; + int used = 0; + + /* Jump tags valid only after a sysjump */ + if (!jdata) + return EC_SUCCESS; + + while (used < jdata->jump_tag_total) { + /* Check the next tag */ + t = (const struct jump_tag *)(system_usable_ram_end() + used); + used += sizeof(struct jump_tag) + ROUNDUP4(t->data_size); + + ccprintf("%08x: 0x%04x %c%c.%d %3d\n", + (uintptr_t)t, + t->tag, t->tag >> 8, (uint8_t)t->tag, + t->data_version, t->data_size); + } + + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(jumptags, command_jumptags, + NULL, + "List jump tags", + NULL); +#endif /* CONFIG_CMD_JUMPTAGS */ + /*****************************************************************************/ /* Host commands */ diff --git a/common/usb_port_power_dumb.c b/common/usb_port_power_dumb.c index 62ac0732f6..8c4081dd6d 100644 --- a/common/usb_port_power_dumb.c +++ b/common/usb_port_power_dumb.c @@ -26,7 +26,6 @@ BUILD_ASSERT(USB_PORT_COUNT == 2); static struct usb_state { uint8_t en[USB_PORT_COUNT]; - uint8_t pad[2]; /* Pad to 4 bytes for system_add_jump_tag(). */ } state; static void usb_port_set_enabled(int port_id, int en) diff --git a/common/usb_port_power_smart.c b/common/usb_port_power_smart.c index def565239a..6a60e8a04f 100644 --- a/common/usb_port_power_smart.c +++ b/common/usb_port_power_smart.c @@ -26,8 +26,6 @@ /* The previous USB port state before sys jump */ struct usb_state { uint8_t port_mode[USB_CHARGE_PORT_COUNT]; - /* Pad to 4 bytes for system_add_jump_tag(). */ - uint8_t pad[4 - USB_CHARGE_PORT_COUNT]; }; static uint8_t charge_mode[USB_CHARGE_PORT_COUNT]; diff --git a/include/config.h b/include/config.h index 32bb725e11..97262e78d2 100644 --- a/include/config.h +++ b/include/config.h @@ -208,6 +208,7 @@ #undef CONFIG_CMD_ECTEMP #undef CONFIG_CMD_GSV #undef CONFIG_CMD_ILIM +#undef CONFIG_CMD_JUMPTAGS #undef CONFIG_CMD_PLL #undef CONFIG_CMD_PMU #undef CONFIG_CMD_POWERLED diff --git a/include/system.h b/include/system.h index cf936d64bf..b4c68bd3ce 100644 --- a/include/system.h +++ b/include/system.h @@ -109,8 +109,7 @@ int system_jumped_to_this_image(void); * This may ONLY be called from within a HOOK_SYSJUMP handler. * * @param tag Data type - * @param size Size of data; must be a multiple of 4 bytes, and less - * than 255 bytes. + * @param size Size of data; must be less than 255 bytes. * @param version Data version, so that tag data can evolve as firmware * is updated. * @param data Pointer to data to save @@ -128,7 +127,7 @@ int system_add_jump_tag(uint16_t tag, int version, int size, const void *data); * @param version Set to data version if successful * @param size Set to data size if successful * @return A pointer to the data, or NULL if no matching tag is - * found. + * found. This pointer will be 32-bit aligned. */ const uint8_t *system_get_jump_tag(uint16_t tag, int *version, int *size); -- cgit v1.2.1