Skip to content

Commit

Permalink
Update libfdt and support current ndless-sdk versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Vogtinator committed Apr 8, 2015
1 parent 3a6d33d commit 9a3635d
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.o
*.zehn
*.elf
*.tns
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ BUILDFLAGS := -DBUILD_DATE="\"$(shell date --rfc-2822)\""
BUILDFLAGS += -DGIT_COMMIT="\"$(shell git rev-parse --short HEAD)\""

LDFLAGS = -lnspireio
OBJCOPY := "$(shell which arm-elf-objcopy 2>/dev/null)"
ifeq (${OBJCOPY},"")
OBJCOPY := arm-none-eabi-objcopy
endif
EXE = linuxloader2.tns

OBJS = $(patsubst %.c,%.o,$(wildcard *.c))
Expand All @@ -30,7 +26,8 @@ all: $(EXE)

$(EXE): $(OBJS)
$(LD) $^ -o $(@:.tns=.elf) $(LDFLAGS)
$(OBJCOPY) -O binary $(@:.tns=.elf) $@
genzehn --input $(@:.tns=.elf) --output $(@:.tns=.zehn) --name "Linux Loader v2" --version 1 --author "tangrs"
make-prg $(@:.tns=.zehn) $@

clean:
rm -f $(OBJS) *.elf
Expand Down
3 changes: 2 additions & 1 deletion common.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
#ifndef COMMON_H
#define COMMON_H

#include <stdarg.h>
#include <stddef.h>
#include <nspireio.h>
#include <nspireio/nspireio.h>

#define PAGE_SIZE 0x1000
#define DTB_MACH_ID 3503
Expand Down
4 changes: 2 additions & 2 deletions libfdt/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
const char *p;

if (fdt_version(fdt) >= 0x11)
if (((int)(offset + len) < offset)
if (((offset + len) < offset)
|| ((offset + len) > fdt_size_dt_struct(fdt)))
return NULL;

Expand Down Expand Up @@ -214,7 +214,7 @@ int fdt_move(const void *fdt, void *buf, int bufsize)
{
FDT_CHECK_HEADER(fdt);

if ((int)fdt_totalsize(fdt) > bufsize)
if (fdt_totalsize(fdt) > bufsize)
return -FDT_ERR_NOSPACE;

memmove(buf, fdt, fdt_totalsize(fdt));
Expand Down
1 change: 0 additions & 1 deletion libfdt/fdt_empty_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,3 @@ int fdt_create_empty_tree(void *buf, int bufsize)

return fdt_open_into(buf, buf, bufsize);
}

2 changes: 1 addition & 1 deletion libfdt/fdt_ro.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle)
{
int offset;

if ((phandle == 0) || (phandle == (uint32_t)-1))
if ((phandle == 0) || (phandle == -1))
return -FDT_ERR_BADPHANDLE;

FDT_CHECK_HEADER(fdt);
Expand Down
2 changes: 1 addition & 1 deletion libfdt/fdt_strerror.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const char *fdt_strerror(int errval)
return "<valid offset/length>";
else if (errval == 0)
return "<no error>";
else if (errval > (int)-FDT_ERRTABSIZE) {
else if (errval > -FDT_ERRTABSIZE) {
const char *s = fdt_errtable[-errval].str;

if (s)
Expand Down
6 changes: 3 additions & 3 deletions libfdt/fdt_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static void *_fdt_grab_space(void *fdt, size_t len)
spaceleft = fdt_totalsize(fdt) - fdt_off_dt_struct(fdt)
- fdt_size_dt_strings(fdt);

if (((int)(offset + len) < offset) || ((int)(offset + len) > spaceleft))
if ((offset + len < offset) || (offset + len > spaceleft))
return NULL;

fdt_set_size_dt_struct(fdt, offset + len);
Expand All @@ -89,7 +89,7 @@ int fdt_create(void *buf, int bufsize)
{
void *fdt = buf;

if (bufsize < (int)sizeof(struct fdt_header))
if (bufsize < sizeof(struct fdt_header))
return -FDT_ERR_NOSPACE;

memset(buf, 0, bufsize);
Expand Down Expand Up @@ -180,7 +180,7 @@ static int _fdt_find_add_string(void *fdt, const char *s)
/* Add it */
offset = -strtabsize - len;
struct_top = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);
if ((int)fdt_totalsize(fdt) + offset < struct_top)
if (fdt_totalsize(fdt) + offset < struct_top)
return 0; /* no more room :( */

memcpy(strtab + offset, s, len);
Expand Down
10 changes: 3 additions & 7 deletions libfdt/libfdt_env.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#ifndef _LIBFDT_ENV_H
#define _LIBFDT_ENV_H

//#include <stddef.h>
//#include <stdint.h>
//#include <string.h>
#include <os.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>

#define EXTRACT_BYTE(n) ((unsigned long long)((uint8_t *)&x)[n])
static inline uint16_t fdt16_to_cpu(uint16_t x)
Expand All @@ -27,7 +26,4 @@ static inline uint64_t fdt64_to_cpu(uint64_t x)
#define cpu_to_fdt64(x) fdt64_to_cpu(x)
#undef EXTRACT_BYTE

/* Included here because os.h doesn't include it for some reason */
const void* memchr(const void *ptr, int value, size_t num);

#endif /* _LIBFDT_ENV_H */
3 changes: 1 addition & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/

#include <os.h>
#include <nspireio.h>
#include "common.h"
#include "memory.h"
#include "cmd.h"
Expand Down Expand Up @@ -74,7 +73,7 @@ int main(int argc, char *argv[]) {
while (1) {
char cmd[128];
nio_puts("> ");
if (nio_gets(cmd)) {
if (nio_getsn(cmd, 127)) {
if (process_cmd(cmd)) break;
}
}
Expand Down

0 comments on commit 9a3635d

Please sign in to comment.