From 84998e09565a858382a6101c06686e0340743c81 Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Tue, 31 Mar 2020 12:58:00 -0700 Subject: cmsg: use two byte ints to send function name string indices When a string parameter __func__ ie encountered in the source code, the function name is saved in the format strings dictionary, and then packet is prepared, instead of sending the string, a byte of 0xff is sent and then the four byte value which is the string index. But two bytes is enough to send the string index, as it is a 16 bit value by design. This patch modifies both transmit and receive sides to start using 2 byte indices for __func__. BUG=b:149964350 TEST=built the new image, tried running it, observed correct function names in the console output. Signed-off-by: Vadim Bendebury Change-Id: I682dd18cb4dd434e6982d33f1918ef398d5caa20 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2131046 Reviewed-by: Randall Spangler --- common/cmsg.c | 15 +++++++++++---- util/acroterm.py | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/common/cmsg.c b/common/cmsg.c index 3c65e10d42..f14c13b262 100644 --- a/common/cmsg.c +++ b/common/cmsg.c @@ -88,7 +88,8 @@ enum param_types { * Parameter is an int, the number of the function name string in the * dictionary prepared by util_precompile.py. Since it is passed as a * %s parameter, to allow the terminal to tell the difference this - * value is sent as 5 bytes, first 0xff and then the function number. + * value is sent as 3 bytes, first 0xff and then the two byte function + * name string index. */ PARAM_FUNC_NAME = 6, /* @@ -117,6 +118,7 @@ static void copy_params(uint32_t mask, uintptr_t params[], enum param_types param_type; uintptr_t param; uint64_t t; + uint16_t func_num; while ((param_type = mask & 0xf) != 0) { const uint8_t ff = 0xff; @@ -127,7 +129,10 @@ static void copy_params(uint32_t mask, uintptr_t params[], switch (param_type) { case PARAM_FUNC_NAME: cmputc(&ff, sizeof(ff)); - /* fallthrough. */ + func_num = param; + cmputc((const void *) &func_num, sizeof(func_num)); + break; + case PARAM_INT: case PARAM_PTR: cmputc((const void *)¶m, sizeof(param)); @@ -265,8 +270,10 @@ static int zz_msg(enum console_channel chan, int str_index, uint32_t fmt_mask, while (param_type) { switch (param_type) { case PARAM_FUNC_NAME: - total_param_length += 1; - /* Falltrhough. */ + /* 0xff and the 2 byte function name index.*/ + total_param_length += 3; + break; + case PARAM_INT: case PARAM_PTR: total_param_length += sizeof(uintptr_t); diff --git a/util/acroterm.py b/util/acroterm.py index 471e861dfd..a2510244d4 100755 --- a/util/acroterm.py +++ b/util/acroterm.py @@ -1089,9 +1089,9 @@ class Cr50Packet(Packet): if str_param.search(token): if data[0] == 0xff: # This is a function name. - index = uint_struct.unpack_from(data[1:])[0] + index = short_struct.unpack_from(data[1:])[0] st = self.strings[index] - data = data[5:] + data = data[3:] else: eos = data.find(0) param = data[:eos].decode('ascii') -- cgit v1.2.1