Skip to content

Commit

Permalink
Various code style fixups
Browse files Browse the repository at this point in the history
Pointer style to "type *name".
Opening braces stay on the same line.
Define __attribute__((unused)) in a macro.
Change code to use UNUSED macro.
Added proper header boilerplate to fdt.h.
  • Loading branch information
tangrs committed May 27, 2013
1 parent 68bac97 commit bafa84e
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 43 deletions.
4 changes: 2 additions & 2 deletions atag.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "atag.h"
#include "common.h"

static void* atag_add(void *head, int tagid, ...) {
static void *atag_add(void *head, int tagid, ...) {
va_list ap;
va_start(ap, tagid);
char *cmdline = NULL;
Expand Down Expand Up @@ -108,7 +108,7 @@ static void* atag_add(void *head, int tagid, ...) {
return (char*)head + tag_size;
}

static void* atag_begin(void *head) {
static void *atag_begin(void *head) {
return atag_add(head, ATAG_CORE);
}

Expand Down
8 changes: 4 additions & 4 deletions cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "cmd.h"


static int next_space_null(const char* str) {
static int next_space_null(const char *str) {
int i = 0;
while (*str != ' ' && *str != '\0') ((i++), (str++));
return i;
Expand All @@ -35,7 +35,7 @@ static int next_space_null(const char* str) {
Returns number of filled arguments.
Var args are all of type char**
*/
int cmd_args(char* args, unsigned max_n, ...) {
int cmd_args(char *args, unsigned max_n, ...) {
va_list ap;
va_start(ap, max_n);

Expand All @@ -59,7 +59,7 @@ int cmd_args(char* args, unsigned max_n, ...) {
return i;
}

int load_script(const char* filename) {
int load_script(const char *filename) {
FILE *script = fopen(filename, "r");
if (!script) {
printl("Warning: Cannot open script file %s" NEWLINE, filename);
Expand All @@ -82,7 +82,7 @@ int load_script(const char* filename) {
Returns 0 if further commands can be executed
*/
#define DEFINE_COMMAND(s, f) else if (!strncmp(#s, cmd, sizeof(#s)-1)) (cmd[sizeof(#s)-1] ? f(cmd+sizeof(#s)) : f(""))
int process_cmd(char * cmd) {
int process_cmd(char *cmd) {
if (*cmd == '#') return 0;
if (*cmd == '\0') return 0;
else if (!strcmp("exit", cmd)) return 1;
Expand Down
6 changes: 3 additions & 3 deletions cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#ifndef CMD_H
#define CMD_H

int load_script(const char* filename);
int process_cmd(char * cmd);
int cmd_args(char* args, unsigned max_n, ...);
int load_script(const char *filename);
int process_cmd(char *cmd);
int cmd_args(char *args, unsigned max_n, ...);

#endif
12 changes: 6 additions & 6 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
#define FOOTER_LEVEL1() FOOTER(" ")
#define FOOTER_LEVEL2() FOOTER(" ")

void setget_mach(char * arg) {
void setget_mach(char *arg) {
int num;
if ( (num = strtol(arg, NULL, 10)) ) {
settings.machine_id = num;
}
printl("Machine ID is set to %d" NEWLINE, settings.machine_id);
}

void setget_phys(char * arg) {
void setget_phys(char *arg) {
unsigned start, size;
if ( (start = strtoul(arg, &arg, 16)) && (size = strtoul(arg, NULL, 16)) ) {
settings.phys.start = (void*)start;
Expand All @@ -51,15 +51,15 @@ void setget_phys(char * arg) {
printl("Physical memory range is 0x%p-0x%p" NEWLINE, settings.phys.start, (void*)((char*)settings.phys.start + settings.phys.size));
}

void setget_rdisksize(char * arg) {
void setget_rdisksize(char *arg) {
unsigned num;
if ( (num = strtoul(arg, NULL, 16)) ) {
settings.ramdisk_size = num;
}
printl("Kernel RAMDISK size set to %uK" NEWLINE, settings.ramdisk_size);
}

void peek(char * arg) {
void peek(char *arg) {
char *endptr;
unsigned addr;

Expand Down Expand Up @@ -98,11 +98,11 @@ void poke(char *arg) {
peek(arg);
}

void break_on_entry(char *arg __attribute__((unused))) {
void break_on_entry(char *arg UNUSED) {
settings.break_on_entry = 1;
}

void dump_settings(char * ignored __attribute__((unused))) {
void dump_settings(char *ignored UNUSED) {
HEADER_LEVEL0(kernel);
DUMP_LEVEL1(settings.kernel, addr);
DUMP_LEVEL1(settings.kernel, size);
Expand Down
20 changes: 10 additions & 10 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,36 @@
uart_printf(__VA_ARGS__); \
} while(0)


#define NEWLINE "\r\n"
#define UNUSED __attribute__((unused))

typedef volatile uint32_t *io32_t;
typedef volatile uint16_t *io16_t;
typedef volatile uint8_t *io8_t;

struct params {
struct {
void* addr; /* Where the kernel is loaded (address should be in range of mem_block) */
void *addr; /* Where the kernel is loaded (address should be in range of mem_block) */
size_t size;
} kernel;

struct {
void* addr; /* Where the initrd is loaded (address should be in range of mem_block) */
void *addr; /* Where the initrd is loaded (address should be in range of mem_block) */
size_t size;
} initrd;

struct {
void* start; /* A separate section of memory for writing ATAG and DTBs */
void *start; /* A separate section of memory for writing ATAG and DTBs */
size_t size;
} boot_param;

struct {
void* start; /* Memory block for kernel and initrd */
void *start; /* Memory block for kernel and initrd */
size_t size;
} mem_block;

struct {
void* start;
void *start;
size_t size;
} phys;

Expand All @@ -82,10 +82,10 @@ struct params {

extern struct params settings;

void dump_settings(char*);
void setget_mach(char * arg);
void setget_phys(char * arg);
void setget_rdisksize(char * arg);
void dump_settings(char *);
void setget_mach(char *arg);
void setget_phys(char *arg);
void setget_rdisksize(char *arg);

void poke(char *arg);
void peek(char *arg);
Expand Down
7 changes: 3 additions & 4 deletions fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
#include "common.h"
#include "memory.h"

static int _fdt_make_node(void * fdt, int parentoffset, const char * name) {
static int _fdt_make_node(void *fdt, int parentoffset, const char *name) {
int e = fdt_subnode_offset(fdt, parentoffset, name);
if(e != FDT_ERR_NOTFOUND)
return e;

return fdt_add_subnode(fdt, parentoffset, name);
}

int update_fdt()
{
static void* fdt = 0;
int update_fdt() {
static void *fdt = 0;

if(!fdt)
fdt = malloc(FDT_SIZE_MAX + 7);
Expand Down
23 changes: 23 additions & 0 deletions fdt.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/*
TI-NSPIRE Linux In-Place Bootloader
Copyright (C) 2012 Daniel Tang
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef FDT_H
#define FDT_H

#define FDT_SIZE_MAX 0x10000

int update_fdt();

#endif
6 changes: 3 additions & 3 deletions kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@

typedef void kentry(int, int, void*);

void kernel_cmdline(char * cmdline) {
void kernel_cmdline(char *cmdline) {
if (strlen(cmdline)) strncpy(settings.kernel_cmdline, cmdline, sizeof(settings.kernel_cmdline)-1);
printl("Kernel command line: \"%s\"" NEWLINE, settings.kernel_cmdline);
}

void kernel_boot(char * ignored __attribute__((unused))) {
kentry* entry = (kentry*)settings.kernel.addr;
void kernel_boot(char *ignored UNUSED) {
kentry *entry = (kentry*)settings.kernel.addr;

if (!settings.kernel_loaded) {
printl("Kernel not loaded." NEWLINE);
Expand Down
6 changes: 3 additions & 3 deletions kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#ifndef KERNEL_H
#define KERNEL_H

void kernel_boot(char*);
void kernel_cmdline(char*);
void kernel_boot(char *);
void kernel_cmdline(char *);

#endif
#endif
8 changes: 4 additions & 4 deletions load.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static size_t file_size(const char *filename) {
void load_kernel(const char *filename) {
size_t kernel_size = file_size(filename);
size_t size_free_memory = mem_block_size_free() - settings.kernel.size;
FILE* f;
FILE *f;

if (!kernel_size) {
printl("Kernel doesn't exist or empty" NEWLINE);
Expand Down Expand Up @@ -64,10 +64,10 @@ void load_kernel(const char *filename) {
}

void load_initrd(const char *filename) {
FILE* f;
FILE *f;
size_t initrd_size = file_size(filename);
size_t size_free_memory = mem_block_size_free() - settings.initrd.size;
void* initrd_laddr = ((char*)settings.mem_block.start + settings.mem_block.size - initrd_size);
void *initrd_laddr = ((char*)settings.mem_block.start + settings.mem_block.size - initrd_size);
initrd_laddr = ROUND_PAGE_BOUND(initrd_laddr);
size_t needed_size = ((char*)settings.mem_block.start + settings.mem_block.size)
- (char*)initrd_laddr;
Expand Down Expand Up @@ -114,7 +114,7 @@ void load_initrd(const char *filename) {
}

void load_dtb(const char *filename) {
FILE* f;
FILE *f;
size_t dtb_size = file_size(filename);

if (dtb_size > settings.boot_param.size) {
Expand Down
2 changes: 1 addition & 1 deletion mach.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static int guess_memory_size() {
return 0;
}

void force_guess_memory(char* ignored __attribute__((unused))) {
void force_guess_memory(char *ignored UNUSED) {
if (guess_memory_size()) printl("Failed to guess memory parameters" NEWLINE);
}

Expand Down
6 changes: 3 additions & 3 deletions memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
Try to alloc the biggest contigious section of memory possible.
Will always be a multiple of INC_BLOCK_SIZE
*/
static void* max_malloc(size_t *size) {
void * ptr = NULL;
static void *max_malloc(size_t *size) {
void *ptr = NULL;
size_t curr_size = 0;

while(1) {
Expand Down Expand Up @@ -58,7 +58,7 @@ static void* max_malloc(size_t *size) {
printl("%u%s", number, unit); \
} while (0)

void show_mem(char *ignored __attribute__((unused))) {
void show_mem(char *ignored UNUSED) {
printl("Total free: ");
HUMAN(mem_block_size_free());
printl("/");
Expand Down

0 comments on commit bafa84e

Please sign in to comment.