2 * RouterBoot helper routines
4 * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
13 #include <linux/routerboot.h>
15 #include "routerboot.h"
17 static u32
get_u32(void *buf
)
21 return ((u32
) p
[3] + ((u32
) p
[2] << 8) + ((u32
) p
[1] << 16) +
25 static u16
get_u16(void *buf
)
29 return (u16
) p
[1] + ((u16
) p
[0] << 8);
33 routerboot_find_magic(u8
*buf
, unsigned int buflen
, u32
*offset
, bool hard
)
35 u32 magic_ref
= hard
? RB_MAGIC_HARD
: RB_MAGIC_SOFT
;
39 while (cur
< buflen
) {
40 magic
= get_u32(buf
+ cur
);
41 if (magic
== magic_ref
) {
53 routerboot_find_tag(u8
*buf
, unsigned int buflen
, u16 tag_id
,
54 u8
**tag_data
, u16
*tag_len
)
65 /* skip magic value */
74 /* skip magic and CRC value */
100 if (id
== RB_ID_TERMINATOR
)