Commit 8b0ecf71 authored by Henrik Nordstrom's avatar Henrik Nordstrom
Browse files

felboot: Replace util_printf.c with pristine printf-stdarg.c from menie.org

same code but the util_printf.c one was missing copyright attribution
and slightly hacked up.
parent afcf0eef
......@@ -30,7 +30,7 @@ UBOOT_OBJS= \
.c.o:
$(CROSS_COMPILE)$(CC) -c $(CFLAGS) $< -o $@
fel-boot-$(BOARD).elf: main.o util_printf.o early_print.o $(addprefix $(UBOOTOBJ),$(UBOOT_OBJS))
fel-boot-$(BOARD).elf: main.o printf-stdarg.o early_print.o $(addprefix $(UBOOTOBJ),$(UBOOT_OBJS))
$(CROSS_COMPILE)$(CC) -Tfel-boot.ld -static -nostartfiles $(CFLAGS) -Wl,-Map=$@.map $^ -o $@
fel-boot-$(BOARD).bin: fel-boot-$(BOARD).elf
......
......@@ -90,3 +90,13 @@ void sunxi_board_init(void)
clock_set_pll1(1008000000);
}
int putchar(int ch)
{
return uart_putc(ch);
}
int puts(const char *str)
{
return uart_puts(str);
}
/*
Copyright 2001, 2002 Georges Menie (www.menie.org)
stdarg version contributed by Christian Ettinger
*/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
#include <stdarg.h>
#include "early_print.h"
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
putchar is the only external dependency for this file,
if you have a working putchar, leave it commented out.
If not, uncomment the define below and
replace outbyte(c) by your own function call.
/* Debug uart have been init by boot rom. */
void put_char(char ch)
{
uart_putc(ch);
}
#define putchar(c) outbyte(c)
*/
#include <stdarg.h>
static void printchar(char **str, int c)
{
extern int putchar(int c);
if (str) {
**str = c;
++(*str);
}
else {
put_char(c);
}
else (void)putchar(c);
}
#define PAD_RIGHT 1
......@@ -104,14 +118,13 @@ static int printi(char **out, int i, int b, int sg, int width, int pad, int letb
return pc + prints (out, s, width, pad);
}
static int print(char **out, const char *format, va_list args )
{
register int width, pad;
register int pc = 0;
char scr[2];
for (; *format != 0; format++) {
for (; *format != 0; ++format) {
if (*format == '%') {
++format;
width = pad = 0;
......@@ -164,45 +177,90 @@ static int print(char **out, const char *format, va_list args )
++pc;
}
}
if (out) **out = '\0';
va_end( args );
return pc;
}
int sprintf(char *out, const char *format, ...)
{
va_list args;
va_start( args, format );
return print( &out, format, args );
}
int printf(const char *format, ...)
{
va_list args;
va_start( args, format );
return print( 0, format, args );
va_list args;
va_start( args, format );
return print( 0, format, args );
}
int printu(const char *format, ...)
int sprintf(char *out, const char *format, ...)
{
va_list args;
va_start( args, format );
return print( 0, format, args );
va_list args;
va_start( args, format );
return print( &out, format, args );
}
void puts ( char * str )
#ifdef TEST_PRINTF
int main(void)
{
int i=0;
while(str[i] != 0)
{
put_char(str[i]);
i++;
}
char *ptr = "Hello world!";
char *np = 0;
int i = 5;
unsigned int bs = sizeof(int)*8;
int mi;
char buf[80];
mi = (1 << (bs-1)) + 1;
printf("%s\n", ptr);
printf("printf test\n");
printf("%s is null pointer\n", np);
printf("%d = 5\n", i);
printf("%d = - max int\n", mi);
printf("char %c = 'a'\n", 'a');
printf("hex %x = ff\n", 0xff);
printf("hex %02x = 00\n", 0);
printf("signed %d = unsigned %u = hex %x\n", -3, -3, -3);
printf("%d %s(s)%", 0, "message");
printf("\n");
printf("%d %s(s) with %%\n", 0, "message");
sprintf(buf, "justif: \"%-10s\"\n", "left"); printf("%s", buf);
sprintf(buf, "justif: \"%10s\"\n", "right"); printf("%s", buf);
sprintf(buf, " 3: %04d zero padded\n", 3); printf("%s", buf);
sprintf(buf, " 3: %-4d left justif.\n", 3); printf("%s", buf);
sprintf(buf, " 3: %4d right justif.\n", 3); printf("%s", buf);
sprintf(buf, "-3: %04d zero padded\n", -3); printf("%s", buf);
sprintf(buf, "-3: %-4d left justif.\n", -3); printf("%s", buf);
sprintf(buf, "-3: %4d right justif.\n", -3); printf("%s", buf);
return 0;
}
/*
* if you compile this file with
* gcc -Wall $(YOUR_C_OPTIONS) -DTEST_PRINTF -c printf.c
* you will get a normal warning:
* printf.c:214: warning: spurious trailing `%' in format
* this line is testing an invalid % at the end of the format string.
*
* this should display (on 32bit int machine) :
*
* Hello world!
* printf test
* (null) is null pointer
* 5 = 5
* -2147483647 = - max int
* char a = 'a'
* hex ff = ff
* hex 00 = 00
* signed -3 = unsigned 4294967293 = hex fffffffd
* 0 message(s)
* 0 message(s) with %
* justif: "left "
* justif: " right"
* 3: 0003 zero padded
* 3: 3 left justif.
* 3: 3 right justif.
* -3: -003 zero padded
* -3: -3 left justif.
* -3: -3 right justif.
*/
#endif
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