diff options
Diffstat (limited to 'libboot')
-rw-r--r-- | libboot/Android.mk | 25 | ||||
-rw-r--r-- | libboot/flash.c | 79 | ||||
-rw-r--r-- | libboot/gpio_keypad.c | 90 | ||||
-rw-r--r-- | libboot/init.c | 41 | ||||
-rw-r--r-- | libboot/poll.c | 51 | ||||
-rw-r--r-- | libboot/tags.c | 64 | ||||
-rw-r--r-- | libboot/tags_cmdline.c | 50 | ||||
-rw-r--r-- | libboot/tags_partition.c | 54 | ||||
-rw-r--r-- | libboot/tags_revision.c | 52 | ||||
-rw-r--r-- | libboot/tags_serialno.c | 49 |
10 files changed, 555 insertions, 0 deletions
diff --git a/libboot/Android.mk b/libboot/Android.mk new file mode 100644 index 0000000..d2085f3 --- /dev/null +++ b/libboot/Android.mk @@ -0,0 +1,25 @@ +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_ARM_MODE := arm + +LOCAL_SRC_FILES := \ + flash.c \ + poll.c \ + tags_partition.c \ + tags_revision.c \ + tags_serialno.c \ + tags_cmdline.c \ + gpio_keypad.c \ + init.c \ + tags.c + +LOCAL_C_INCLUDES := $(call include-path-for, bootloader) + +LOCAL_CFLAGS := -O2 -g -W -Wall +LOCAL_CFLAGS += -march=armv6 + +LOCAL_MODULE := libboot + +include $(BUILD_RAW_STATIC_LIBRARY) diff --git a/libboot/flash.c b/libboot/flash.c new file mode 100644 index 0000000..f1503dc --- /dev/null +++ b/libboot/flash.c @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <boot/boot.h> +#include <boot/flash.h> + +#define MAX_PTN 16 + +static ptentry ptable[MAX_PTN]; +static unsigned pcount = 0; + +void flash_add_ptn(ptentry *ptn) +{ + if(pcount < MAX_PTN){ + memcpy(ptable + pcount, ptn, sizeof(*ptn)); + pcount++; + } +} + +void flash_dump_ptn(void) +{ + unsigned n; + for(n = 0; n < pcount; n++) { + ptentry *ptn = ptable + n; + dprintf("ptn %d name='%s' start=%d len=%d\n", + n, ptn->name, ptn->start, ptn->length); + } +} + + +ptentry *flash_find_ptn(const char *name) +{ + unsigned n; + for(n = 0; n < pcount; n++) { + if(!strcmp(ptable[n].name, name)) { + return ptable + n; + } + } + return 0; +} + +ptentry *flash_get_ptn(unsigned n) +{ + if(n < pcount) { + return ptable + n; + } else { + return 0; + } +} + +unsigned flash_get_ptn_count(void) +{ + return pcount; +} diff --git a/libboot/gpio_keypad.c b/libboot/gpio_keypad.c new file mode 100644 index 0000000..b1ec7c2 --- /dev/null +++ b/libboot/gpio_keypad.c @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <boot/boot.h> +#include <boot/gpio.h> +#include <boot/gpio_keypad.h> + +int gpio_keypad_init(gpio_keypad_info *keypad) +{ + unsigned i; + for(i = 0; i < keypad->noutputs; i++) { + gpio_set(keypad->output_gpios[i], keypad->polarity ^ keypad->drive_inactive_outputs); + gpio_dir(keypad->output_gpios[i], keypad->drive_inactive_outputs); + } + for(i = 0; i < keypad->ninputs; i++) { + gpio_dir(keypad->input_gpios[i], 0); + } + keypad->state = 0; + return 0; +} + +void gpio_keypad_scan_keys(gpio_keypad_info *keypad) +{ + unsigned out, in; + unsigned long long keys; + unsigned npolarity = !keypad->polarity; + unsigned int shift; + + keys = 0; + out = keypad->noutputs; + shift = keypad->noutputs * keypad->ninputs; + while(out > 0) { + out--; + if(keypad->drive_inactive_outputs) + gpio_set(keypad->output_gpios[out], !npolarity); + else + gpio_dir(keypad->output_gpios[out], 1); + udelay(keypad->settle_time); + in = keypad->ninputs; + while(in > 0) { + in--; + shift--; + keys = (keys << 1) | (gpio_get(keypad->input_gpios[in]) ^ npolarity); + if(((unsigned)(keypad->state >> shift) ^ (unsigned)keys) & 1) { + unsigned int mapped_key = 0; + if(keypad->key_map) + mapped_key = keypad->key_map[shift]; + //dprintf("gpio_keypad_scan_keys: %d-%d (%d-%d) %d (%d): %d\n", out, in, + // keypad->output_gpios[out], keypad->input_gpios[in], + // shift, mapped_key, keys & 1); + if(mapped_key && key_changed) + key_changed(mapped_key, keys & 1); + } + } + if(keypad->drive_inactive_outputs) + gpio_set(keypad->output_gpios[out], npolarity); + else + gpio_dir(keypad->output_gpios[out], 0); + } + if(keys != keypad->state) { + keypad->state = keys; + //dprintf("gpio_keypad_scan_keys: %x %x\n", (unsigned long)(keys >> 32), (unsigned long)keys); + } +} + diff --git a/libboot/init.c b/libboot/init.c new file mode 100644 index 0000000..3223dda --- /dev/null +++ b/libboot/init.c @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +char data[3]; + +extern unsigned BOOTLOADER_INIT_FIRST; +extern unsigned BOOTLOADER_INIT_LAST; + +void call_init_hooks() +{ + unsigned x; + for(x = BOOTLOADER_INIT_FIRST; x < BOOTLOADER_INIT_LAST; x += 4) { + int (*hook)(void) = (void*) x; + hook(); + } +} diff --git a/libboot/poll.c b/libboot/poll.c new file mode 100644 index 0000000..4b87140 --- /dev/null +++ b/libboot/poll.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <boot/boot.h> + +#define MAX_POLL_FUNCS 16 + +typedef void (*poll_func)(void); + +static poll_func poll_funcs[MAX_POLL_FUNCS]; +static unsigned poll_count = 0; + +void boot_register_poll_func(void (*func)(void)) +{ + if(poll_count < MAX_POLL_FUNCS) { + poll_funcs[poll_count++] = func; + } +} + +void boot_poll(void) +{ + unsigned n; + for(n = 0; n < poll_count; n++) { + poll_funcs[n](); + } +} diff --git a/libboot/tags.c b/libboot/tags.c new file mode 100644 index 0000000..3fbf23b --- /dev/null +++ b/libboot/tags.c @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <boot/tags.h> + +#define DBG(x...) do{}while(0) +//#define DBG(x...) dprintf(x) + +void tags_parse(void *_tags, struct tag_handler *handlers, unsigned count) +{ + unsigned n; + unsigned *tags = _tags; + + DBG("tags_parse %p\n", tags); + + /* make sure there's a CORE marker first */ + if(tags[0] != 2) return; + if(tags[1] != 0x54410001) return; + + for(;;) { + unsigned size = tags[0]; + unsigned type = tags[1]; + + DBG("tags_parse %x %x\n", size, type); + + if(size < 2) break; + + for(n = 0; n < count; n++) { + struct tag_handler *h = handlers + n; + if((h->type == type) || (h->type == 0)) { + h->func(type, (void*) &tags[2], (size - 2) * 4, h->cookie); + break; + } + } + + tags += size; + } +} + diff --git a/libboot/tags_cmdline.c b/libboot/tags_cmdline.c new file mode 100644 index 0000000..4496e53 --- /dev/null +++ b/libboot/tags_cmdline.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <boot/boot.h> +#include <boot/tags.h> +#include <boot/flash.h> + +static void tag_cmdline(unsigned tag, void *data, unsigned bytes, void *cookie) +{ + *((const char **) cookie) = data; +} + +const char *tags_get_cmdline(void *tags) +{ + const char *cmdline = ""; + struct tag_handler h; + + h.type = 0x54410009; + h.func = tag_cmdline; + h.cookie = &cmdline; + + tags_parse(tags, &h, 1); + + return cmdline; +} diff --git a/libboot/tags_partition.c b/libboot/tags_partition.c new file mode 100644 index 0000000..5881a48 --- /dev/null +++ b/libboot/tags_partition.c @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <boot/boot.h> +#include <boot/tags.h> +#include <boot/flash.h> + +static void ptn_importer(unsigned tag, void *data, unsigned bytes, void *cookie) +{ + struct ptentry *ptn = data; + unsigned n = 0; + + while(bytes >= sizeof(*ptn)) { + flash_add_ptn(ptn); + ptn++; + n++; + bytes -= sizeof(*ptn); + } +} + +static struct tag_handler ptn_handler = { + .type = 0x4d534d70, + .func = ptn_importer, +}; + +void tags_import_partitions(void *tags) +{ + tags_parse(tags, &ptn_handler, 1); +} diff --git a/libboot/tags_revision.c b/libboot/tags_revision.c new file mode 100644 index 0000000..d4eeb40 --- /dev/null +++ b/libboot/tags_revision.c @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <boot/boot.h> +#include <boot/tags.h> +#include <boot/flash.h> + +static void tag_revision(unsigned tag, void *data, unsigned bytes, void *cookie) +{ + if(bytes == 4) { + memcpy(cookie, data, 4); + } +} + +unsigned tags_get_revision(void *tags) +{ + unsigned n = 0; + struct tag_handler h; + + h.type = 0x54410007; + h.func = tag_revision; + h.cookie = &n; + + tags_parse(tags, &h, 1); + + return n; +} diff --git a/libboot/tags_serialno.c b/libboot/tags_serialno.c new file mode 100644 index 0000000..a647c21 --- /dev/null +++ b/libboot/tags_serialno.c @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <boot/boot.h> +#include <boot/tags.h> +#include <boot/flash.h> + +static void tag_serialno(unsigned tag, void *data, unsigned bytes, void *cookie) +{ + if(bytes == 8) { + memcpy(cookie, data, 8); + } +} + +void tags_get_serialno(void *tags, void *sn) +{ + struct tag_handler h; + + h.type = 0x54410006; + h.func = tag_serialno; + h.cookie = sn; + + tags_parse(tags, &h, 1); +} |