From e7fcc273dc0d44145083f131d242424135fe2e53 Mon Sep 17 00:00:00 2001 From: Max Krummenacher Date: Mon, 1 May 2017 17:23:13 +0200 Subject: bmode-usb: add recipe to set i.mx 6 boot mode This linux userspace tool does what U-Boot's 'bmode usb noreset' does. On the next reboot the i.MX 6 will boot to recovery aka serial download mode. Signed-off-by: Max Krummenacher Signed-off-by: Stefan Agner --- recipes-support/bmode-usb/bmode-usb/bmode_usb.c | 45 +++++++++++++++++++++++++ recipes-support/bmode-usb/bmode-usb_1.0.bb | 15 +++++++++ 2 files changed, 60 insertions(+) create mode 100644 recipes-support/bmode-usb/bmode-usb/bmode_usb.c create mode 100644 recipes-support/bmode-usb/bmode-usb_1.0.bb diff --git a/recipes-support/bmode-usb/bmode-usb/bmode_usb.c b/recipes-support/bmode-usb/bmode-usb/bmode_usb.c new file mode 100644 index 0000000..c8ca7e2 --- /dev/null +++ b/recipes-support/bmode-usb/bmode-usb/bmode_usb.c @@ -0,0 +1,45 @@ +/* + * Copyright 2017 Toradex AG. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/* + * Running this will set GPR9/GPR10 to values which will make the module + * go to recovery mode on next reboot. + * It has the same effect as 'bmode usb noreset' in U-Boot + * + * $ arm-linux-gnueabihf-gcc -o bmode_usb bmode_usb.c + * $ arm-linux-gnueabihf-strip bmode_usb + */ + +#include +#include +#include +#include + +/* valid for i.MX6DL/i.MX6Q */ +#define SRC_BASE_ADDR 0x020D8000 +#define SRC_GPR9_OFF (0x40/4) +#define SRC_GPR10_OFF (0x44/4) + +int main(void) +{ + int fd; + unsigned reg; + unsigned *src; + + fd = open("/dev/mem", O_RDWR); + src = (unsigned *)mmap(0, SRC_GPR10_OFF + 4, PROT_READ|PROT_WRITE, + MAP_SHARED, fd, 0x020D8000); + if(src == NULL) { + printf("Failed to mmap register\n"); + return -1; + } + + src[SRC_GPR9_OFF] = 0x10; + src[SRC_GPR10_OFF] |= 0x10000000; + + printf("Next reboot (not powercycle!) will boot to recovery mode\n"); + return 0; +} diff --git a/recipes-support/bmode-usb/bmode-usb_1.0.bb b/recipes-support/bmode-usb/bmode-usb_1.0.bb new file mode 100644 index 0000000..f33f531 --- /dev/null +++ b/recipes-support/bmode-usb/bmode-usb_1.0.bb @@ -0,0 +1,15 @@ +SUMMARY = "Sets i.MX boot mode on next reboot to recovery, aka serial download" +LICENSE = "GPLv2+" +LIC_FILES_CHKSUM = "file://bmode_usb.c;endline=5;md5=4c9010cb42fb7648a460c35e6b5c685c" + +SRC_URI = "file://bmode_usb.c" +S = "${WORKDIR}" + +do_compile() { + ${CC} -o bmode_usb bmode_usb.c ${CFLAGS} ${LDFLAGS} +} + +do_install() { + install -d ${D}${bindir} + install bmode_usb ${D}${bindir} +} -- cgit v1.2.3