[U-Boot] [RFC PATCH] Pre-console buffer for ARM

Graeme Russ graeme.russ at gmail.com
Tue Aug 30 07:28:36 CEST 2011


Hi Wolfgang

On Tue, Aug 30, 2011 at 3:17 PM, Wolfgang Denk <wd at denx.de> wrote:
> Dear Graeme Russ,
>
> In message <CALButCJF1p+60WOLtiJqhcAed-71VxmP2mBqY2wdNURPk5=Q+g at mail.gmail.com> you wrote:
>>
>> >> > it's fairly easy as well:
>> >> > #define CIRC_BUF_IDX(idx) ((idx) & (CONFIG_SYS_TMP_CON_BUF_SZ-1))
>> >> > buffer[CIRC_BUF_IDX(gd->conf_buf_idx++)] = c;
>> >>
>> >> But does that work for non power-of-two buffer sizes...
>> >
>> > no, but not that big of a deal.  so you get limited to the last 1KiB, 4KiB,
>> > 8KiB, 16KiB, etc... amount of data.
>>
>> Until someone doesn't read the documentation and figures they can only
>> squeeze 200 bytes out of their L1 cache after making room for gd and stack
>> and then tries to print 201 bytes of debug info and trashes either the
>> stack or gd and then things start to get a lot weirder than simply having
>> their early debug messgaes clipped...
>>
>> To be safe, CONFIG_SYS_TMP_CON_BUF_SZ would need to be checked for ^2 size
>> and now we only get 128 bytes rather than 200 :( - Better to add another
>> long in gd and get 196
>
> Grrrgh.
>
> If you want to support arbitrary buffer sizes, then just use
>
>        #define CIRC_BUF_IDX(idx) ((idx) % CONFIG_SYS_TMP_CON_BUF_SZ)

I know, but I was concerned that you wouldn't like the use of modulo
arithmetic for every putc() - But I suppose thats cheaper than a compare
plus branch...

If you prefer modulo over the 'must be a power of two' restriction, then
I am happy to do it that way instead

Regards,

Graeme


More information about the U-Boot mailing list