diff mbox series

core/console.c: Make skiboot fun again

Message ID 20171208022846.28067-1-alistair@popple.id.au
State Rejected
Headers show
Series core/console.c: Make skiboot fun again | expand

Commit Message

Alistair Popple Dec. 8, 2017, 2:28 a.m. UTC
,_         _,
         |\\.-"""-.//|
         \`         `/
        /    _   _    \
        |    a _ a    |
        '.=    Y    =.'
          >._  ^  _.<
         /   `````   \
         )           (
        ,(           ),
       / )   /   \   ( \
       ) (   )   (   ) (
       ( )   (   )   ( )
       )_(   )   (   )_(-.._
      (  )_  (._.)  _(  )_, `\
       ``(   )   (   )`` .' .'
    jgs   ```     ```   ( (`
                         '-'

Skiboot output is pretty dull to look at. Sometimes surprises are nice.
Especially when they are comforting cats. Even more so when they are
rainbow coloured cats. Lol.

Signed-off-by: Alistair Popple <alistair@popple.id.au>
---
 core/console.c            | 62 +++++++++++++++++++++++++++++++++++++++++++++++
 core/init.c               |  4 +++
 include/skiboot.h         |  3 +++
 platforms/astbmc/common.c |  5 ++++
 4 files changed, 74 insertions(+)

Comments

Samuel Mendoza-Jonas Dec. 8, 2017, 2:35 a.m. UTC | #1
On Fri, 2017-12-08 at 13:28 +1100, Alistair Popple wrote:
>          ,_         _,
>          |\\.-"""-.//|
>          \`         `/
>         /    _   _    \
>         |    a _ a    |
>         '.=    Y    =.'
>           >._  ^  _.<
>          /   `````   \
>          )           (
>         ,(           ),
>        / )   /   \   ( \
>        ) (   )   (   ) (
>        ( )   (   )   ( )
>        )_(   )   (   )_(-.._
>       (  )_  (._.)  _(  )_, `\
>        ``(   )   (   )`` .' .'
>     jgs   ```     ```   ( (`
>                          '-'
> 
> Skiboot output is pretty dull to look at. Sometimes surprises are nice.
> Especially when they are comforting cats. Even more so when they are
> rainbow coloured cats. Lol.
> 
> Signed-off-by: Alistair Popple <alistair@popple.id.au>

Aggressively Acked-By: Samuel Mendoza-Jonas <sam@mendozajonas.com>

> ---
>  core/console.c            | 62 +++++++++++++++++++++++++++++++++++++++++++++++
>  core/init.c               |  4 +++
>  include/skiboot.h         |  3 +++
>  platforms/astbmc/common.c |  5 ++++
>  4 files changed, 74 insertions(+)
> 
> diff --git a/core/console.c b/core/console.c
> index b9129c9f..9c344e9e 100644
> --- a/core/console.c
> +++ b/core/console.c
> @@ -235,6 +235,39 @@ static void write_char(char c)
>  	inmem_write(c);
>  }
>  
> +int sine_table[] = {
> +	0x80,0x83,0x86,0x8a,0x8d,0x90,0x93,0x97,
> +	0x9a,0x9d,0xa0,0xa4,0xa7,0xaa,0xad,0xb0,
> +	0xb3,0xb6,0xb9,0xbc,0xbf,0xc2,0xc5,0xc8,
> +	0xca,0xcd,0xd0,0xd2,0xd5,0xd7,0xda,0xdc,
> +	0xde,0xe0,0xe3,0xe5,0xe7,0xe9,0xea,0xec,
> +	0xee,0xf0,0xf1,0xf3,0xf4,0xf5,0xf7,0xf8,
> +	0xf9,0xfa,0xfb,0xfb,0xfc,0xfd,0xfd,0xfe,
> +	0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
> +	0xfe,0xfe,0xfd,0xfd,0xfc,0xfb,0xfb,0xfa,
> +	0xf9,0xf8,0xf7,0xf5,0xf4,0xf3,0xf1,0xf0,
> +	0xee,0xec,0xea,0xe9,0xe7,0xe5,0xe3,0xe0,
> +	0xde,0xdc,0xda,0xd7,0xd5,0xd2,0xd0,0xcd,
> +	0xca,0xc8,0xc5,0xc2,0xbf,0xbc,0xb9,0xb6,
> +	0xb3,0xb0,0xad,0xaa,0xa7,0xa4,0xa0,0x9d,
> +	0x9a,0x97,0x93,0x90,0x8d,0x8a,0x86,0x83,
> +	0x80,0x7c,0x79,0x75,0x72,0x6f,0x6c,0x68,
> +	0x65,0x62,0x5f,0x5b,0x58,0x55,0x52,0x4f,
> +	0x4c,0x49,0x46,0x43,0x40,0x3d,0x3a,0x37,
> +	0x35,0x32,0x2f,0x2d,0x2a,0x28,0x25,0x23,
> +	0x21,0x1f,0x1c,0x1a,0x18,0x16,0x15,0x13,
> +	0x11,0xf,0xe,0xc,0xb,0xa,0x8,0x7,
> +	0x6,0x5,0x4,0x4,0x3,0x2,0x2,0x1,
> +	0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
> +	0x1,0x1,0x2,0x2,0x3,0x4,0x4,0x5,
> +	0x6,0x7,0x8,0xa,0xb,0xc,0xe,0xf,
> +	0x11,0x13,0x15,0x16,0x18,0x1a,0x1c,0x1f,
> +	0x21,0x23,0x25,0x28,0x2a,0x2d,0x2f,0x32,
> +	0x35,0x37,0x3a,0x3d,0x40,0x43,0x46,0x49,
> +	0x4c,0x4f,0x52,0x55,0x58,0x5b,0x5f,0x62,
> +	0x65,0x68,0x6c,0x6f,0x72,0x75,0x79,0x7c };
> +
> +int lolcat = 0;
>  ssize_t console_write(bool flush_to_drivers, const void *buf, size_t count)
>  {
>  	/* We use recursive locking here as we can get called
> @@ -242,12 +275,41 @@ ssize_t console_write(bool flush_to_drivers, const void *buf, size_t count)
>  	 */
>  	bool need_unlock = lock_recursive(&con_lock);
>  	const char *cbuf = buf;
> +	char colour[30];
> +	const char *colour_end = "\x1b[0m";
> +	const char *cc;
> +	int red, green, blue;
> +	static int char_count = 0;
>  
>  	while(count--) {
>  		char c = *(cbuf++);
>  		if (c == '\n')
>  			write_char('\r');
> +
> +		if (lolcat) {
> +			red = sine_table[char_count];
> +			green = sine_table[(char_count + ARRAY_SIZE(sine_table)/3) % ARRAY_SIZE(sine_table)];
> +			blue = sine_table[(char_count + (2*ARRAY_SIZE(sine_table))/3) % ARRAY_SIZE(sine_table)];
> +
> +			snprintf(colour, ARRAY_SIZE(colour), "\x1b[38;2;%03d;%03d;%03dm", red, green, blue);
> +			cc = colour;
> +			while (*cc) {
> +				write_char(*cc);
> +				cc++;
> +			}
> +		}
> +
>  		write_char(c);
> +
> +		if (lolcat) {
> +			cc = colour_end;
> +			while (*cc) {
> +				write_char(*cc);
> +				cc++;
> +				char_count++;
> +				char_count %= ARRAY_SIZE(sine_table);
> +			}
> +		}
>  	}
>  
>  	__flush_console(flush_to_drivers);
> diff --git a/core/init.c b/core/init.c
> index 2eeba759..17c31118 100644
> --- a/core/init.c
> +++ b/core/init.c
> @@ -1002,6 +1002,10 @@ void __noreturn __nomcount main_cpu_entry(const void *fdt)
>  	/* Read in NVRAM and set it up */
>  	nvram_init();
>  
> +	/* Feeling colourful? */
> +	if (!lolcat)
> +		lolcat = !!nvram_query("lolcat");
> +
>  	/* preload the IMC catalog dtb */
>  	imc_catalog_preload();
>  
> diff --git a/include/skiboot.h b/include/skiboot.h
> index db913258..11914a67 100644
> --- a/include/skiboot.h
> +++ b/include/skiboot.h
> @@ -52,6 +52,9 @@ extern struct mem_region *mem_region_next(struct mem_region *region);
>  /* Readonly section start and end. */
>  extern char __rodata_start[], __rodata_end[];
>  
> +/* Enable lolcat mode */
> +extern int lolcat;
> +
>  static inline bool is_rodata(const void *p)
>  {
>  	return ((const char *)p >= __rodata_start && (const char *)p < __rodata_end);
> diff --git a/platforms/astbmc/common.c b/platforms/astbmc/common.c
> index 243ad946..9d6583b0 100644
> --- a/platforms/astbmc/common.c
> +++ b/platforms/astbmc/common.c
> @@ -26,6 +26,7 @@
>  #include <bt.h>
>  #include <errorlog.h>
>  #include <lpc.h>
> +#include <rtc.h>
>  
>  #include "astbmc.h"
>  
> @@ -120,6 +121,8 @@ static int astbmc_fru_init(void)
>  
>  void astbmc_init(void)
>  {
> +	struct tm tm;
> +
>  	/* Initialize PNOR/NVRAM */
>  	pnor_init();
>  
> @@ -131,6 +134,8 @@ void astbmc_init(void)
>  	ipmi_wdt_init();
>  	ipmi_rtc_init();
>  	ipmi_opal_init();
> +	while (rtc_cache_get(&tm)) opal_run_pollers();
> +	lolcat = tm.tm_mon == 11 && tm.tm_mday == 7 && tm.tm_hour == 17 && tm.tm_min == 58;
>  	astbmc_fru_init();
>  	ipmi_sensor_init();
>
Suraj Jitindar Singh Dec. 8, 2017, 2:44 a.m. UTC | #2
On Fri, 2017-12-08 at 13:28 +1100, Alistair Popple wrote:
>          ,_         _,
>          |\\.-"""-.//|
>          \`         `/
>         /    _   _    \
>         |    a _ a    |
>         '.=    Y    =.'
>           >._  ^  _.<
>          /   `````   \
>          )           (
>         ,(           ),
>        / )   /   \   ( \
>        ) (   )   (   ) (
>        ( )   (   )   ( )
>        )_(   )   (   )_(-.._
>       (  )_  (._.)  _(  )_, `\
>        ``(   )   (   )`` .' .'
>     jgs   ```     ```   ( (`
>                          '-'
> 
> Skiboot output is pretty dull to look at. Sometimes surprises are
> nice.
> Especially when they are comforting cats. Even more so when they are
> rainbow coloured cats. Lol.
> 
> Signed-off-by: Alistair Popple <alistair@popple.id.au>

Tested-by/Acked-by/Reviewed-by/Suggest-on-by-default-by: Suraj Jitindar
 Singh <sjitindarsingh@gmail.com>

> ---
>  core/console.c            | 62
> +++++++++++++++++++++++++++++++++++++++++++++++
>  core/init.c               |  4 +++
>  include/skiboot.h         |  3 +++
>  platforms/astbmc/common.c |  5 ++++
>  4 files changed, 74 insertions(+)
> 
> diff --git a/core/console.c b/core/console.c
> index b9129c9f..9c344e9e 100644
> --- a/core/console.c
> +++ b/core/console.c
> @@ -235,6 +235,39 @@ static void write_char(char c)
>  	inmem_write(c);
>  }
>  
> +int sine_table[] = {
> +	0x80,0x83,0x86,0x8a,0x8d,0x90,0x93,0x97,
> +	0x9a,0x9d,0xa0,0xa4,0xa7,0xaa,0xad,0xb0,
> +	0xb3,0xb6,0xb9,0xbc,0xbf,0xc2,0xc5,0xc8,
> +	0xca,0xcd,0xd0,0xd2,0xd5,0xd7,0xda,0xdc,
> +	0xde,0xe0,0xe3,0xe5,0xe7,0xe9,0xea,0xec,
> +	0xee,0xf0,0xf1,0xf3,0xf4,0xf5,0xf7,0xf8,
> +	0xf9,0xfa,0xfb,0xfb,0xfc,0xfd,0xfd,0xfe,
> +	0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
> +	0xfe,0xfe,0xfd,0xfd,0xfc,0xfb,0xfb,0xfa,
> +	0xf9,0xf8,0xf7,0xf5,0xf4,0xf3,0xf1,0xf0,
> +	0xee,0xec,0xea,0xe9,0xe7,0xe5,0xe3,0xe0,
> +	0xde,0xdc,0xda,0xd7,0xd5,0xd2,0xd0,0xcd,
> +	0xca,0xc8,0xc5,0xc2,0xbf,0xbc,0xb9,0xb6,
> +	0xb3,0xb0,0xad,0xaa,0xa7,0xa4,0xa0,0x9d,
> +	0x9a,0x97,0x93,0x90,0x8d,0x8a,0x86,0x83,
> +	0x80,0x7c,0x79,0x75,0x72,0x6f,0x6c,0x68,
> +	0x65,0x62,0x5f,0x5b,0x58,0x55,0x52,0x4f,
> +	0x4c,0x49,0x46,0x43,0x40,0x3d,0x3a,0x37,
> +	0x35,0x32,0x2f,0x2d,0x2a,0x28,0x25,0x23,
> +	0x21,0x1f,0x1c,0x1a,0x18,0x16,0x15,0x13,
> +	0x11,0xf,0xe,0xc,0xb,0xa,0x8,0x7,
> +	0x6,0x5,0x4,0x4,0x3,0x2,0x2,0x1,
> +	0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
> +	0x1,0x1,0x2,0x2,0x3,0x4,0x4,0x5,
> +	0x6,0x7,0x8,0xa,0xb,0xc,0xe,0xf,
> +	0x11,0x13,0x15,0x16,0x18,0x1a,0x1c,0x1f,
> +	0x21,0x23,0x25,0x28,0x2a,0x2d,0x2f,0x32,
> +	0x35,0x37,0x3a,0x3d,0x40,0x43,0x46,0x49,
> +	0x4c,0x4f,0x52,0x55,0x58,0x5b,0x5f,0x62,
> +	0x65,0x68,0x6c,0x6f,0x72,0x75,0x79,0x7c };
> +
> +int lolcat = 0;
>  ssize_t console_write(bool flush_to_drivers, const void *buf, size_t
> count)
>  {
>  	/* We use recursive locking here as we can get called
> @@ -242,12 +275,41 @@ ssize_t console_write(bool flush_to_drivers,
> const void *buf, size_t count)
>  	 */
>  	bool need_unlock = lock_recursive(&con_lock);
>  	const char *cbuf = buf;
> +	char colour[30];
> +	const char *colour_end = "\x1b[0m";
> +	const char *cc;
> +	int red, green, blue;
> +	static int char_count = 0;
>  
>  	while(count--) {
>  		char c = *(cbuf++);
>  		if (c == '\n')
>  			write_char('\r');
> +
> +		if (lolcat) {
> +			red = sine_table[char_count];
> +			green = sine_table[(char_count +
> ARRAY_SIZE(sine_table)/3) % ARRAY_SIZE(sine_table)];
> +			blue = sine_table[(char_count +
> (2*ARRAY_SIZE(sine_table))/3) % ARRAY_SIZE(sine_table)];
> +
> +			snprintf(colour, ARRAY_SIZE(colour),
> "\x1b[38;2;%03d;%03d;%03dm", red, green, blue);
> +			cc = colour;
> +			while (*cc) {
> +				write_char(*cc);
> +				cc++;
> +			}
> +		}
> +
>  		write_char(c);
> +
> +		if (lolcat) {
> +			cc = colour_end;
> +			while (*cc) {
> +				write_char(*cc);
> +				cc++;
> +				char_count++;
> +				char_count %=
> ARRAY_SIZE(sine_table);
> +			}
> +		}
>  	}
>  
>  	__flush_console(flush_to_drivers);
> diff --git a/core/init.c b/core/init.c
> index 2eeba759..17c31118 100644
> --- a/core/init.c
> +++ b/core/init.c
> @@ -1002,6 +1002,10 @@ void __noreturn __nomcount
> main_cpu_entry(const void *fdt)
>  	/* Read in NVRAM and set it up */
>  	nvram_init();
>  
> +	/* Feeling colourful? */
> +	if (!lolcat)
> +		lolcat = !!nvram_query("lolcat");
> +
>  	/* preload the IMC catalog dtb */
>  	imc_catalog_preload();
>  
> diff --git a/include/skiboot.h b/include/skiboot.h
> index db913258..11914a67 100644
> --- a/include/skiboot.h
> +++ b/include/skiboot.h
> @@ -52,6 +52,9 @@ extern struct mem_region *mem_region_next(struct
> mem_region *region);
>  /* Readonly section start and end. */
>  extern char __rodata_start[], __rodata_end[];
>  
> +/* Enable lolcat mode */
> +extern int lolcat;
> +
>  static inline bool is_rodata(const void *p)
>  {
>  	return ((const char *)p >= __rodata_start && (const char *)p
> < __rodata_end);
> diff --git a/platforms/astbmc/common.c b/platforms/astbmc/common.c
> index 243ad946..9d6583b0 100644
> --- a/platforms/astbmc/common.c
> +++ b/platforms/astbmc/common.c
> @@ -26,6 +26,7 @@
>  #include <bt.h>
>  #include <errorlog.h>
>  #include <lpc.h>
> +#include <rtc.h>
>  
>  #include "astbmc.h"
>  
> @@ -120,6 +121,8 @@ static int astbmc_fru_init(void)
>  
>  void astbmc_init(void)
>  {
> +	struct tm tm;
> +
>  	/* Initialize PNOR/NVRAM */
>  	pnor_init();
>  
> @@ -131,6 +134,8 @@ void astbmc_init(void)
>  	ipmi_wdt_init();
>  	ipmi_rtc_init();
>  	ipmi_opal_init();
> +	while (rtc_cache_get(&tm)) opal_run_pollers();
> +	lolcat = tm.tm_mon == 11 && tm.tm_mday == 7 && tm.tm_hour ==
> 17 && tm.tm_min == 58;
>  	astbmc_fru_init();
>  	ipmi_sensor_init();
>
Cyril Bur Dec. 8, 2017, 2:53 a.m. UTC | #3
On Fri, 2017-12-08 at 13:28 +1100, Alistair Popple wrote:
>          ,_         _,
>          |\\.-"""-.//|
>          \`         `/
>         /    _   _    \
>         |    a _ a    |
>         '.=    Y    =.'
>           >._  ^  _.<
>          /   `````   \
>          )           (
>         ,(           ),
>        / )   /   \   ( \
>        ) (   )   (   ) (
>        ( )   (   )   ( )
>        )_(   )   (   )_(-.._
>       (  )_  (._.)  _(  )_, `\
>        ``(   )   (   )`` .' .'
>     jgs   ```     ```   ( (`
>                          '-'
> 
> Skiboot output is pretty dull to look at. Sometimes surprises are nice.
> Especially when they are comforting cats. Even more so when they are
> rainbow coloured cats. Lol.
> 
> Signed-off-by: Alistair Popple <alistair@popple.id.au>

Needs-more-bikeshed-by: Cyril Bur <cyril.bur@au1.ibm.com>

> ---
>  core/console.c            | 62 +++++++++++++++++++++++++++++++++++++++++++++++
>  core/init.c               |  4 +++
>  include/skiboot.h         |  3 +++
>  platforms/astbmc/common.c |  5 ++++
>  4 files changed, 74 insertions(+)
> 
> diff --git a/core/console.c b/core/console.c
> index b9129c9f..9c344e9e 100644
> --- a/core/console.c
> +++ b/core/console.c
> @@ -235,6 +235,39 @@ static void write_char(char c)
>  	inmem_write(c);
>  }
>  
> +int sine_table[] = {
> +	0x80,0x83,0x86,0x8a,0x8d,0x90,0x93,0x97,
> +	0x9a,0x9d,0xa0,0xa4,0xa7,0xaa,0xad,0xb0,
> +	0xb3,0xb6,0xb9,0xbc,0xbf,0xc2,0xc5,0xc8,
> +	0xca,0xcd,0xd0,0xd2,0xd5,0xd7,0xda,0xdc,
> +	0xde,0xe0,0xe3,0xe5,0xe7,0xe9,0xea,0xec,
> +	0xee,0xf0,0xf1,0xf3,0xf4,0xf5,0xf7,0xf8,
> +	0xf9,0xfa,0xfb,0xfb,0xfc,0xfd,0xfd,0xfe,
> +	0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
> +	0xfe,0xfe,0xfd,0xfd,0xfc,0xfb,0xfb,0xfa,
> +	0xf9,0xf8,0xf7,0xf5,0xf4,0xf3,0xf1,0xf0,
> +	0xee,0xec,0xea,0xe9,0xe7,0xe5,0xe3,0xe0,
> +	0xde,0xdc,0xda,0xd7,0xd5,0xd2,0xd0,0xcd,
> +	0xca,0xc8,0xc5,0xc2,0xbf,0xbc,0xb9,0xb6,
> +	0xb3,0xb0,0xad,0xaa,0xa7,0xa4,0xa0,0x9d,
> +	0x9a,0x97,0x93,0x90,0x8d,0x8a,0x86,0x83,
> +	0x80,0x7c,0x79,0x75,0x72,0x6f,0x6c,0x68,
> +	0x65,0x62,0x5f,0x5b,0x58,0x55,0x52,0x4f,
> +	0x4c,0x49,0x46,0x43,0x40,0x3d,0x3a,0x37,
> +	0x35,0x32,0x2f,0x2d,0x2a,0x28,0x25,0x23,
> +	0x21,0x1f,0x1c,0x1a,0x18,0x16,0x15,0x13,
> +	0x11,0xf,0xe,0xc,0xb,0xa,0x8,0x7,
> +	0x6,0x5,0x4,0x4,0x3,0x2,0x2,0x1,
> +	0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
> +	0x1,0x1,0x2,0x2,0x3,0x4,0x4,0x5,
> +	0x6,0x7,0x8,0xa,0xb,0xc,0xe,0xf,
> +	0x11,0x13,0x15,0x16,0x18,0x1a,0x1c,0x1f,
> +	0x21,0x23,0x25,0x28,0x2a,0x2d,0x2f,0x32,
> +	0x35,0x37,0x3a,0x3d,0x40,0x43,0x46,0x49,
> +	0x4c,0x4f,0x52,0x55,0x58,0x5b,0x5f,0x62,
> +	0x65,0x68,0x6c,0x6f,0x72,0x75,0x79,0x7c };
> +
> +int lolcat = 0;
>  ssize_t console_write(bool flush_to_drivers, const void *buf, size_t count)
>  {
>  	/* We use recursive locking here as we can get called
> @@ -242,12 +275,41 @@ ssize_t console_write(bool flush_to_drivers, const void *buf, size_t count)
>  	 */
>  	bool need_unlock = lock_recursive(&con_lock);
>  	const char *cbuf = buf;
> +	char colour[30];
> +	const char *colour_end = "\x1b[0m";
> +	const char *cc;
> +	int red, green, blue;
> +	static int char_count = 0;
>  
>  	while(count--) {
>  		char c = *(cbuf++);
>  		if (c == '\n')
>  			write_char('\r');
> +
> +		if (lolcat) {
> +			red = sine_table[char_count];
> +			green = sine_table[(char_count + ARRAY_SIZE(sine_table)/3) % ARRAY_SIZE(sine_table)];
> +			blue = sine_table[(char_count + (2*ARRAY_SIZE(sine_table))/3) % ARRAY_SIZE(sine_table)];
> +
> +			snprintf(colour, ARRAY_SIZE(colour), "\x1b[38;2;%03d;%03d;%03dm", red, green, blue);
> +			cc = colour;
> +			while (*cc) {
> +				write_char(*cc);
> +				cc++;
> +			}
> +		}
> +
>  		write_char(c);
> +
> +		if (lolcat) {
> +			cc = colour_end;
> +			while (*cc) {
> +				write_char(*cc);
> +				cc++;
> +				char_count++;
> +				char_count %= ARRAY_SIZE(sine_table);
> +			}
> +		}
>  	}
>  
>  	__flush_console(flush_to_drivers);
> diff --git a/core/init.c b/core/init.c
> index 2eeba759..17c31118 100644
> --- a/core/init.c
> +++ b/core/init.c
> @@ -1002,6 +1002,10 @@ void __noreturn __nomcount main_cpu_entry(const void *fdt)
>  	/* Read in NVRAM and set it up */
>  	nvram_init();
>  
> +	/* Feeling colourful? */
> +	if (!lolcat)
> +		lolcat = !!nvram_query("lolcat");
> +
>  	/* preload the IMC catalog dtb */
>  	imc_catalog_preload();
>  
> diff --git a/include/skiboot.h b/include/skiboot.h
> index db913258..11914a67 100644
> --- a/include/skiboot.h
> +++ b/include/skiboot.h
> @@ -52,6 +52,9 @@ extern struct mem_region *mem_region_next(struct mem_region *region);
>  /* Readonly section start and end. */
>  extern char __rodata_start[], __rodata_end[];
>  
> +/* Enable lolcat mode */
> +extern int lolcat;
> +
>  static inline bool is_rodata(const void *p)
>  {
>  	return ((const char *)p >= __rodata_start && (const char *)p < __rodata_end);
> diff --git a/platforms/astbmc/common.c b/platforms/astbmc/common.c
> index 243ad946..9d6583b0 100644
> --- a/platforms/astbmc/common.c
> +++ b/platforms/astbmc/common.c
> @@ -26,6 +26,7 @@
>  #include <bt.h>
>  #include <errorlog.h>
>  #include <lpc.h>
> +#include <rtc.h>
>  
>  #include "astbmc.h"
>  
> @@ -120,6 +121,8 @@ static int astbmc_fru_init(void)
>  
>  void astbmc_init(void)
>  {
> +	struct tm tm;
> +
>  	/* Initialize PNOR/NVRAM */
>  	pnor_init();
>  
> @@ -131,6 +134,8 @@ void astbmc_init(void)
>  	ipmi_wdt_init();
>  	ipmi_rtc_init();
>  	ipmi_opal_init();
> +	while (rtc_cache_get(&tm)) opal_run_pollers();
> +	lolcat = tm.tm_mon == 11 && tm.tm_mday == 7 && tm.tm_hour == 17 && tm.tm_min == 58;
>  	astbmc_fru_init();
>  	ipmi_sensor_init();
>
Guilherme G. Piccoli Dec. 11, 2017, 8:20 p.m. UTC | #4
On 12/08/2017 12:28 AM, Alistair Popple wrote:
>          ,_         _,
>          |\\.-"""-.//|
>          \`         `/
>         /    _   _    \
>         |    a _ a    |
>         '.=    Y    =.'
>           >._  ^  _.<
>          /   `````   \
>          )           (
>         ,(           ),
>        / )   /   \   ( \
>        ) (   )   (   ) (
>        ( )   (   )   ( )
>        )_(   )   (   )_(-.._
>       (  )_  (._.)  _(  )_, `\
>        ``(   )   (   )`` .' .'
>     jgs   ```     ```   ( (`
>                          '-'
> 
> Skiboot output is pretty dull to look at. Sometimes surprises are nice.
> Especially when they are comforting cats. Even more so when they are
> rainbow coloured cats. Lol.
> 
> Signed-off-by: Alistair Popple <alistair@popple.id.au>

Admired-by: Guilherme G. Piccoli <gpiccoli@linux.vnet.ibm.com>

> ---
>  core/console.c            | 62 +++++++++++++++++++++++++++++++++++++++++++++++
>  core/init.c               |  4 +++
>  include/skiboot.h         |  3 +++
>  platforms/astbmc/common.c |  5 ++++
>  4 files changed, 74 insertions(+)
> 
> diff --git a/core/console.c b/core/console.c
> index b9129c9f..9c344e9e 100644
> --- a/core/console.c
> +++ b/core/console.c
> @@ -235,6 +235,39 @@ static void write_char(char c)
>  	inmem_write(c);
>  }
>  
> +int sine_table[] = {
> +	0x80,0x83,0x86,0x8a,0x8d,0x90,0x93,0x97,
> +	0x9a,0x9d,0xa0,0xa4,0xa7,0xaa,0xad,0xb0,
> +	0xb3,0xb6,0xb9,0xbc,0xbf,0xc2,0xc5,0xc8,
> +	0xca,0xcd,0xd0,0xd2,0xd5,0xd7,0xda,0xdc,
> +	0xde,0xe0,0xe3,0xe5,0xe7,0xe9,0xea,0xec,
> +	0xee,0xf0,0xf1,0xf3,0xf4,0xf5,0xf7,0xf8,
> +	0xf9,0xfa,0xfb,0xfb,0xfc,0xfd,0xfd,0xfe,
> +	0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
> +	0xfe,0xfe,0xfd,0xfd,0xfc,0xfb,0xfb,0xfa,
> +	0xf9,0xf8,0xf7,0xf5,0xf4,0xf3,0xf1,0xf0,
> +	0xee,0xec,0xea,0xe9,0xe7,0xe5,0xe3,0xe0,
> +	0xde,0xdc,0xda,0xd7,0xd5,0xd2,0xd0,0xcd,
> +	0xca,0xc8,0xc5,0xc2,0xbf,0xbc,0xb9,0xb6,
> +	0xb3,0xb0,0xad,0xaa,0xa7,0xa4,0xa0,0x9d,
> +	0x9a,0x97,0x93,0x90,0x8d,0x8a,0x86,0x83,
> +	0x80,0x7c,0x79,0x75,0x72,0x6f,0x6c,0x68,
> +	0x65,0x62,0x5f,0x5b,0x58,0x55,0x52,0x4f,
> +	0x4c,0x49,0x46,0x43,0x40,0x3d,0x3a,0x37,
> +	0x35,0x32,0x2f,0x2d,0x2a,0x28,0x25,0x23,
> +	0x21,0x1f,0x1c,0x1a,0x18,0x16,0x15,0x13,
> +	0x11,0xf,0xe,0xc,0xb,0xa,0x8,0x7,
> +	0x6,0x5,0x4,0x4,0x3,0x2,0x2,0x1,
> +	0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
> +	0x1,0x1,0x2,0x2,0x3,0x4,0x4,0x5,
> +	0x6,0x7,0x8,0xa,0xb,0xc,0xe,0xf,
> +	0x11,0x13,0x15,0x16,0x18,0x1a,0x1c,0x1f,
> +	0x21,0x23,0x25,0x28,0x2a,0x2d,0x2f,0x32,
> +	0x35,0x37,0x3a,0x3d,0x40,0x43,0x46,0x49,
> +	0x4c,0x4f,0x52,0x55,0x58,0x5b,0x5f,0x62,
> +	0x65,0x68,0x6c,0x6f,0x72,0x75,0x79,0x7c };
> +
> +int lolcat = 0;
>  ssize_t console_write(bool flush_to_drivers, const void *buf, size_t count)
>  {
>  	/* We use recursive locking here as we can get called
> @@ -242,12 +275,41 @@ ssize_t console_write(bool flush_to_drivers, const void *buf, size_t count)
>  	 */
>  	bool need_unlock = lock_recursive(&con_lock);
>  	const char *cbuf = buf;
> +	char colour[30];
> +	const char *colour_end = "\x1b[0m";
> +	const char *cc;
> +	int red, green, blue;
> +	static int char_count = 0;
>  
>  	while(count--) {
>  		char c = *(cbuf++);
>  		if (c == '\n')
>  			write_char('\r');
> +
> +		if (lolcat) {
> +			red = sine_table[char_count];
> +			green = sine_table[(char_count + ARRAY_SIZE(sine_table)/3) % ARRAY_SIZE(sine_table)];
> +			blue = sine_table[(char_count + (2*ARRAY_SIZE(sine_table))/3) % ARRAY_SIZE(sine_table)];
> +
> +			snprintf(colour, ARRAY_SIZE(colour), "\x1b[38;2;%03d;%03d;%03dm", red, green, blue);
> +			cc = colour;
> +			while (*cc) {
> +				write_char(*cc);
> +				cc++;
> +			}
> +		}
> +
>  		write_char(c);
> +
> +		if (lolcat) {
> +			cc = colour_end;
> +			while (*cc) {
> +				write_char(*cc);
> +				cc++;
> +				char_count++;
> +				char_count %= ARRAY_SIZE(sine_table);
> +			}
> +		}
>  	}
>  
>  	__flush_console(flush_to_drivers);
> diff --git a/core/init.c b/core/init.c
> index 2eeba759..17c31118 100644
> --- a/core/init.c
> +++ b/core/init.c
> @@ -1002,6 +1002,10 @@ void __noreturn __nomcount main_cpu_entry(const void *fdt)
>  	/* Read in NVRAM and set it up */
>  	nvram_init();
>  
> +	/* Feeling colourful? */
> +	if (!lolcat)
> +		lolcat = !!nvram_query("lolcat");
> +
>  	/* preload the IMC catalog dtb */
>  	imc_catalog_preload();
>  
> diff --git a/include/skiboot.h b/include/skiboot.h
> index db913258..11914a67 100644
> --- a/include/skiboot.h
> +++ b/include/skiboot.h
> @@ -52,6 +52,9 @@ extern struct mem_region *mem_region_next(struct mem_region *region);
>  /* Readonly section start and end. */
>  extern char __rodata_start[], __rodata_end[];
>  
> +/* Enable lolcat mode */
> +extern int lolcat;
> +
>  static inline bool is_rodata(const void *p)
>  {
>  	return ((const char *)p >= __rodata_start && (const char *)p < __rodata_end);
> diff --git a/platforms/astbmc/common.c b/platforms/astbmc/common.c
> index 243ad946..9d6583b0 100644
> --- a/platforms/astbmc/common.c
> +++ b/platforms/astbmc/common.c
> @@ -26,6 +26,7 @@
>  #include <bt.h>
>  #include <errorlog.h>
>  #include <lpc.h>
> +#include <rtc.h>
>  
>  #include "astbmc.h"
>  
> @@ -120,6 +121,8 @@ static int astbmc_fru_init(void)
>  
>  void astbmc_init(void)
>  {
> +	struct tm tm;
> +
>  	/* Initialize PNOR/NVRAM */
>  	pnor_init();
>  
> @@ -131,6 +134,8 @@ void astbmc_init(void)
>  	ipmi_wdt_init();
>  	ipmi_rtc_init();
>  	ipmi_opal_init();
> +	while (rtc_cache_get(&tm)) opal_run_pollers();
> +	lolcat = tm.tm_mon == 11 && tm.tm_mday == 7 && tm.tm_hour == 17 && tm.tm_min == 58;
>  	astbmc_fru_init();
>  	ipmi_sensor_init();
>  
>
Joel Stanley Dec. 12, 2017, 3:46 a.m. UTC | #5
On Fri, Dec 8, 2017 at 12:58 PM, Alistair Popple <alistair@popple.id.au> wrote:
>          ,_         _,
>          |\\.-"""-.//|
>          \`         `/
>         /    _   _    \
>         |    a _ a    |
>         '.=    Y    =.'
>           >._  ^  _.<
>          /   `````   \
>          )           (
>         ,(           ),
>        / )   /   \   ( \
>        ) (   )   (   ) (
>        ( )   (   )   ( )
>        )_(   )   (   )_(-.._
>       (  )_  (._.)  _(  )_, `\
>        ``(   )   (   )`` .' .'
>     jgs   ```     ```   ( (`
>                          '-'
>
> Skiboot output is pretty dull to look at. Sometimes surprises are nice.
> Especially when they are comforting cats. Even more so when they are
> rainbow coloured cats. Lol.
>
> Signed-off-by: Alistair Popple <alistair@popple.id.au>

Whitespace-acked-by: Joel Stanley <joel@jms.id.au>
Stewart Smith Dec. 21, 2017, 1:58 a.m. UTC | #6
Alistair Popple <alistair@popple.id.au> writes:
>          ,_         _,
>          |\\.-"""-.//|
>          \`         `/
>         /    _   _    \
>         |    a _ a    |
>         '.=    Y    =.'
>           >._  ^  _.<
>          /   `````   \
>          )           (
>         ,(           ),
>        / )   /   \   ( \
>        ) (   )   (   ) (
>        ( )   (   )   ( )
>        )_(   )   (   )_(-.._
>       (  )_  (._.)  _(  )_, `\
>        ``(   )   (   )`` .' .'
>     jgs   ```     ```   ( (`
>                          '-'
>
> Skiboot output is pretty dull to look at. Sometimes surprises are nice.
> Especially when they are comforting cats. Even more so when they are
> rainbow coloured cats. Lol.
>
> Signed-off-by: Alistair Popple <alistair@popple.id.au>

Naked-because-cats-are-objectively-rubbish-by: Stewart Smith
<stewart@linux.vnet.ibm.com>

:)

(also, we should be way more non-obvious about it :)
diff mbox series

Patch

diff --git a/core/console.c b/core/console.c
index b9129c9f..9c344e9e 100644
--- a/core/console.c
+++ b/core/console.c
@@ -235,6 +235,39 @@  static void write_char(char c)
 	inmem_write(c);
 }
 
+int sine_table[] = {
+	0x80,0x83,0x86,0x8a,0x8d,0x90,0x93,0x97,
+	0x9a,0x9d,0xa0,0xa4,0xa7,0xaa,0xad,0xb0,
+	0xb3,0xb6,0xb9,0xbc,0xbf,0xc2,0xc5,0xc8,
+	0xca,0xcd,0xd0,0xd2,0xd5,0xd7,0xda,0xdc,
+	0xde,0xe0,0xe3,0xe5,0xe7,0xe9,0xea,0xec,
+	0xee,0xf0,0xf1,0xf3,0xf4,0xf5,0xf7,0xf8,
+	0xf9,0xfa,0xfb,0xfb,0xfc,0xfd,0xfd,0xfe,
+	0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+	0xfe,0xfe,0xfd,0xfd,0xfc,0xfb,0xfb,0xfa,
+	0xf9,0xf8,0xf7,0xf5,0xf4,0xf3,0xf1,0xf0,
+	0xee,0xec,0xea,0xe9,0xe7,0xe5,0xe3,0xe0,
+	0xde,0xdc,0xda,0xd7,0xd5,0xd2,0xd0,0xcd,
+	0xca,0xc8,0xc5,0xc2,0xbf,0xbc,0xb9,0xb6,
+	0xb3,0xb0,0xad,0xaa,0xa7,0xa4,0xa0,0x9d,
+	0x9a,0x97,0x93,0x90,0x8d,0x8a,0x86,0x83,
+	0x80,0x7c,0x79,0x75,0x72,0x6f,0x6c,0x68,
+	0x65,0x62,0x5f,0x5b,0x58,0x55,0x52,0x4f,
+	0x4c,0x49,0x46,0x43,0x40,0x3d,0x3a,0x37,
+	0x35,0x32,0x2f,0x2d,0x2a,0x28,0x25,0x23,
+	0x21,0x1f,0x1c,0x1a,0x18,0x16,0x15,0x13,
+	0x11,0xf,0xe,0xc,0xb,0xa,0x8,0x7,
+	0x6,0x5,0x4,0x4,0x3,0x2,0x2,0x1,
+	0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
+	0x1,0x1,0x2,0x2,0x3,0x4,0x4,0x5,
+	0x6,0x7,0x8,0xa,0xb,0xc,0xe,0xf,
+	0x11,0x13,0x15,0x16,0x18,0x1a,0x1c,0x1f,
+	0x21,0x23,0x25,0x28,0x2a,0x2d,0x2f,0x32,
+	0x35,0x37,0x3a,0x3d,0x40,0x43,0x46,0x49,
+	0x4c,0x4f,0x52,0x55,0x58,0x5b,0x5f,0x62,
+	0x65,0x68,0x6c,0x6f,0x72,0x75,0x79,0x7c };
+
+int lolcat = 0;
 ssize_t console_write(bool flush_to_drivers, const void *buf, size_t count)
 {
 	/* We use recursive locking here as we can get called
@@ -242,12 +275,41 @@  ssize_t console_write(bool flush_to_drivers, const void *buf, size_t count)
 	 */
 	bool need_unlock = lock_recursive(&con_lock);
 	const char *cbuf = buf;
+	char colour[30];
+	const char *colour_end = "\x1b[0m";
+	const char *cc;
+	int red, green, blue;
+	static int char_count = 0;
 
 	while(count--) {
 		char c = *(cbuf++);
 		if (c == '\n')
 			write_char('\r');
+
+		if (lolcat) {
+			red = sine_table[char_count];
+			green = sine_table[(char_count + ARRAY_SIZE(sine_table)/3) % ARRAY_SIZE(sine_table)];
+			blue = sine_table[(char_count + (2*ARRAY_SIZE(sine_table))/3) % ARRAY_SIZE(sine_table)];
+
+			snprintf(colour, ARRAY_SIZE(colour), "\x1b[38;2;%03d;%03d;%03dm", red, green, blue);
+			cc = colour;
+			while (*cc) {
+				write_char(*cc);
+				cc++;
+			}
+		}
+
 		write_char(c);
+
+		if (lolcat) {
+			cc = colour_end;
+			while (*cc) {
+				write_char(*cc);
+				cc++;
+				char_count++;
+				char_count %= ARRAY_SIZE(sine_table);
+			}
+		}
 	}
 
 	__flush_console(flush_to_drivers);
diff --git a/core/init.c b/core/init.c
index 2eeba759..17c31118 100644
--- a/core/init.c
+++ b/core/init.c
@@ -1002,6 +1002,10 @@  void __noreturn __nomcount main_cpu_entry(const void *fdt)
 	/* Read in NVRAM and set it up */
 	nvram_init();
 
+	/* Feeling colourful? */
+	if (!lolcat)
+		lolcat = !!nvram_query("lolcat");
+
 	/* preload the IMC catalog dtb */
 	imc_catalog_preload();
 
diff --git a/include/skiboot.h b/include/skiboot.h
index db913258..11914a67 100644
--- a/include/skiboot.h
+++ b/include/skiboot.h
@@ -52,6 +52,9 @@  extern struct mem_region *mem_region_next(struct mem_region *region);
 /* Readonly section start and end. */
 extern char __rodata_start[], __rodata_end[];
 
+/* Enable lolcat mode */
+extern int lolcat;
+
 static inline bool is_rodata(const void *p)
 {
 	return ((const char *)p >= __rodata_start && (const char *)p < __rodata_end);
diff --git a/platforms/astbmc/common.c b/platforms/astbmc/common.c
index 243ad946..9d6583b0 100644
--- a/platforms/astbmc/common.c
+++ b/platforms/astbmc/common.c
@@ -26,6 +26,7 @@ 
 #include <bt.h>
 #include <errorlog.h>
 #include <lpc.h>
+#include <rtc.h>
 
 #include "astbmc.h"
 
@@ -120,6 +121,8 @@  static int astbmc_fru_init(void)
 
 void astbmc_init(void)
 {
+	struct tm tm;
+
 	/* Initialize PNOR/NVRAM */
 	pnor_init();
 
@@ -131,6 +134,8 @@  void astbmc_init(void)
 	ipmi_wdt_init();
 	ipmi_rtc_init();
 	ipmi_opal_init();
+	while (rtc_cache_get(&tm)) opal_run_pollers();
+	lolcat = tm.tm_mon == 11 && tm.tm_mday == 7 && tm.tm_hour == 17 && tm.tm_min == 58;
 	astbmc_fru_init();
 	ipmi_sensor_init();