summaryrefslogtreecommitdiffstats
path: root/common
Commit message (Collapse)AuthorAgeFilesLines
* include: move crc specific stuff to crc.hSascha Hauer2016-04-155-0/+5
| | | | | | | We have a crc.h, so move our crc function prototypes there to further cleanup common.h. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* include: move shell prototypes to shell.hSascha Hauer2016-04-152-0/+2
| | | | | | We have a shell,h, so move shell specific prototypes there. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* include: move run_command prototype to command.hSascha Hauer2016-04-152-0/+2
| | | | | | run_command fits much better into command.h, move it there. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/imx-bbu-nand-fcb'Sascha Hauer2016-04-082-153/+827
|\
| * imx-bbu-nand-fcb: Print error message when out of pebsSascha Hauer2016-04-081-1/+3
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * imx-bbu-nand-fcb: Make robust against power cutsSascha Hauer2016-04-081-31/+341
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch makes the update to Nand robust against power failures. With this we make sure that during every step of the update at least one of the two images on Nand is readable and valid. Also this patch makes it possible to refresh/repair the boot images on Nand. This may become necessary when a previous update has been interrupted due to a power cut, or when the number of bitflips is near to the number we can correct. This is also done in a way that allow power cuts at every step. We assume the following layout in the Nand flash: fwmaxsize = (n_blocks - 4) / 2 block 0 ---------------------- | FCB/DBBT 0 | 1 ---------------------- | FCB/DBBT 1 | 2 ---------------------- | FCB/DBBT 2 | 3 ---------------------- | FCB/DBBT 3 | 4 ---------------------- | Firmware slot 0 | 4 + fwmaxsize ---------------------- | Firmware slot 1 | ---------------------- When the layout found on the device differs from the above the update won't be robust, but nevertheless works. Since the layout is changed to the above during the update, the next update will be robust. Here's the strategy we use to implement a robust update: The FCBs contain pointers to the firmware slots in the Firmware1_startingPage and Firmware2_startingPage fields. Note that Firmware1_startingPage doesn't necessarily point to slot 0. We exchange the pointers during update to atomically switch between the old and the new firmware. - We read the first valid FCB and the firmware slots. - We check which firmware slot is currently used by the ROM: - if no FCB is found or its layout differs from the above layout, continue without robust update - if only one firmware slot is readable, the ROM uses it - if both slots are readable, the ROM will use slot 0 - Step 1: erase/update the slot currently unused by the ROM - Step 2: Update FCBs/DBBTs, thereby letting Firmware1_startingPage point to the slot we just updated. From this moment on the new firmware will be used and running a refresh/repair after a power failure after this step will complete the update. - Step 3: erase/update the other firmwre slot - Step 4: Eventually write FCBs/DBBTs again. This may become necessary when step 3 revealed new bad blocks. Refreshing the firmware which is needed when when blocks become unreadable due to read disturbance works the same way, only that the new firmware is the same as the old firmware and that it will only be written when reading from the device returns -EUCLEAN indicating that a block needs to be rewritten. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * imx-bbu-nand-fcb: Print error when writing blocks failsSascha Hauer2016-04-081-1/+3
| | | | | | | | | | | | | | When writing to a block fails the update handler fails relatively silent. Print an error message in this case. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * imx-bbu-nand-fcb: When writing firmware return new bad blocksSascha Hauer2016-04-081-2/+3
| | | | | | | | | | | | | | | | | | | | Positive return values of imx_bbu_write_firmware() so far indicate the last block that has been written to. This value is unused, so return values > 0 to indicate if there are new bad blocks. This information can be used in the next step to know if the DBBT has to be rewritten. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * imx-bbu-nand-fcb: Only write FCBs/DBBTs when necessarySascha Hauer2016-04-081-0/+230
| | | | | | | | | | | | | | | | Instead of writing the FCBs/DBBTs on every update write them only if they have changed or if a block needs cleanup (returns -EUCLEAN) Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * imx-bbu-nand-fcb: erase on demandSascha Hauer2016-04-081-33/+14
| | | | | | | | | | | | | | | | Instead of erasing the whole partition on update entry, erase the areas separately when we actually want to write them. This is done as a step towards robust update. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * imx-bbu-nand-fcb: factor out a fcb write functionSascha Hauer2016-04-081-86/+172
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * imx-bbu-nand-fcb: Use mtd-peb API to write firmwareSascha Hauer2016-04-081-9/+35
| | | | | | | | | | | | | | | | With this patch we verify the firmware written to the NAND and thus can react on write failures. We torture the block and if it went bad we mark it as bad. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * imx-bbu-nand-fcb: factor out layout functionsSascha Hauer2016-04-081-20/+46
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * bbu: Allow to refresh/repair imagesSascha Hauer2016-04-081-1/+11
| | | | | | | | | | | | | | | | | | | | Some SoCs allow to store multiple boot images on a device in order to improve robustness. This adds a -r option to barebox_update to indicate we do not want to make an update but instead repair/refresh an existing image. Handlers which want to support this feature must set the BBU_HANDLER_CAN_REFRESH flag during registration. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/imx'Sascha Hauer2016-04-081-0/+1
|\ \
| * | common: Add EPROBE_DEFER to strerrorAndrey Smirnov2016-03-171-0/+1
| |/ | | | | | | | | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | common: add dependency !SANDBOX on imd target toolAntony Pavlov2016-04-071-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The build of bareboximd-target tool fails on sandbox architecture: CC scripts/bareboximd-target /tmp/ccoGPulo.o: In function `imd_concat_strings': scripts/../common/imd.c:216: undefined reference to `barebox_malloc' /tmp/ccoGPulo.o: In function `read_file_2': scripts/bareboximd.c:68: undefined reference to `barebox_open' scripts/bareboximd.c:74: undefined reference to `barebox_lseek' scripts/bareboximd.c:84: undefined reference to `barebox_lseek' scripts/bareboximd.c:90: undefined reference to `barebox_malloc' scripts/bareboximd.c:99: undefined reference to `barebox_read' scripts/bareboximd.c:119: undefined reference to `barebox_free' scripts/bareboximd.c:121: undefined reference to `barebox_close' /tmp/ccoGPulo.o: In function `imd_command': scripts/../common/imd.c:292: undefined reference to `barebox_printf' scripts/../common/imd.c:319: undefined reference to `barebox_printf' scripts/../common/imd.c:322: undefined reference to `barebox_free' scripts/../common/imd.c:324: undefined reference to `barebox_printf' /tmp/ccoGPulo.o: In function `usage': scripts/bareboximd.c:134: undefined reference to `barebox_printf' collect2: error: ld returned 1 exit status scripts/Makefile:58: recipe for target 'scripts/bareboximd-target' failed See also commit d4aa01503348a033b1057d8a66c20a4f5819e01f Author: Alexander Aring <alex.aring@gmail.com> Date: Tue Nov 19 02:08:13 2013 +0100 common: add dependency !SANDBOX on target tools The build of target tools fails on sandbox architecture. We don't need any target tools in this case, so add a dependency. Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Cc: Alexander Aring <alex.aring@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | bbu: print and evaluate image MetadataSascha Hauer2016-04-061-0/+78
| | | | | | | | | | | | | | | | | | | | | | With imd we can store metadata in barebox images. Let's use this information to further verify that the image that is to be flashed is the correct one. This patch extracts the device tree compatible from the image and compares it with the one from the currently running barebox. If it doesn't match the update is aborted with a warning. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | imd: Add function to read parametersSascha Hauer2016-04-011-0/+31
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | imd: export functionsSascha Hauer2016-04-011-3/+27
| | | | | | | | | | | | | | To make the image metadata API usable for external users export some functions. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | imd: rename imd_search_validate to imd_getSascha Hauer2016-04-011-13/+11
| | | | | | | | | | | | | | The name is more suitable for what the function does. Also let the function return a pointer to the imd data found in the buffer. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | imd: string returned from imd_string_data should be constSascha Hauer2016-04-011-6/+10
| | | | | | | | | | | | | | imd_string_data() returns the original data, so the string should be const. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | imd: use struct imd_header * as argumentSascha Hauer2016-03-291-15/+16
|/ | | | | | | | imd_concat_strings() and imd_string_data() are easier to handle when they take a struct imd_header * instead of a struct imd_entry_string *. Change this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/mtd'Sascha Hauer2016-03-111-6/+2
|\
| * imx-bbu-nand-fcb: Remove double write of first fcbSascha Hauer2016-03-041-4/+0
| | | | | | | | | | | | | | The first FCB page was written twice. One time is enough, drop the second write. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * imx-bbu-nand-fcb: optimize check for bad block loopSascha Hauer2016-03-041-2/+2
| | | | | | | | | | | | | | | | The argument passed to dbbt_data_create() contains the number of blocks, not the last block. This means we can exit the loop with '<' instead of '<=' Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/misc'Sascha Hauer2016-03-112-0/+37
|\ \
| * | common: oftree: Add function to register set status fixupTeresa Remmet2016-03-011-0/+36
| | | | | | | | | | | | | | | | | | | | | | | | Added a function to register a fixup to enable or disable device tree nodes. Signed-off-by: Teresa Remmet <t.remmet@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | Print error message if of_state_fixup() failsHarald Welte2016-02-181-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If of_state_fixup() fails for some reason, boot/bootm will fail, too However, it is completely unclear where the error has happened, and to the user it rather seems like the kernel device tree loaded from some file was broken/corrupt, not that in fact some fixup routine was failing. Adding a meaningful error message can help debugging significantly. Signed-off-by: Harald Welte <laforge@gnumonks.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | Merge branch 'for-next/doc'Sascha Hauer2016-03-111-15/+1
|\ \ \
| * | | ratp: remove unused ratp_close commandRobert Schwebel2016-02-101-15/+1
| | |/ | |/| | | | | | | | | | | | | | | | This is a leftover from development, remove. Signed-off-by: Robert Schwebel <r.schwebel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | Merge branch 'for-next/bbu'Sascha Hauer2016-03-112-1/+46
|\ \ \
| * | | fastboot: Add a ARM Barebox filetype handlerMarkus Pargmann2016-03-111-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This will automatically call barebox_update for the transfered file if it is an ARM Barebox image and the destination file is defined by some update handler. Signed-off-by: Markus Pargmann <mpa@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | bbu: Add function to check if an update handler existsMarkus Pargmann2016-02-181-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds a function to check for the existence of an update handler based on the supplied bbu_data. Signed-off-by: Markus Pargmann <mpa@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | bbu: Add barebox_update search by deviceMarkus Pargmann2016-02-181-1/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | bbu_data includes a devicefile information. Add the possibility to make an update based on the given devicefile. This is in addition to the normal search for a barebox update handler by its name. Signed-off-by: Markus Pargmann <mpa@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | | ratp: use proper defines for BAREBOX_CMDLucas Stach2016-03-041-1/+1
| | | | | | | | | | | | | | | | | | | | Signed-off-by: Lucas Stach <dev@lynxeye.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | | bbu: use correct printf format specifier for size_tLucas Stach2016-03-041-1/+1
| | | | | | | | | | | | | | | | | | | | Signed-off-by: Lucas Stach <dev@lynxeye.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | | bootm: Fix booting uImagesSascha Hauer2016-02-251-6/+12
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes: 0a37e22d (bootm: use names instead of numbers for image parts) This commit switches to strings for the image numbers for better FIT image support (which uses names instead of numbers). These strings may be NULL when no image number is given. They are used uninitialzed in several places. Introduce a wrapper function to convert the string into a number. Check for NULL here in which case we return 0 which is the correct value. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | bootm: Free allocated fdt buffer in error pathHarald Welte2016-02-181-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | It seems like there is a memory leak in an error path of bootm_open_oftree_uimage() where the memory allocated for the fdt is not released again. Signed-off-by: Harald Welte <laforge@gnumonks.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | bootm: parse initrd and oftree into correct struct membersLucas Stach2016-02-151-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | The code parsing the oftree and initrd file names is clearly wrong, leading to bootm not loading oftree or initrd files any more. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | bootm: restore load DT message for plain oftree filesLucas Stach2016-02-151-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | This message was dropped when reorganizing the DT loading code, and it's really confusing to miss this. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | blspec: ignore lines beginning with '#'Sascha Hauer2016-02-111-0/+3
| | | | | | | | | | | | | | | | | | According to the bootloader spec these should be treated as comments. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | blspec: Do not crash on config files without newline on last lineSascha Hauer2016-02-111-1/+1
| |/ |/| | | | | | | | | | | When the last line in a config file has no newline then 'next' is NULL on the the loop iteration. Check that before derefencing 'next'. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | ratp-console: select CRC16 and POLLER, depend on CONSOLE_FULLLucas Stach2016-02-111-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | RATP console selects RATP, which in turn selects CRC16, but those chains don't work in Kconfig, so select CRC16 also from the console option. Also fix build errors by depending on CONSOLE_FULL and selecting POLLER. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | bootm: Fix resource_size_t format specifierSascha Hauer2016-02-111-2/+2
|/ | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/ratp'Sascha Hauer2016-02-084-3/+545
|\
| * barebox remote controlSascha Hauer2016-01-184-3/+545
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds the ability to control barebox over serial lines. The regular console is designed for human input and is unsuitable for controlling barebox from scripts since characters can be lost on both ends, the data stream contains escape sequences and the prompt cannot be easily matched upon. This approach is based on the RATP protocol. RATP packages start with a binary 0x01 which does not occur in normal console data. Whenever a 0x01 character is detected in the console barebox goes into RATP mode. The RATP packets contain a simple structure with a command/respone type and data for that type. Currently defined types are: BB_RATP_TYPE_COMMAND (host->barebox): Execute a command in the shell BB_RATP_TYPE_COMMAND_RETURN (barebox->host) Sends return value of the command back to the host, also means barebox is ready for the next command BB_RATP_TYPE_CONSOLEMSG (barebox->host) Console message from barebox Planned but not yet implemented are: BB_RATP_TYPE_PING (host->barebox) BB_RATP_TYPE_PONG (barebox->host) For testing purposes BB_RATP_TYPE_GETENV (host->barebox) BB_RATP_TYPE_GETENV_RETURN (barebox->host) Get values of environment variables Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Tested-by: Andrey Smirnov <andrew.smirnov@gmail.com>
* | Merge branch 'for-next/misc'Sascha Hauer2016-02-083-25/+24
|\ \
| * | Convert users of PRINTF_CONVERSION_RESOURCE to %paSascha Hauer2016-01-152-10/+9
| | | | | | | | | | | | | | | | | | | | | | | | printf now supports printing resource_size_t directly, convert all users of the previously used PRINTF_CONVERSION_RESOURCE over to %pa. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | hush: fix indentationSascha Hauer2016-01-111-17/+17
| | | | | | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>